@downcity/shell 0.1.4

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 (141) hide show
  1. package/bin/Shell.d.ts +55 -0
  2. package/bin/Shell.d.ts.map +1 -0
  3. package/bin/Shell.js +171 -0
  4. package/bin/Shell.js.map +1 -0
  5. package/bin/approval/ShellApprovalRuntime.d.ts +62 -0
  6. package/bin/approval/ShellApprovalRuntime.d.ts.map +1 -0
  7. package/bin/approval/ShellApprovalRuntime.js +214 -0
  8. package/bin/approval/ShellApprovalRuntime.js.map +1 -0
  9. package/bin/index.d.ts +27 -0
  10. package/bin/index.d.ts.map +1 -0
  11. package/bin/index.js +26 -0
  12. package/bin/index.js.map +1 -0
  13. package/bin/sandbox/LinuxBubblewrapSandbox.d.ts +19 -0
  14. package/bin/sandbox/LinuxBubblewrapSandbox.d.ts.map +1 -0
  15. package/bin/sandbox/LinuxBubblewrapSandbox.js +186 -0
  16. package/bin/sandbox/LinuxBubblewrapSandbox.js.map +1 -0
  17. package/bin/sandbox/MacOsSeatbeltSandbox.d.ts +16 -0
  18. package/bin/sandbox/MacOsSeatbeltSandbox.d.ts.map +1 -0
  19. package/bin/sandbox/MacOsSeatbeltSandbox.js +154 -0
  20. package/bin/sandbox/MacOsSeatbeltSandbox.js.map +1 -0
  21. package/bin/sandbox/SandboxConfigResolver.d.ts +37 -0
  22. package/bin/sandbox/SandboxConfigResolver.d.ts.map +1 -0
  23. package/bin/sandbox/SandboxConfigResolver.js +130 -0
  24. package/bin/sandbox/SandboxConfigResolver.js.map +1 -0
  25. package/bin/sandbox/SandboxPreflight.d.ts +73 -0
  26. package/bin/sandbox/SandboxPreflight.d.ts.map +1 -0
  27. package/bin/sandbox/SandboxPreflight.js +122 -0
  28. package/bin/sandbox/SandboxPreflight.js.map +1 -0
  29. package/bin/sandbox/SandboxRunner.d.ts +61 -0
  30. package/bin/sandbox/SandboxRunner.d.ts.map +1 -0
  31. package/bin/sandbox/SandboxRunner.js +107 -0
  32. package/bin/sandbox/SandboxRunner.js.map +1 -0
  33. package/bin/sandbox/UnrestrictedSandbox.d.ts +16 -0
  34. package/bin/sandbox/UnrestrictedSandbox.d.ts.map +1 -0
  35. package/bin/sandbox/UnrestrictedSandbox.js +39 -0
  36. package/bin/sandbox/UnrestrictedSandbox.js.map +1 -0
  37. package/bin/sandbox/types/Sandbox.d.ts +130 -0
  38. package/bin/sandbox/types/Sandbox.d.ts.map +1 -0
  39. package/bin/sandbox/types/Sandbox.js +10 -0
  40. package/bin/sandbox/types/Sandbox.js.map +1 -0
  41. package/bin/sandbox/types/SandboxRuntime.d.ts +370 -0
  42. package/bin/sandbox/types/SandboxRuntime.d.ts.map +1 -0
  43. package/bin/sandbox/types/SandboxRuntime.js +10 -0
  44. package/bin/sandbox/types/SandboxRuntime.js.map +1 -0
  45. package/bin/session/Paths.d.ts +12 -0
  46. package/bin/session/Paths.d.ts.map +1 -0
  47. package/bin/session/Paths.js +21 -0
  48. package/bin/session/Paths.js.map +1 -0
  49. package/bin/session/ShellActionResponse.d.ts +52 -0
  50. package/bin/session/ShellActionResponse.d.ts.map +1 -0
  51. package/bin/session/ShellActionResponse.js +73 -0
  52. package/bin/session/ShellActionResponse.js.map +1 -0
  53. package/bin/session/ShellActionRuntime.d.ts +15 -0
  54. package/bin/session/ShellActionRuntime.d.ts.map +1 -0
  55. package/bin/session/ShellActionRuntime.js +15 -0
  56. package/bin/session/ShellActionRuntime.js.map +1 -0
  57. package/bin/session/ShellActionRuntimeSupport.d.ts +88 -0
  58. package/bin/session/ShellActionRuntimeSupport.d.ts.map +1 -0
  59. package/bin/session/ShellActionRuntimeSupport.js +305 -0
  60. package/bin/session/ShellActionRuntimeSupport.js.map +1 -0
  61. package/bin/session/ShellProcessEvents.d.ts +22 -0
  62. package/bin/session/ShellProcessEvents.d.ts.map +1 -0
  63. package/bin/session/ShellProcessEvents.js +41 -0
  64. package/bin/session/ShellProcessEvents.js.map +1 -0
  65. package/bin/session/ShellRunScope.d.ts +43 -0
  66. package/bin/session/ShellRunScope.d.ts.map +1 -0
  67. package/bin/session/ShellRunScope.js +29 -0
  68. package/bin/session/ShellRunScope.js.map +1 -0
  69. package/bin/session/ShellRuntimeEnvironment.d.ts +21 -0
  70. package/bin/session/ShellRuntimeEnvironment.d.ts.map +1 -0
  71. package/bin/session/ShellRuntimeEnvironment.js +69 -0
  72. package/bin/session/ShellRuntimeEnvironment.js.map +1 -0
  73. package/bin/session/ShellRuntimeTypes.d.ts +160 -0
  74. package/bin/session/ShellRuntimeTypes.d.ts.map +1 -0
  75. package/bin/session/ShellRuntimeTypes.js +10 -0
  76. package/bin/session/ShellRuntimeTypes.js.map +1 -0
  77. package/bin/session/actions/ShellActionShared.d.ts +76 -0
  78. package/bin/session/actions/ShellActionShared.d.ts.map +1 -0
  79. package/bin/session/actions/ShellActionShared.js +100 -0
  80. package/bin/session/actions/ShellActionShared.js.map +1 -0
  81. package/bin/session/actions/ShellApprovalActions.d.ts +34 -0
  82. package/bin/session/actions/ShellApprovalActions.d.ts.map +1 -0
  83. package/bin/session/actions/ShellApprovalActions.js +37 -0
  84. package/bin/session/actions/ShellApprovalActions.js.map +1 -0
  85. package/bin/session/actions/ShellExecActions.d.ts +15 -0
  86. package/bin/session/actions/ShellExecActions.d.ts.map +1 -0
  87. package/bin/session/actions/ShellExecActions.js +117 -0
  88. package/bin/session/actions/ShellExecActions.js.map +1 -0
  89. package/bin/session/actions/ShellLifecycleActions.d.ts +18 -0
  90. package/bin/session/actions/ShellLifecycleActions.d.ts.map +1 -0
  91. package/bin/session/actions/ShellLifecycleActions.js +53 -0
  92. package/bin/session/actions/ShellLifecycleActions.js.map +1 -0
  93. package/bin/session/actions/ShellQueryActions.d.ts +27 -0
  94. package/bin/session/actions/ShellQueryActions.d.ts.map +1 -0
  95. package/bin/session/actions/ShellQueryActions.js +151 -0
  96. package/bin/session/actions/ShellQueryActions.js.map +1 -0
  97. package/bin/session/actions/ShellStartActions.d.ts +15 -0
  98. package/bin/session/actions/ShellStartActions.d.ts.map +1 -0
  99. package/bin/session/actions/ShellStartActions.js +167 -0
  100. package/bin/session/actions/ShellStartActions.js.map +1 -0
  101. package/bin/session/actions/ShellWriteActions.d.ts +15 -0
  102. package/bin/session/actions/ShellWriteActions.d.ts.map +1 -0
  103. package/bin/session/actions/ShellWriteActions.js +85 -0
  104. package/bin/session/actions/ShellWriteActions.js.map +1 -0
  105. package/bin/tool/ShellToolFormatting.d.ts +12 -0
  106. package/bin/tool/ShellToolFormatting.d.ts.map +1 -0
  107. package/bin/tool/ShellToolFormatting.js +31 -0
  108. package/bin/tool/ShellToolFormatting.js.map +1 -0
  109. package/bin/tool/ShellToolSchemas.d.ts +61 -0
  110. package/bin/tool/ShellToolSchemas.d.ts.map +1 -0
  111. package/bin/tool/ShellToolSchemas.js +130 -0
  112. package/bin/tool/ShellToolSchemas.js.map +1 -0
  113. package/bin/tool/ShellTools.d.ts +32 -0
  114. package/bin/tool/ShellTools.d.ts.map +1 -0
  115. package/bin/tool/ShellTools.js +296 -0
  116. package/bin/tool/ShellTools.js.map +1 -0
  117. package/bin/types/Shell.d.ts +115 -0
  118. package/bin/types/Shell.d.ts.map +1 -0
  119. package/bin/types/Shell.js +9 -0
  120. package/bin/types/Shell.js.map +1 -0
  121. package/bin/types/ShellAction.d.ts +258 -0
  122. package/bin/types/ShellAction.d.ts.map +1 -0
  123. package/bin/types/ShellAction.js +9 -0
  124. package/bin/types/ShellAction.js.map +1 -0
  125. package/bin/types/ShellHostContext.d.ts +78 -0
  126. package/bin/types/ShellHostContext.d.ts.map +1 -0
  127. package/bin/types/ShellHostContext.js +9 -0
  128. package/bin/types/ShellHostContext.js.map +1 -0
  129. package/bin/types/ShellRuntime.d.ts +128 -0
  130. package/bin/types/ShellRuntime.d.ts.map +1 -0
  131. package/bin/types/ShellRuntime.js +9 -0
  132. package/bin/types/ShellRuntime.js.map +1 -0
  133. package/bin/types/ShellRuntimeOptions.d.ts +103 -0
  134. package/bin/types/ShellRuntimeOptions.d.ts.map +1 -0
  135. package/bin/types/ShellRuntimeOptions.js +10 -0
  136. package/bin/types/ShellRuntimeOptions.js.map +1 -0
  137. package/bin/utils/Id.d.ts +11 -0
  138. package/bin/utils/Id.d.ts.map +1 -0
  139. package/bin/utils/Id.js +14 -0
  140. package/bin/utils/Id.js.map +1 -0
  141. package/package.json +81 -0
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Shell action 运行环境解析辅助。
3
+ *
4
+ * 关键点(中文)
5
+ * - 集中处理 shell 子进程 cwd、env 与 owner context 的解析。
6
+ * - 这里只做输入归一化,不持有 shell session 状态。
7
+ */
8
+ import path from "node:path";
9
+ function stripShellSecretEnv(env) {
10
+ delete env.DC_AUTH_TOKEN;
11
+ delete env.DC_AGENT_TOKEN;
12
+ }
13
+ /**
14
+ * 构造 shell 子进程环境变量。
15
+ */
16
+ export function buildShellEnv(context) {
17
+ const env = { ...process.env };
18
+ // 关键点(中文)
19
+ // - ShellHostContext.env 现在就是宿主已经整理好的最终 env 视图。
20
+ // - shell 只消费这一份显式上下文,避免再次引入 platform/global env 隐式来源。
21
+ for (const [key, value] of Object.entries(context.env || {})) {
22
+ const normalizedKey = String(key || "").trim();
23
+ const normalizedValue = String(value || "").trim();
24
+ if (!normalizedKey || !normalizedValue)
25
+ continue;
26
+ env[normalizedKey] = normalizedValue;
27
+ }
28
+ const run_context = context.shellIntegration?.getRunContext?.();
29
+ const sessionId = String(run_context?.sessionId || "").trim();
30
+ const agentPath = String(context.rootPath || "").trim();
31
+ const configuredAgentId = String(context.config?.id || "").trim();
32
+ const agentId = configuredAgentId || (agentPath ? path.basename(agentPath) : "");
33
+ // 关键点(中文)
34
+ // - agent 自己在 shell 里执行 `town <service> ...` 时,也需要显式知道“当前 agent 是谁”。
35
+ // - 否则 service CLI 会退回到当前终端 cwd / registry 猜测,在多 agent 或外部工作目录下
36
+ // 很容易把请求发到错误项目,最终误报 “Agent runtime 没启动”。
37
+ if (agentPath)
38
+ env.DC_AGENT_PATH = agentPath;
39
+ if (agentId)
40
+ env.DC_AGENT_ID = agentId;
41
+ if (sessionId)
42
+ env.DC_SESSION_ID = sessionId;
43
+ if (process.env.DC_CITY_HOST)
44
+ env.DC_CITY_HOST = process.env.DC_CITY_HOST;
45
+ if (process.env.DC_CITY_PORT)
46
+ env.DC_CITY_PORT = process.env.DC_CITY_PORT;
47
+ stripShellSecretEnv(env);
48
+ return env;
49
+ }
50
+ /**
51
+ * 解析 shell 执行目录。
52
+ */
53
+ export function resolveShellCwd(context, cwd) {
54
+ const raw = String(cwd || "").trim();
55
+ if (!raw)
56
+ return context.rootPath;
57
+ return path.isAbsolute(raw) ? raw : path.resolve(context.rootPath, raw);
58
+ }
59
+ /**
60
+ * 推断 shell 所属的 owner context。
61
+ */
62
+ export function resolveOwnerContextId(context, explicit) {
63
+ const fromInput = String(explicit || "").trim();
64
+ if (fromInput)
65
+ return fromInput;
66
+ const fromRequest = String(context.shellIntegration?.getRunContext?.()?.sessionId || "").trim();
67
+ return fromRequest || undefined;
68
+ }
69
+ //# sourceMappingURL=ShellRuntimeEnvironment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShellRuntimeEnvironment.js","sourceRoot":"","sources":["../../src/session/ShellRuntimeEnvironment.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,SAAS,mBAAmB,CAAC,GAAsB;IACjD,OAAO,GAAG,CAAC,aAAa,CAAC;IACzB,OAAO,GAAG,CAAC,cAAc,CAAC;AAC5B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,OAAyB;IACrD,MAAM,GAAG,GAAsB,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAElD,UAAU;IACV,gDAAgD;IAChD,uDAAuD;IACvD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,I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GAAG,CAAC,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;IAC1E,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAEzB,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,OAAyB,EAAE,GAAY;IACrE,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,IAAI,CAAC,GAAG;QAAE,OAAO,OAAO,CAAC,QAAQ,CAAC;IAClC,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AAC1E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAyB,EACzB,QAAiB;IAEjB,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAChD,IAAI,SAAS;QAAE,OAAO,SAAS,CAAC;IAChC,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAAE,aAAa,EAAE,EAAE,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAChG,OAAO,WAAW,IAAI,SAAS,CAAC;AAClC,CAAC"}
@@ -0,0 +1,160 @@
1
+ /**
2
+ * ShellRuntime 类型定义。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这些类型描述 shell runtime 的实例级运行态。
6
+ * - 状态所有权归属于 `Shell` 实例,而不是模块级单例。
7
+ * - 统一归档到 `src/shell/` 相邻层级,避免继续分散在跨域目录里。
8
+ */
9
+ import type { ChildProcessWithoutNullStreams } from "node:child_process";
10
+ import type { ShellHostContext } from "../types/ShellHostContext.js";
11
+ import type { ShellApprovalStatus, ShellApprovalToolName, ShellSessionSnapshot } from "../types/ShellAction.js";
12
+ import type { ResolvedShellRuntimeOptions } from "../types/ShellRuntimeOptions.js";
13
+ /**
14
+ * unrestricted sandbox 审批运行态。
15
+ */
16
+ export type ShellApprovalRuntimeState = {
17
+ /**
18
+ * 当前审批请求 ID。
19
+ */
20
+ approvalId: string;
21
+ /**
22
+ * 关联的 shell_id。
23
+ */
24
+ shellId: string;
25
+ /**
26
+ * 所属 session/聊天上下文。
27
+ */
28
+ ownerContextId?: string;
29
+ /**
30
+ * 关联工具名。
31
+ */
32
+ toolName: ShellApprovalToolName;
33
+ /**
34
+ * 申请执行的命令。
35
+ *
36
+ * 说明(中文)
37
+ * - `shell_write` 使用该字段保存 stdin 写入预览,保持审批队列结构统一。
38
+ */
39
+ cmd: string;
40
+ /**
41
+ * 审批动作类型。
42
+ */
43
+ operation: "exec" | "start" | "write";
44
+ /**
45
+ * stdin 写入内容预览;仅 `shell_write` 审批存在。
46
+ */
47
+ inputPreview?: string;
48
+ /**
49
+ * stdin 写入字符数;仅 `shell_write` 审批存在。
50
+ */
51
+ inputChars?: number;
52
+ /**
53
+ * 命令执行目录。
54
+ */
55
+ cwd: string;
56
+ /**
57
+ * 申请原因。
58
+ */
59
+ reason: string;
60
+ /**
61
+ * 当前审批创建时间。
62
+ */
63
+ createdAt: number;
64
+ /**
65
+ * 审批超时定时器。
66
+ */
67
+ timer: NodeJS.Timeout;
68
+ /**
69
+ * 兑现审批结果。
70
+ */
71
+ resolve: (status: ShellApprovalStatus) => void;
72
+ };
73
+ /**
74
+ * 单个 shell wait 调用挂起时注册的 waiter。
75
+ */
76
+ export type ShellSessionWaiter = {
77
+ /**
78
+ * 当前等待完成后的唤醒回调。
79
+ */
80
+ resolve: () => void;
81
+ /**
82
+ * 当前 waiter 对应的超时定时器。
83
+ */
84
+ timer: NodeJS.Timeout;
85
+ };
86
+ /**
87
+ * 单个 shell session 的内存运行态。
88
+ */
89
+ export type ShellSessionRuntimeState = {
90
+ /**
91
+ * 当前 shell session 的对外快照。
92
+ */
93
+ snapshot: ShellSessionSnapshot;
94
+ /**
95
+ * 当前 shell session 对应的子进程句柄。
96
+ */
97
+ child: ChildProcessWithoutNullStreams;
98
+ /**
99
+ * 当前已缓存的标准输出与标准错误文本。
100
+ */
101
+ outputText: string;
102
+ /**
103
+ * 当前输出持久化文件路径。
104
+ */
105
+ outputFilePath: string;
106
+ /**
107
+ * 当前快照持久化文件路径。
108
+ */
109
+ snapshotFilePath: string;
110
+ /**
111
+ * 串行化文件写入链,避免并发 append 乱序。
112
+ */
113
+ writeChain: Promise<void>;
114
+ /**
115
+ * 终态后的延迟清理定时器。
116
+ */
117
+ cleanupTimer: NodeJS.Timeout | null;
118
+ /**
119
+ * 当前挂起等待该 session 状态变化的 waiter 集合。
120
+ */
121
+ waiters: Set<ShellSessionWaiter>;
122
+ /**
123
+ * 当前 shell 进入终态后的完成 promise。
124
+ *
125
+ * 关键点(中文)
126
+ * - 供 `shell.exec` 这类 one-shot 路径直接等待进程结束。
127
+ * - 这样可以减少对版本轮询的依赖,降低瞬时命令的竞态超时。
128
+ */
129
+ completionPromise: Promise<void>;
130
+ /**
131
+ * 当前 shell 进入终态时触发的完成回调。
132
+ */
133
+ resolveCompletion: () => void;
134
+ };
135
+ /**
136
+ * `Shell` 实例级状态。
137
+ */
138
+ export type ShellRuntimeState = {
139
+ /**
140
+ * 当前 shell 归一化后的运行参数。
141
+ */
142
+ options: ResolvedShellRuntimeOptions;
143
+ /**
144
+ * 当前实例持有的全部 in-memory shell session。
145
+ */
146
+ sessions: Map<string, ShellSessionRuntimeState>;
147
+ /**
148
+ * 当前实例持有的全部 pending unrestricted sandbox 审批。
149
+ */
150
+ approvals: Map<string, ShellApprovalRuntimeState>;
151
+ /**
152
+ * 当前实例最近一次启动时绑定的 agent context。
153
+ *
154
+ * 关键点(中文)
155
+ * - 仅用于 shell 自动通知 chat 的回调路径。
156
+ * - 这是实例字段,不再是模块级全局变量。
157
+ */
158
+ context: ShellHostContext | null;
159
+ };
160
+ //# sourceMappingURL=ShellRuntimeTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShellRuntimeTypes.d.ts","sourceRoot":"","sources":["../../src/session/ShellRuntimeTypes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAElF;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,QAAQ,EAAE,qBAAqB,CAAC;IAChC;;;;;OAKG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;IACtC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC;IACtB;;OAEG;IACH,OAAO,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,IAAI,CAAC;CAChD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC;;OAEG;IACH,QAAQ,EAAE,oBAAoB,CAAC;IAC/B;;OAEG;IACH,KAAK,EAAE,8BAA8B,CAAC;IACtC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;IACpC;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACjC;;;;;;OAMG;IACH,iBAAiB,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC;;OAEG;IACH,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,OAAO,EAAE,2BAA2B,CAAC;IACrC;;OAEG;IACH,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IAChD;;OAEG;IACH,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;IAClD;;;;;;OAMG;IACH,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAClC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * ShellRuntime 类型定义。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这些类型描述 shell runtime 的实例级运行态。
6
+ * - 状态所有权归属于 `Shell` 实例,而不是模块级单例。
7
+ * - 统一归档到 `src/shell/` 相邻层级,避免继续分散在跨域目录里。
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=ShellRuntimeTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShellRuntimeTypes.js","sourceRoot":"","sources":["../../src/session/ShellRuntimeTypes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Shell action 共享辅助函数。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这里只放多个 action 都需要的轻量逻辑。
6
+ * - 不承载具体 action 编排,避免重新形成巨型模块。
7
+ */
8
+ import type { ShellSessionRuntimeState } from "../../session/ShellRuntimeTypes.js";
9
+ import type { ShellActionResponse, ShellApprovalStatus } from "../../types/ShellAction.js";
10
+ /**
11
+ * 解析默认 shell 路径。
12
+ */
13
+ export declare function resolveDefaultShellPath(): string;
14
+ /**
15
+ * 解析 shell action 请求的 sandbox 模式。
16
+ */
17
+ export declare function resolveSandboxMode(value: unknown): "safe" | "unrestricted";
18
+ /**
19
+ * 构造 shell_start / shell_exec 审批未通过时的统一响应。
20
+ */
21
+ export declare function buildDeniedApprovalResponse(params: {
22
+ /**
23
+ * shell session id。
24
+ */
25
+ shellId: string;
26
+ /**
27
+ * 归属的宿主 session id。
28
+ */
29
+ ownerContextId?: string;
30
+ /**
31
+ * 请求执行的命令。
32
+ */
33
+ cmd: string;
34
+ /**
35
+ * 请求执行目录。
36
+ */
37
+ cwd: string;
38
+ /**
39
+ * shell 程序路径。
40
+ */
41
+ shellPath: string;
42
+ /**
43
+ * approval id。
44
+ */
45
+ approvalId: string;
46
+ /**
47
+ * agent 给出的申请原因。
48
+ */
49
+ reason: string;
50
+ /**
51
+ * 审批结果状态。
52
+ */
53
+ approvalStatus: ShellApprovalStatus;
54
+ }): ShellActionResponse;
55
+ /**
56
+ * 构造 shell_write 审批未通过时的统一响应。
57
+ */
58
+ export declare function buildDeniedWriteApprovalResponse(params: {
59
+ /**
60
+ * 当前 shell session。
61
+ */
62
+ session: ShellSessionRuntimeState;
63
+ /**
64
+ * approval id。
65
+ */
66
+ approvalId: string;
67
+ /**
68
+ * agent 给出的申请原因。
69
+ */
70
+ reason: string;
71
+ /**
72
+ * 审批结果状态。
73
+ */
74
+ approvalStatus: ShellApprovalStatus;
75
+ }): ShellActionResponse;
76
+ //# sourceMappingURL=ShellActionShared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShellActionShared.d.ts","sourceRoot":"","sources":["../../../src/session/actions/ShellActionShared.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAMhC;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAIhD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,cAAc,CAE1E;AAQD;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE;IAClD;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,cAAc,EAAE,mBAAmB,CAAC;CACrC,GAAG,mBAAmB,CA0CtB;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAAC,MAAM,EAAE;IACvD;;OAEG;IACH,OAAO,EAAE,wBAAwB,CAAC;IAClC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,cAAc,EAAE,mBAAmB,CAAC;CACrC,GAAG,mBAAmB,CAqBtB"}
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Shell action 共享辅助函数。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这里只放多个 action 都需要的轻量逻辑。
6
+ * - 不承载具体 action 编排,避免重新形成巨型模块。
7
+ */
8
+ import { buildActionResponse, nowMs, } from "../ShellActionRuntimeSupport.js";
9
+ /**
10
+ * 解析默认 shell 路径。
11
+ */
12
+ export function resolveDefaultShellPath() {
13
+ const envShell = String(process.env.SHELL || "").trim();
14
+ if (envShell)
15
+ return envShell;
16
+ return process.platform === "darwin" ? "/bin/zsh" : "/bin/sh";
17
+ }
18
+ /**
19
+ * 解析 shell action 请求的 sandbox 模式。
20
+ */
21
+ export function resolveSandboxMode(value) {
22
+ return value === "unrestricted" ? "unrestricted" : "safe";
23
+ }
24
+ function approvalDeniedMessage(status) {
25
+ return status === "expired"
26
+ ? "Unrestricted sandbox approval expired."
27
+ : "User denied unrestricted sandbox execution.";
28
+ }
29
+ /**
30
+ * 构造 shell_start / shell_exec 审批未通过时的统一响应。
31
+ */
32
+ export function buildDeniedApprovalResponse(params) {
33
+ const now = nowMs();
34
+ const message = approvalDeniedMessage(params.approvalStatus);
35
+ return buildActionResponse({
36
+ shell: {
37
+ shellId: params.shellId,
38
+ ...(params.ownerContextId ? { ownerContextId: params.ownerContextId } : {}),
39
+ cmd: params.cmd,
40
+ cwd: params.cwd,
41
+ shellPath: params.shellPath,
42
+ sandboxed: false,
43
+ sandboxMode: "unrestricted",
44
+ sandboxBackend: "unrestricted-host",
45
+ sandboxNetworkMode: "full",
46
+ approvalStatus: params.approvalStatus,
47
+ approvalId: params.approvalId,
48
+ approvalReason: params.reason,
49
+ stdinWritable: true,
50
+ status: params.approvalStatus === "expired" ? "expired" : "failed",
51
+ startedAt: now,
52
+ updatedAt: now,
53
+ endedAt: now,
54
+ exitCode: -1,
55
+ lastOutputPreview: message,
56
+ outputChars: message.length,
57
+ droppedChars: 0,
58
+ version: 1,
59
+ autoNotifyOnExit: false,
60
+ notificationSent: false,
61
+ externalRefs: [],
62
+ },
63
+ chunk: {
64
+ shellId: params.shellId,
65
+ output: message,
66
+ startCursor: 0,
67
+ endCursor: message.length,
68
+ originalChars: message.length,
69
+ originalLines: 1,
70
+ hasMoreOutput: false,
71
+ },
72
+ note: message,
73
+ });
74
+ }
75
+ /**
76
+ * 构造 shell_write 审批未通过时的统一响应。
77
+ */
78
+ export function buildDeniedWriteApprovalResponse(params) {
79
+ const message = approvalDeniedMessage(params.approvalStatus);
80
+ return buildActionResponse({
81
+ shell: {
82
+ ...params.session.snapshot,
83
+ approvalStatus: params.approvalStatus,
84
+ approvalId: params.approvalId,
85
+ approvalReason: params.reason,
86
+ stdinWritable: true,
87
+ },
88
+ chunk: {
89
+ shellId: params.session.snapshot.shellId,
90
+ output: message,
91
+ startCursor: 0,
92
+ endCursor: message.length,
93
+ originalChars: message.length,
94
+ originalLines: 1,
95
+ hasMoreOutput: false,
96
+ },
97
+ note: message,
98
+ });
99
+ }
100
+ //# sourceMappingURL=ShellActionShared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShellActionShared.js","sourceRoot":"","sources":["../../../src/session/actions/ShellActionShared.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,EACL,mBAAmB,EACnB,KAAK,GACN,MAAM,iCAAiC,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxD,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;AAChE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,KAAK,KAAK,cAAc,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC;AAC5D,CAAC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AAE;SACjB;QACD,KAAK,EAAE;YACL,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE,OAAO;YACf,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,OAAO,CAAC,MAAM;YACzB,aAAa,EAAE,OAAO,CAAC,MAAM;YAC7B,aAAa,EAAE,CAAC;YAChB,aAAa,EAAE,KAAK;SACrB;QACD,IAAI,EAAE,OAAO;KACd,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gCAAgC,CAAC,MAiBhD;IACC,MAAM,OAAO,GAAG,qBAAqB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAC7D,OAAO,mBAAmB,CAAC;QACzB,KAAK,EAAE;YACL,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ;YAC1B,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,cAAc,EAAE,MAAM,CAAC,MAAM;YAC7B,aAAa,EAAE,IAAI;SACpB;QACD,KAAK,EAAE;YACL,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO;YACxC,MAAM,EAAE,OAAO;YACf,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,OAAO,CAAC,MAAM;YACzB,aAAa,EAAE,OAAO,CAAC,MAAM;YAC7B,aAAa,EAAE,CAAC;YAChB,aAAa,EAAE,KAAK;SACrB;QACD,IAAI,EAAE,OAAO;KACd,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Shell approval action。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这里只暴露 pending approval 查询与用户决策入口。
6
+ * - 具体 approval event、timeout、audit 仍由 approval 模块负责。
7
+ */
8
+ import type { ShellHostContext } from "../../types/ShellHostContext.js";
9
+ import type { ShellRuntimeState } from "../../session/ShellRuntimeTypes.js";
10
+ /**
11
+ * 列出 pending unrestricted sandbox 审批。
12
+ */
13
+ export declare function listShellApprovals(state: ShellRuntimeState): {
14
+ approvalId: string;
15
+ shellId: string;
16
+ ownerContextId?: string;
17
+ toolName: import("../../index.js").ShellApprovalToolName;
18
+ cmd: string;
19
+ operation: "exec" | "start" | "write";
20
+ inputPreview?: string;
21
+ inputChars?: number;
22
+ cwd: string;
23
+ reason: string;
24
+ createdAt: number;
25
+ }[];
26
+ /**
27
+ * 批准 pending unrestricted sandbox 审批。
28
+ */
29
+ export declare function approveShellApproval(state: ShellRuntimeState, context: ShellHostContext, approvalId: string): Promise<boolean>;
30
+ /**
31
+ * 拒绝 pending unrestricted sandbox 审批。
32
+ */
33
+ export declare function denyShellApproval(state: ShellRuntimeState, context: ShellHostContext, approvalId: string): Promise<boolean>;
34
+ //# sourceMappingURL=ShellApprovalActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShellApprovalActions.d.ts","sourceRoot":"","sources":["../../../src/session/actions/ShellApprovalActions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAMxE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB;;;;;;;;;;;;IAE1D;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,gBAAgB,EACzB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,gBAAgB,EACzB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,OAAO,CAAC,CAOlB"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Shell approval action。
3
+ *
4
+ * 关键点(中文)
5
+ * - 这里只暴露 pending approval 查询与用户决策入口。
6
+ * - 具体 approval event、timeout、audit 仍由 approval 模块负责。
7
+ */
8
+ import { listPendingApprovals, resolveApproval, } from "../../approval/ShellApprovalRuntime.js";
9
+ /**
10
+ * 列出 pending unrestricted sandbox 审批。
11
+ */
12
+ export function listShellApprovals(state) {
13
+ return listPendingApprovals(state);
14
+ }
15
+ /**
16
+ * 批准 pending unrestricted sandbox 审批。
17
+ */
18
+ export async function approveShellApproval(state, context, approvalId) {
19
+ return await resolveApproval({
20
+ state,
21
+ context,
22
+ approvalId,
23
+ decision: "approved",
24
+ });
25
+ }
26
+ /**
27
+ * 拒绝 pending unrestricted sandbox 审批。
28
+ */
29
+ export async function denyShellApproval(state, context, approvalId) {
30
+ return await resolveApproval({
31
+ state,
32
+ context,
33
+ approvalId,
34
+ decision: "denied",
35
+ });
36
+ }
37
+ //# sourceMappingURL=ShellApprovalActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShellApprovalActions.js","sourceRoot":"","sources":["../../../src/session/actions/ShellApprovalActions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EACL,oBAAoB,EACpB,eAAe,GAChB,MAAM,wCAAwC,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAwB;IACzD,OAAO,oBAAoB,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,KAAwB,EACxB,OAAyB,EACzB,UAAkB;IAElB,OAAO,MAAM,eAAe,CAAC;QAC3B,KAAK;QACL,OAAO;QACP,UAAU;QACV,QAAQ,EAAE,UAAU;KACrB,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,KAAwB,EACxB,OAAyB,EACzB,UAAkB;IAElB,OAAO,MAAM,eAAe,CAAC;QAC3B,KAAK;QACL,OAAO;QACP,UAAU;QACV,QAAQ,EAAE,QAAQ;KACnB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Shell exec action。
3
+ *
4
+ * 关键点(中文)
5
+ * - exec 是基于 start + wait + close 的 one-shot 编排。
6
+ * - 保留完整输出返回,适合短命令。
7
+ */
8
+ import type { ShellHostContext } from "../../types/ShellHostContext.js";
9
+ import type { ShellRuntimeState } from "../../session/ShellRuntimeTypes.js";
10
+ import type { ShellActionResponse, ShellExecRequest } from "../../types/ShellAction.js";
11
+ /**
12
+ * 以 one-shot 模式执行 shell command。
13
+ */
14
+ export declare function execShellCommand(state: ShellRuntimeState, context: ShellHostContext, request: ShellExecRequest): Promise<ShellActionResponse>;
15
+ //# sourceMappingURL=ShellExecActions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShellExecActions.d.ts","sourceRoot":"","sources":["../../../src/session/actions/ShellExecActions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,KAAK,EACV,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAmBhC;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,iBAAiB,EACxB,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,mBAAmB,CAAC,CA6G9B"}
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Shell exec action。
3
+ *
4
+ * 关键点(中文)
5
+ * - exec 是基于 start + wait + close 的 one-shot 编排。
6
+ * - 保留完整输出返回,适合短命令。
7
+ */
8
+ import { buildActionResponse, clampWaitMsWithOptions, createOutputChunk, isTerminalStatus, nowMs, resolveSession, } from "../ShellActionRuntimeSupport.js";
9
+ import { closeShellSession } from "./ShellQueryActions.js";
10
+ import { startShellSession } from "./ShellStartActions.js";
11
+ async function sleep(ms) {
12
+ await new Promise((resolve) => {
13
+ const timer = setTimeout(resolve, ms);
14
+ if (typeof timer.unref === "function")
15
+ timer.unref();
16
+ });
17
+ }
18
+ /**
19
+ * 以 one-shot 模式执行 shell command。
20
+ */
21
+ export async function execShellCommand(state, context, request) {
22
+ const timeoutMs = clampWaitMsWithOptions(state.options, request.timeoutMs, state.options.defaultExecTimeoutMs);
23
+ const started = await startShellSession(state, context, {
24
+ cmd: request.cmd,
25
+ ...(request.cwd ? { cwd: request.cwd } : {}),
26
+ ...(request.shell ? { shell: request.shell } : {}),
27
+ login: request.login,
28
+ sandbox: request.sandbox,
29
+ reason: request.reason,
30
+ approvalToolName: "shell_exec",
31
+ inlineWaitMs: Math.min(state.options.defaultInlineWaitMs, timeoutMs),
32
+ maxOutputTokens: request.maxOutputTokens,
33
+ autoNotifyOnExit: false,
34
+ });
35
+ let current = started;
36
+ let fromCursor = current.chunk?.endCursor ?? 0;
37
+ const outputParts = [];
38
+ if (current.chunk?.output) {
39
+ outputParts.push(current.chunk.output);
40
+ }
41
+ const deadline = nowMs() + timeoutMs;
42
+ while (!isTerminalStatus(current.shell.status)) {
43
+ const remaining = deadline - nowMs();
44
+ if (remaining <= 0) {
45
+ await closeShellSession(state, context, {
46
+ shellId: current.shell.shellId,
47
+ force: true,
48
+ });
49
+ throw new Error(`shell.exec timed out after ${timeoutMs}ms. Use shell_start for long-running commands.`);
50
+ }
51
+ const inMemory = state.sessions.get(current.shell.shellId);
52
+ if (inMemory &&
53
+ (inMemory.snapshot.status === "running" ||
54
+ inMemory.snapshot.status === "starting")) {
55
+ await Promise.race([
56
+ inMemory.completionPromise,
57
+ sleep(Math.min(remaining, 250)),
58
+ ]);
59
+ }
60
+ else {
61
+ await sleep(Math.min(remaining, 250));
62
+ }
63
+ const refreshed = await resolveSession(state, context, {
64
+ shellId: current.shell.shellId,
65
+ includeCompleted: true,
66
+ });
67
+ if (!refreshed) {
68
+ throw new Error(`shell session disappeared unexpectedly: ${current.shell.shellId}`);
69
+ }
70
+ const chunk = createOutputChunk({
71
+ shellId: current.shell.shellId,
72
+ outputText: refreshed.outputText,
73
+ fromCursor,
74
+ context,
75
+ maxOutputTokens: request.maxOutputTokens,
76
+ });
77
+ current = buildActionResponse({
78
+ shell: refreshed.snapshot,
79
+ chunk,
80
+ });
81
+ if (chunk.output) {
82
+ outputParts.push(chunk.output);
83
+ }
84
+ if (typeof chunk.endCursor === "number") {
85
+ fromCursor = chunk.endCursor;
86
+ }
87
+ }
88
+ const finalSession = state.sessions.get(current.shell.shellId);
89
+ if (finalSession) {
90
+ await finalSession.completionPromise;
91
+ await finalSession.writeChain.catch(() => undefined);
92
+ }
93
+ await closeShellSession(state, context, {
94
+ shellId: current.shell.shellId,
95
+ force: false,
96
+ }).catch(() => undefined);
97
+ const completed = await resolveSession(state, context, {
98
+ shellId: current.shell.shellId,
99
+ includeCompleted: true,
100
+ });
101
+ const fullOutput = completed?.outputText ?? outputParts.join("");
102
+ const originalLines = fullOutput ? fullOutput.split("\n").length : 0;
103
+ return buildActionResponse({
104
+ shell: current.shell,
105
+ chunk: {
106
+ shellId: current.shell.shellId,
107
+ output: fullOutput,
108
+ startCursor: 0,
109
+ endCursor: fullOutput.length,
110
+ originalChars: fullOutput.length,
111
+ originalLines,
112
+ hasMoreOutput: false,
113
+ },
114
+ note: "shell exec completed in one-shot mode",
115
+ });
116
+ }
117
+ //# sourceMappingURL=ShellExecActions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShellExecActions.js","sourceRoot":"","sources":["../../../src/session/actions/ShellExecActions.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,EACL,cAAc,GACf,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,KAAK,UAAU,KA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