@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.
- package/bin/Shell.d.ts +55 -0
- package/bin/Shell.d.ts.map +1 -0
- package/bin/Shell.js +171 -0
- package/bin/Shell.js.map +1 -0
- package/bin/approval/ShellApprovalRuntime.d.ts +62 -0
- package/bin/approval/ShellApprovalRuntime.d.ts.map +1 -0
- package/bin/approval/ShellApprovalRuntime.js +214 -0
- package/bin/approval/ShellApprovalRuntime.js.map +1 -0
- package/bin/index.d.ts +27 -0
- package/bin/index.d.ts.map +1 -0
- package/bin/index.js +26 -0
- package/bin/index.js.map +1 -0
- package/bin/sandbox/LinuxBubblewrapSandbox.d.ts +19 -0
- package/bin/sandbox/LinuxBubblewrapSandbox.d.ts.map +1 -0
- package/bin/sandbox/LinuxBubblewrapSandbox.js +186 -0
- package/bin/sandbox/LinuxBubblewrapSandbox.js.map +1 -0
- package/bin/sandbox/MacOsSeatbeltSandbox.d.ts +16 -0
- package/bin/sandbox/MacOsSeatbeltSandbox.d.ts.map +1 -0
- package/bin/sandbox/MacOsSeatbeltSandbox.js +154 -0
- package/bin/sandbox/MacOsSeatbeltSandbox.js.map +1 -0
- package/bin/sandbox/SandboxConfigResolver.d.ts +37 -0
- package/bin/sandbox/SandboxConfigResolver.d.ts.map +1 -0
- package/bin/sandbox/SandboxConfigResolver.js +130 -0
- package/bin/sandbox/SandboxConfigResolver.js.map +1 -0
- package/bin/sandbox/SandboxPreflight.d.ts +73 -0
- package/bin/sandbox/SandboxPreflight.d.ts.map +1 -0
- package/bin/sandbox/SandboxPreflight.js +122 -0
- package/bin/sandbox/SandboxPreflight.js.map +1 -0
- package/bin/sandbox/SandboxRunner.d.ts +61 -0
- package/bin/sandbox/SandboxRunner.d.ts.map +1 -0
- package/bin/sandbox/SandboxRunner.js +107 -0
- package/bin/sandbox/SandboxRunner.js.map +1 -0
- package/bin/sandbox/UnrestrictedSandbox.d.ts +16 -0
- package/bin/sandbox/UnrestrictedSandbox.d.ts.map +1 -0
- package/bin/sandbox/UnrestrictedSandbox.js +39 -0
- package/bin/sandbox/UnrestrictedSandbox.js.map +1 -0
- package/bin/sandbox/types/Sandbox.d.ts +130 -0
- package/bin/sandbox/types/Sandbox.d.ts.map +1 -0
- package/bin/sandbox/types/Sandbox.js +10 -0
- package/bin/sandbox/types/Sandbox.js.map +1 -0
- package/bin/sandbox/types/SandboxRuntime.d.ts +370 -0
- package/bin/sandbox/types/SandboxRuntime.d.ts.map +1 -0
- package/bin/sandbox/types/SandboxRuntime.js +10 -0
- package/bin/sandbox/types/SandboxRuntime.js.map +1 -0
- package/bin/session/Paths.d.ts +12 -0
- package/bin/session/Paths.d.ts.map +1 -0
- package/bin/session/Paths.js +21 -0
- package/bin/session/Paths.js.map +1 -0
- package/bin/session/ShellActionResponse.d.ts +52 -0
- package/bin/session/ShellActionResponse.d.ts.map +1 -0
- package/bin/session/ShellActionResponse.js +73 -0
- package/bin/session/ShellActionResponse.js.map +1 -0
- package/bin/session/ShellActionRuntime.d.ts +15 -0
- package/bin/session/ShellActionRuntime.d.ts.map +1 -0
- package/bin/session/ShellActionRuntime.js +15 -0
- package/bin/session/ShellActionRuntime.js.map +1 -0
- package/bin/session/ShellActionRuntimeSupport.d.ts +88 -0
- package/bin/session/ShellActionRuntimeSupport.d.ts.map +1 -0
- package/bin/session/ShellActionRuntimeSupport.js +305 -0
- package/bin/session/ShellActionRuntimeSupport.js.map +1 -0
- package/bin/session/ShellProcessEvents.d.ts +22 -0
- package/bin/session/ShellProcessEvents.d.ts.map +1 -0
- package/bin/session/ShellProcessEvents.js +41 -0
- package/bin/session/ShellProcessEvents.js.map +1 -0
- package/bin/session/ShellRunScope.d.ts +43 -0
- package/bin/session/ShellRunScope.d.ts.map +1 -0
- package/bin/session/ShellRunScope.js +29 -0
- package/bin/session/ShellRunScope.js.map +1 -0
- package/bin/session/ShellRuntimeEnvironment.d.ts +21 -0
- package/bin/session/ShellRuntimeEnvironment.d.ts.map +1 -0
- package/bin/session/ShellRuntimeEnvironment.js +69 -0
- package/bin/session/ShellRuntimeEnvironment.js.map +1 -0
- package/bin/session/ShellRuntimeTypes.d.ts +160 -0
- package/bin/session/ShellRuntimeTypes.d.ts.map +1 -0
- package/bin/session/ShellRuntimeTypes.js +10 -0
- package/bin/session/ShellRuntimeTypes.js.map +1 -0
- package/bin/session/actions/ShellActionShared.d.ts +76 -0
- package/bin/session/actions/ShellActionShared.d.ts.map +1 -0
- package/bin/session/actions/ShellActionShared.js +100 -0
- package/bin/session/actions/ShellActionShared.js.map +1 -0
- package/bin/session/actions/ShellApprovalActions.d.ts +34 -0
- package/bin/session/actions/ShellApprovalActions.d.ts.map +1 -0
- package/bin/session/actions/ShellApprovalActions.js +37 -0
- package/bin/session/actions/ShellApprovalActions.js.map +1 -0
- package/bin/session/actions/ShellExecActions.d.ts +15 -0
- package/bin/session/actions/ShellExecActions.d.ts.map +1 -0
- package/bin/session/actions/ShellExecActions.js +117 -0
- package/bin/session/actions/ShellExecActions.js.map +1 -0
- package/bin/session/actions/ShellLifecycleActions.d.ts +18 -0
- package/bin/session/actions/ShellLifecycleActions.d.ts.map +1 -0
- package/bin/session/actions/ShellLifecycleActions.js +53 -0
- package/bin/session/actions/ShellLifecycleActions.js.map +1 -0
- package/bin/session/actions/ShellQueryActions.d.ts +27 -0
- package/bin/session/actions/ShellQueryActions.d.ts.map +1 -0
- package/bin/session/actions/ShellQueryActions.js +151 -0
- package/bin/session/actions/ShellQueryActions.js.map +1 -0
- package/bin/session/actions/ShellStartActions.d.ts +15 -0
- package/bin/session/actions/ShellStartActions.d.ts.map +1 -0
- package/bin/session/actions/ShellStartActions.js +167 -0
- package/bin/session/actions/ShellStartActions.js.map +1 -0
- package/bin/session/actions/ShellWriteActions.d.ts +15 -0
- package/bin/session/actions/ShellWriteActions.d.ts.map +1 -0
- package/bin/session/actions/ShellWriteActions.js +85 -0
- package/bin/session/actions/ShellWriteActions.js.map +1 -0
- package/bin/tool/ShellToolFormatting.d.ts +12 -0
- package/bin/tool/ShellToolFormatting.d.ts.map +1 -0
- package/bin/tool/ShellToolFormatting.js +31 -0
- package/bin/tool/ShellToolFormatting.js.map +1 -0
- package/bin/tool/ShellToolSchemas.d.ts +61 -0
- package/bin/tool/ShellToolSchemas.d.ts.map +1 -0
- package/bin/tool/ShellToolSchemas.js +130 -0
- package/bin/tool/ShellToolSchemas.js.map +1 -0
- package/bin/tool/ShellTools.d.ts +32 -0
- package/bin/tool/ShellTools.d.ts.map +1 -0
- package/bin/tool/ShellTools.js +296 -0
- package/bin/tool/ShellTools.js.map +1 -0
- package/bin/types/Shell.d.ts +115 -0
- package/bin/types/Shell.d.ts.map +1 -0
- package/bin/types/Shell.js +9 -0
- package/bin/types/Shell.js.map +1 -0
- package/bin/types/ShellAction.d.ts +258 -0
- package/bin/types/ShellAction.d.ts.map +1 -0
- package/bin/types/ShellAction.js +9 -0
- package/bin/types/ShellAction.js.map +1 -0
- package/bin/types/ShellHostContext.d.ts +78 -0
- package/bin/types/ShellHostContext.d.ts.map +1 -0
- package/bin/types/ShellHostContext.js +9 -0
- package/bin/types/ShellHostContext.js.map +1 -0
- package/bin/types/ShellRuntime.d.ts +128 -0
- package/bin/types/ShellRuntime.d.ts.map +1 -0
- package/bin/types/ShellRuntime.js +9 -0
- package/bin/types/ShellRuntime.js.map +1 -0
- package/bin/types/ShellRuntimeOptions.d.ts +103 -0
- package/bin/types/ShellRuntimeOptions.d.ts.map +1 -0
- package/bin/types/ShellRuntimeOptions.js +10 -0
- package/bin/types/ShellRuntimeOptions.js.map +1 -0
- package/bin/utils/Id.d.ts +11 -0
- package/bin/utils/Id.d.ts.map +1 -0
- package/bin/utils/Id.js +14 -0
- package/bin/utils/Id.js.map +1 -0
- package/package.json +81 -0
package/bin/Shell.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell 对象入口。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - Shell 是 `@downcity/shell` 的主要对外对象,拥有 tools、sessions、sandbox 与 approvals。
|
|
6
|
+
* - Agent 只组合 Shell 实例,不再通过 Shell 间接调用 shell 能力。
|
|
7
|
+
*/
|
|
8
|
+
import type { ShellApprovalDecisionResult, ShellApprovalView, ShellConfigureOptions, ShellOptions, ShellToolSet } from "./types/ShellRuntime.js";
|
|
9
|
+
/**
|
|
10
|
+
* Shell 运行时对象。
|
|
11
|
+
*/
|
|
12
|
+
export declare class Shell {
|
|
13
|
+
/**
|
|
14
|
+
* Shell 内部状态。
|
|
15
|
+
*/
|
|
16
|
+
private readonly state;
|
|
17
|
+
/**
|
|
18
|
+
* Shell 宿主配置。
|
|
19
|
+
*/
|
|
20
|
+
private host_options;
|
|
21
|
+
/**
|
|
22
|
+
* 模型可调用的 shell tools。
|
|
23
|
+
*/
|
|
24
|
+
readonly tools: ShellToolSet;
|
|
25
|
+
constructor(options?: ShellOptions);
|
|
26
|
+
/**
|
|
27
|
+
* 补齐宿主上下文。
|
|
28
|
+
*
|
|
29
|
+
* 关键点(中文):这是 Agent 内部装配入口,用户只需要 `new Agent({ shell: new Shell() })`。
|
|
30
|
+
*/
|
|
31
|
+
configure(options: ShellConfigureOptions): void;
|
|
32
|
+
/**
|
|
33
|
+
* 列出 pending approvals。
|
|
34
|
+
*/
|
|
35
|
+
approvals(): ShellApprovalView[];
|
|
36
|
+
/**
|
|
37
|
+
* 批准 pending approval。
|
|
38
|
+
*/
|
|
39
|
+
approve(input: {
|
|
40
|
+
approval_id: string;
|
|
41
|
+
}): Promise<ShellApprovalDecisionResult>;
|
|
42
|
+
/**
|
|
43
|
+
* 拒绝 pending approval。
|
|
44
|
+
*/
|
|
45
|
+
deny(input: {
|
|
46
|
+
approval_id: string;
|
|
47
|
+
}): Promise<ShellApprovalDecisionResult>;
|
|
48
|
+
/**
|
|
49
|
+
* 释放所有 shell sessions。
|
|
50
|
+
*/
|
|
51
|
+
dispose(): Promise<void>;
|
|
52
|
+
private run_action;
|
|
53
|
+
private create_host_context;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=Shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Shell.d.ts","sourceRoot":"","sources":["../src/Shell.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EACV,2BAA2B,EAC3B,iBAAiB,EACjB,qBAAqB,EACrB,YAAY,EACZ,YAAY,EACb,MAAM,yBAAyB,CAAC;AAuBjC;;GAEG;AACH,qBAAa,KAAK;IAChB;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoB;IAE1C;;OAEG;IACH,OAAO,CAAC,YAAY,CAAwB;IAE5C;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;gBAEjB,OAAO,GAAE,YAAiB;IAQtC;;;;OAIG;IACH,SAAS,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI;IAc/C;;OAEG;IACH,SAAS,IAAI,iBAAiB,EAAE;IAgBhC;;OAEG;IACG,OAAO,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAWnF;;OAEG;IACG,IAAI,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAWhF;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAYhB,UAAU;IAyBxB,OAAO,CAAC,mBAAmB;CAqC5B"}
|
package/bin/Shell.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell 对象入口。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - Shell 是 `@downcity/shell` 的主要对外对象,拥有 tools、sessions、sandbox 与 approvals。
|
|
6
|
+
* - Agent 只组合 Shell 实例,不再通过 Shell 间接调用 shell 能力。
|
|
7
|
+
*/
|
|
8
|
+
import { approveShellApproval, closeAllShellSessions, closeShellSession, createShellRuntimeState, denyShellApproval, execShellCommand, getShellSessionStatus, listShellApprovals, readShellSession, startShellSession, waitShellSession, writeShellSession, } from "./session/ShellActionRuntime.js";
|
|
9
|
+
import { createShellTools, } from "./tool/ShellTools.js";
|
|
10
|
+
import { getShellRunContext } from "./session/ShellRunScope.js";
|
|
11
|
+
/**
|
|
12
|
+
* Shell 运行时对象。
|
|
13
|
+
*/
|
|
14
|
+
export class Shell {
|
|
15
|
+
/**
|
|
16
|
+
* Shell 内部状态。
|
|
17
|
+
*/
|
|
18
|
+
state;
|
|
19
|
+
/**
|
|
20
|
+
* Shell 宿主配置。
|
|
21
|
+
*/
|
|
22
|
+
host_options;
|
|
23
|
+
/**
|
|
24
|
+
* 模型可调用的 shell tools。
|
|
25
|
+
*/
|
|
26
|
+
tools;
|
|
27
|
+
constructor(options = {}) {
|
|
28
|
+
this.host_options = { ...options };
|
|
29
|
+
this.state = createShellRuntimeState();
|
|
30
|
+
this.tools = createShellTools({
|
|
31
|
+
run_action: async (params) => await this.run_action(params.action, params.payload),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 补齐宿主上下文。
|
|
36
|
+
*
|
|
37
|
+
* 关键点(中文):这是 Agent 内部装配入口,用户只需要 `new Agent({ shell: new Shell() })`。
|
|
38
|
+
*/
|
|
39
|
+
configure(options) {
|
|
40
|
+
this.host_options = {
|
|
41
|
+
...this.host_options,
|
|
42
|
+
...options,
|
|
43
|
+
env: {
|
|
44
|
+
...(this.host_options.env || {}),
|
|
45
|
+
...(options.env || {}),
|
|
46
|
+
},
|
|
47
|
+
sandbox: options.sandbox || this.host_options.sandbox,
|
|
48
|
+
logger: options.logger || this.host_options.logger,
|
|
49
|
+
emit_event: options.emit_event || this.host_options.emit_event,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 列出 pending approvals。
|
|
54
|
+
*/
|
|
55
|
+
approvals() {
|
|
56
|
+
return listShellApprovals(this.state).map((item) => ({
|
|
57
|
+
approval_id: item.approvalId,
|
|
58
|
+
shell_id: item.shellId,
|
|
59
|
+
...(item.ownerContextId ? { session_id: item.ownerContextId } : {}),
|
|
60
|
+
tool_name: item.toolName,
|
|
61
|
+
cmd: item.cmd,
|
|
62
|
+
operation: item.operation,
|
|
63
|
+
...(item.inputPreview !== undefined ? { input_preview: item.inputPreview } : {}),
|
|
64
|
+
...(typeof item.inputChars === "number" ? { input_chars: item.inputChars } : {}),
|
|
65
|
+
cwd: item.cwd,
|
|
66
|
+
reason: item.reason,
|
|
67
|
+
created_at: item.createdAt,
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 批准 pending approval。
|
|
72
|
+
*/
|
|
73
|
+
async approve(input) {
|
|
74
|
+
const approval_id = String(input.approval_id || "").trim();
|
|
75
|
+
if (!approval_id)
|
|
76
|
+
throw new Error("approval_id is required");
|
|
77
|
+
const success = await approveShellApproval(this.state, this.create_host_context(), approval_id);
|
|
78
|
+
return {
|
|
79
|
+
success,
|
|
80
|
+
approval_id,
|
|
81
|
+
decision: "approved",
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 拒绝 pending approval。
|
|
86
|
+
*/
|
|
87
|
+
async deny(input) {
|
|
88
|
+
const approval_id = String(input.approval_id || "").trim();
|
|
89
|
+
if (!approval_id)
|
|
90
|
+
throw new Error("approval_id is required");
|
|
91
|
+
const success = await denyShellApproval(this.state, this.create_host_context(), approval_id);
|
|
92
|
+
return {
|
|
93
|
+
success,
|
|
94
|
+
approval_id,
|
|
95
|
+
decision: "denied",
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 释放所有 shell sessions。
|
|
100
|
+
*/
|
|
101
|
+
async dispose() {
|
|
102
|
+
await closeAllShellSessions(this.state, true);
|
|
103
|
+
for (const session of this.state.sessions.values()) {
|
|
104
|
+
if (session.cleanupTimer) {
|
|
105
|
+
clearTimeout(session.cleanupTimer);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
this.state.sessions.clear();
|
|
109
|
+
this.state.approvals.clear();
|
|
110
|
+
this.state.context = null;
|
|
111
|
+
}
|
|
112
|
+
async run_action(action, payload) {
|
|
113
|
+
const context = this.create_host_context();
|
|
114
|
+
switch (action) {
|
|
115
|
+
case "start":
|
|
116
|
+
return await startShellSession(this.state, context, payload);
|
|
117
|
+
case "exec":
|
|
118
|
+
return await execShellCommand(this.state, context, payload);
|
|
119
|
+
case "status":
|
|
120
|
+
return await getShellSessionStatus(this.state, context, payload);
|
|
121
|
+
case "read":
|
|
122
|
+
return await readShellSession(this.state, context, payload);
|
|
123
|
+
case "write":
|
|
124
|
+
return await writeShellSession(this.state, context, payload);
|
|
125
|
+
case "wait":
|
|
126
|
+
return await waitShellSession(this.state, context, payload);
|
|
127
|
+
case "close":
|
|
128
|
+
return await closeShellSession(this.state, context, payload);
|
|
129
|
+
default:
|
|
130
|
+
throw new Error(`Unknown shell action: ${String(action)}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
create_host_context() {
|
|
134
|
+
const root_path = String(this.host_options.root_path || "").trim();
|
|
135
|
+
if (!root_path) {
|
|
136
|
+
throw new Error("Shell requires root_path. Pass Shell through new Agent({ shell }) or construct Shell with root_path.");
|
|
137
|
+
}
|
|
138
|
+
const emit_event = this.host_options.emit_event;
|
|
139
|
+
const run_context = getShellRunContext() || null;
|
|
140
|
+
const session_id = String(run_context?.session_id || "").trim();
|
|
141
|
+
const turn_id = String(run_context?.turn_id || "").trim();
|
|
142
|
+
return {
|
|
143
|
+
rootPath: root_path,
|
|
144
|
+
env: this.host_options.env,
|
|
145
|
+
config: {
|
|
146
|
+
...(this.host_options.agent_id ? { id: this.host_options.agent_id } : {}),
|
|
147
|
+
...(this.host_options.sandbox ? { sandbox: this.host_options.sandbox } : {}),
|
|
148
|
+
},
|
|
149
|
+
logger: this.host_options.logger,
|
|
150
|
+
session: emit_event
|
|
151
|
+
? {
|
|
152
|
+
get: (target_session_id) => ({
|
|
153
|
+
publishEvent: (event) => {
|
|
154
|
+
emit_event({
|
|
155
|
+
...event,
|
|
156
|
+
session_id: String(target_session_id || session_id || "").trim(),
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
}),
|
|
160
|
+
}
|
|
161
|
+
: undefined,
|
|
162
|
+
shellIntegration: {
|
|
163
|
+
getRunContext: () => ({
|
|
164
|
+
...(session_id ? { sessionId: session_id } : {}),
|
|
165
|
+
...(turn_id ? { turnId: turn_id } : {}),
|
|
166
|
+
}),
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=Shell.js.map
|
package/bin/Shell.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Shell.js","sourceRoot":"","sources":["../src/Shell.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,gBAAgB,GAEjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE;;GAEG;AACH,MAAM,OAAO,KAAK;IAChB;;OAEG;IACc,KAAK,CAAoB;IAE1C;;OAEG;IACK,YAAY,CAAwB;IAE5C;;OAEG;IACM,KAAK,CAAe;IAE7B,YAAY,UAAwB,EAAE;QACpC,IAAI,CAAC,YAAY,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;QACnC,IAAI,CAAC,KAAK,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AM;YAChC,OAAO,EAAE,UAAU;gBACjB,CAAC,CAAC;oBACE,GAAG,EAAE,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;wBAC3B,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;4BACtB,UAAU,CAAC;gCACT,GAAG,KAAK;gCACR,UAAU,EAAE,MAAM,CAAC,iBAAiB,IAAI,UAAU,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;6BACjE,CAAC,CAAC;wBACL,CAAC;qBACF,CAAC;iBACH;gBACH,CAAC,CAAC,SAAS;YACb,gBAAgB,EAAE;gBAChB,aAAa,EAAE,GAAG,EAAE,CAAC,CAAC;oBACpB,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAChD,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBACxC,CAAC;aACH;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell unrestricted sandbox 审批运行时。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - agent 只能通过 shell tool 请求 unrestricted sandbox;真正执行前必须等待用户确认。
|
|
6
|
+
* - 审批结果最终回到原 tool result;session event 只用于 UI/CLI/Console 展示和操作。
|
|
7
|
+
* - V1 授权粒度固定为单次命令、单次 shell_start 启动,或单次 shell_write 输入。
|
|
8
|
+
*/
|
|
9
|
+
import type { ShellHostContext } from "../types/ShellHostContext.js";
|
|
10
|
+
import type { ShellApprovalStatus, ShellApprovalToolName } from "../types/ShellAction.js";
|
|
11
|
+
import type { ShellRuntimeState } from "../session/ShellRuntimeTypes.js";
|
|
12
|
+
/**
|
|
13
|
+
* 校验 unrestricted sandbox 请求。
|
|
14
|
+
*/
|
|
15
|
+
export declare function validateUnrestrictedRequest(params: {
|
|
16
|
+
cmd: string;
|
|
17
|
+
reason?: string;
|
|
18
|
+
}): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* 请求用户批准 unrestricted sandbox 执行。
|
|
21
|
+
*/
|
|
22
|
+
export declare function requestUnrestrictedApproval(params: {
|
|
23
|
+
state: ShellRuntimeState;
|
|
24
|
+
context: ShellHostContext;
|
|
25
|
+
shellId: string;
|
|
26
|
+
toolName: ShellApprovalToolName;
|
|
27
|
+
cmd: string;
|
|
28
|
+
cwd: string;
|
|
29
|
+
reason: string;
|
|
30
|
+
ownerContextId?: string;
|
|
31
|
+
inputPreview?: string;
|
|
32
|
+
inputChars?: number;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
approvalId: string;
|
|
35
|
+
status: ShellApprovalStatus;
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* 兑现 unrestricted sandbox 审批。
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveApproval(params: {
|
|
41
|
+
state: ShellRuntimeState;
|
|
42
|
+
context: ShellHostContext;
|
|
43
|
+
approvalId: string;
|
|
44
|
+
decision: ShellApprovalStatus;
|
|
45
|
+
}): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* 列出 pending unrestricted sandbox 审批。
|
|
48
|
+
*/
|
|
49
|
+
export declare function listPendingApprovals(state: ShellRuntimeState): Array<{
|
|
50
|
+
approvalId: string;
|
|
51
|
+
shellId: string;
|
|
52
|
+
ownerContextId?: string;
|
|
53
|
+
toolName: ShellApprovalToolName;
|
|
54
|
+
cmd: string;
|
|
55
|
+
operation: "exec" | "start" | "write";
|
|
56
|
+
inputPreview?: string;
|
|
57
|
+
inputChars?: number;
|
|
58
|
+
cwd: string;
|
|
59
|
+
reason: string;
|
|
60
|
+
createdAt: number;
|
|
61
|
+
}>;
|
|
62
|
+
//# sourceMappingURL=ShellApprovalRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShellApproval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AU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,qBAAqB,CAAC;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC,CAcD"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell unrestricted sandbox 审批运行时。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - agent 只能通过 shell tool 请求 unrestricted sandbox;真正执行前必须等待用户确认。
|
|
6
|
+
* - 审批结果最终回到原 tool result;session event 只用于 UI/CLI/Console 展示和操作。
|
|
7
|
+
* - V1 授权粒度固定为单次命令、单次 shell_start 启动,或单次 shell_write 输入。
|
|
8
|
+
*/
|
|
9
|
+
import fs from "fs-extra";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { generateId } from "../utils/Id.js";
|
|
12
|
+
import { nowMs } from "../session/ShellActionRuntimeSupport.js";
|
|
13
|
+
const DANGEROUS_COMMAND_PATTERNS = [
|
|
14
|
+
/\bsudo\b/,
|
|
15
|
+
/\brm\s+-[^&|;\n]*r[^&|;\n]*f\s+\/(?:\s|$)/,
|
|
16
|
+
/\bchmod\s+-R\s+777\s+\/(?:\s|$)/,
|
|
17
|
+
/\bssh-keygen\b/,
|
|
18
|
+
/\bsecurity\s+(?:add|delete|unlock|set|import|export)-/i,
|
|
19
|
+
/(?:^|[\s;&|])(?:nohup\s+)?[^;&|\n]*(?:&)\s*$/,
|
|
20
|
+
];
|
|
21
|
+
function isDangerousCommand(cmd) {
|
|
22
|
+
return DANGEROUS_COMMAND_PATTERNS.some((pattern) => pattern.test(cmd));
|
|
23
|
+
}
|
|
24
|
+
function resolveApprovalOperation(toolName) {
|
|
25
|
+
if (toolName === "shell_write")
|
|
26
|
+
return "write";
|
|
27
|
+
if (toolName === "shell_exec")
|
|
28
|
+
return "exec";
|
|
29
|
+
return "start";
|
|
30
|
+
}
|
|
31
|
+
function buildInputPreview(value) {
|
|
32
|
+
const normalized = String(value || "");
|
|
33
|
+
if (normalized.length <= 240)
|
|
34
|
+
return normalized;
|
|
35
|
+
return `${normalized.slice(0, 240)}...`;
|
|
36
|
+
}
|
|
37
|
+
function resolveAuditPath(context) {
|
|
38
|
+
return path.join(context.rootPath, ".downcity", "logs", "unrestricted-sandbox-audit.jsonl");
|
|
39
|
+
}
|
|
40
|
+
async function appendAudit(params) {
|
|
41
|
+
const filePath = resolveAuditPath(params.context);
|
|
42
|
+
await fs.ensureDir(path.dirname(filePath));
|
|
43
|
+
await fs.appendFile(filePath, `${JSON.stringify(params.record)}\n`, "utf-8");
|
|
44
|
+
}
|
|
45
|
+
function publishApprovalResult(params) {
|
|
46
|
+
const sessionId = String(params.ownerContextId || "").trim();
|
|
47
|
+
if (!sessionId || !params.context.session)
|
|
48
|
+
return;
|
|
49
|
+
const turnId = String(params.context.shellIntegration?.getRunContext?.()?.turnId || sessionId).trim();
|
|
50
|
+
try {
|
|
51
|
+
params.context.session.get(sessionId).publishEvent({
|
|
52
|
+
type: "tool-approval-result",
|
|
53
|
+
turnId,
|
|
54
|
+
toolCallId: params.shellId,
|
|
55
|
+
toolName: params.toolName,
|
|
56
|
+
approvalId: params.approvalId,
|
|
57
|
+
decision: params.decision,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// ignore event delivery failures
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 校验 unrestricted sandbox 请求。
|
|
66
|
+
*/
|
|
67
|
+
export function validateUnrestrictedRequest(params) {
|
|
68
|
+
const reason = String(params.reason || "").trim();
|
|
69
|
+
if (!reason) {
|
|
70
|
+
return "unrestricted sandbox requires a non-empty reason";
|
|
71
|
+
}
|
|
72
|
+
if (isDangerousCommand(params.cmd)) {
|
|
73
|
+
return "unrestricted sandbox rejected a dangerous command";
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 请求用户批准 unrestricted sandbox 执行。
|
|
79
|
+
*/
|
|
80
|
+
export async function requestUnrestrictedApproval(params) {
|
|
81
|
+
const approvalId = `ap_${generateId()}`;
|
|
82
|
+
const createdAt = nowMs();
|
|
83
|
+
const ownerContextId = String(params.ownerContextId || "").trim() || undefined;
|
|
84
|
+
const operation = resolveApprovalOperation(params.toolName);
|
|
85
|
+
const inputPreview = params.inputPreview !== undefined
|
|
86
|
+
? buildInputPreview(params.inputPreview)
|
|
87
|
+
: undefined;
|
|
88
|
+
const status = await new Promise((resolve) => {
|
|
89
|
+
const timer = setTimeout(() => {
|
|
90
|
+
resolveApproval({
|
|
91
|
+
state: params.state,
|
|
92
|
+
context: params.context,
|
|
93
|
+
approvalId,
|
|
94
|
+
decision: "expired",
|
|
95
|
+
}).catch(() => undefined);
|
|
96
|
+
}, params.state.options.defaultApprovalTimeoutMs);
|
|
97
|
+
if (typeof timer.unref === "function")
|
|
98
|
+
timer.unref();
|
|
99
|
+
params.state.approvals.set(approvalId, {
|
|
100
|
+
approvalId,
|
|
101
|
+
shellId: params.shellId,
|
|
102
|
+
...(ownerContextId ? { ownerContextId } : {}),
|
|
103
|
+
toolName: params.toolName,
|
|
104
|
+
cmd: params.cmd,
|
|
105
|
+
operation,
|
|
106
|
+
...(inputPreview !== undefined ? { inputPreview } : {}),
|
|
107
|
+
...(typeof params.inputChars === "number" ? { inputChars: params.inputChars } : {}),
|
|
108
|
+
cwd: params.cwd,
|
|
109
|
+
reason: params.reason,
|
|
110
|
+
createdAt,
|
|
111
|
+
timer,
|
|
112
|
+
resolve,
|
|
113
|
+
});
|
|
114
|
+
if (ownerContextId) {
|
|
115
|
+
const turnId = String(params.context.shellIntegration?.getRunContext?.()?.turnId || ownerContextId).trim();
|
|
116
|
+
try {
|
|
117
|
+
params.context.session?.get(ownerContextId).publishEvent({
|
|
118
|
+
type: "tool-approval-request",
|
|
119
|
+
turnId,
|
|
120
|
+
toolCallId: params.shellId,
|
|
121
|
+
toolName: params.toolName,
|
|
122
|
+
approvalId,
|
|
123
|
+
sandbox: "unrestricted",
|
|
124
|
+
cmd: params.cmd,
|
|
125
|
+
cwd: params.cwd,
|
|
126
|
+
reason: params.reason,
|
|
127
|
+
status: "pending",
|
|
128
|
+
operation,
|
|
129
|
+
shellId: params.shellId,
|
|
130
|
+
...(inputPreview !== undefined ? { inputPreview } : {}),
|
|
131
|
+
...(typeof params.inputChars === "number" ? { inputChars: params.inputChars } : {}),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// ignore event delivery failures
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
appendAudit({
|
|
139
|
+
context: params.context,
|
|
140
|
+
record: {
|
|
141
|
+
event: "approval_requested",
|
|
142
|
+
approval_id: approvalId,
|
|
143
|
+
session_id: ownerContextId || null,
|
|
144
|
+
tool_call_id: params.shellId,
|
|
145
|
+
agent_id: params.context.config?.id || null,
|
|
146
|
+
cmd: params.cmd,
|
|
147
|
+
operation,
|
|
148
|
+
...(inputPreview !== undefined ? { input_preview: inputPreview } : {}),
|
|
149
|
+
...(typeof params.inputChars === "number" ? { input_chars: params.inputChars } : {}),
|
|
150
|
+
cwd: params.cwd,
|
|
151
|
+
reason: params.reason,
|
|
152
|
+
created_at: new Date(createdAt).toISOString(),
|
|
153
|
+
},
|
|
154
|
+
}).catch(() => undefined);
|
|
155
|
+
});
|
|
156
|
+
return { approvalId, status };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 兑现 unrestricted sandbox 审批。
|
|
160
|
+
*/
|
|
161
|
+
export async function resolveApproval(params) {
|
|
162
|
+
const approval = params.state.approvals.get(params.approvalId);
|
|
163
|
+
if (!approval)
|
|
164
|
+
return false;
|
|
165
|
+
params.state.approvals.delete(params.approvalId);
|
|
166
|
+
clearTimeout(approval.timer);
|
|
167
|
+
approval.resolve(params.decision);
|
|
168
|
+
publishApprovalResult({
|
|
169
|
+
context: params.context,
|
|
170
|
+
ownerContextId: approval.ownerContextId,
|
|
171
|
+
approvalId: approval.approvalId,
|
|
172
|
+
shellId: approval.shellId,
|
|
173
|
+
toolName: approval.toolName,
|
|
174
|
+
decision: params.decision,
|
|
175
|
+
});
|
|
176
|
+
await appendAudit({
|
|
177
|
+
context: params.context,
|
|
178
|
+
record: {
|
|
179
|
+
event: "approval_resolved",
|
|
180
|
+
approval_id: approval.approvalId,
|
|
181
|
+
session_id: approval.ownerContextId || null,
|
|
182
|
+
tool_call_id: approval.shellId,
|
|
183
|
+
agent_id: params.context.config?.id || null,
|
|
184
|
+
cmd: approval.cmd,
|
|
185
|
+
operation: approval.operation,
|
|
186
|
+
...(approval.inputPreview !== undefined ? { input_preview: approval.inputPreview } : {}),
|
|
187
|
+
...(typeof approval.inputChars === "number" ? { input_chars: approval.inputChars } : {}),
|
|
188
|
+
cwd: approval.cwd,
|
|
189
|
+
reason: approval.reason,
|
|
190
|
+
decision: params.decision,
|
|
191
|
+
resolved_at: new Date(nowMs()).toISOString(),
|
|
192
|
+
},
|
|
193
|
+
}).catch(() => undefined);
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* 列出 pending unrestricted sandbox 审批。
|
|
198
|
+
*/
|
|
199
|
+
export function listPendingApprovals(state) {
|
|
200
|
+
return Array.from(state.approvals.values()).map((approval) => ({
|
|
201
|
+
approvalId: approval.approvalId,
|
|
202
|
+
shellId: approval.shellId,
|
|
203
|
+
...(approval.ownerContextId ? { ownerContextId: approval.ownerContextId } : {}),
|
|
204
|
+
toolName: approval.toolName,
|
|
205
|
+
cmd: approval.cmd,
|
|
206
|
+
operation: approval.operation,
|
|
207
|
+
...(approval.inputPreview !== undefined ? { inputPreview: approval.inputPreview } : {}),
|
|
208
|
+
...(typeof approval.inputChars === "number" ? { inputChars: approval.inputChars } : {}),
|
|
209
|
+
cwd: approval.cwd,
|
|
210
|
+
reason: approval.reason,
|
|
211
|
+
createdAt: approval.createdAt,
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=ShellApprovalRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ShellApprovalRuntime.js","sourceRoot":"","sources":["../../src/approval/ShellApprovalRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAO3C,OAAO,EAAE,KAAK,EAAE,MAAM,yCAAyC,CAAC;AAEhE,MAAM,0BAA0B,GAAG;IACjC,UAAU;IACV,2CAA2C;IAC3C,iCAAiC;IACjC,gBAAgB;IAChB,wDAAwD;IACxD,8CAA8C;CAC/C,CAAC;AAEF,SAAS,kBAAkB,CAAC,GAAW;IACrC,OAAO,0BAA0B,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,wBAAwB,CAAC,QAA+B;IAC/D,IAAI,QAAQ,KAAK,aAAa;QAAE,OAAO,OAAO,CAAC;IAC/C,IAAI,QAAQ,KAAK,YAAY;QAAE,OAAO,MAAM,CAAC;IAC7C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAa;IACtC,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;IACvC,IAAI,UAAU,CAAC,MAAM,IAAI,GAAG;QAA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AC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvF,GAAG,CAAC,OAAO,QAAQ,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvF,GAAG,EAAE,QAAQ,CAAC,GAAG;QACjB,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,SAAS,EAAE,QAAQ,CAAC,SAAS;KAC9B,CAAC,CAAC,CAAC;AACN,CAAC"}
|
package/bin/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @downcity/shell 公开入口。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - 本包拥有 shell / sandbox 的领域能力,不依赖 agent session 或 plugin 系统。
|
|
6
|
+
* - Agent 与 plugins 通过这里复用本地命令执行、shell session、approval 与 sandbox backend。
|
|
7
|
+
*/
|
|
8
|
+
export * from "./types/Shell.js";
|
|
9
|
+
export * from "./types/ShellRuntime.js";
|
|
10
|
+
export type { ShellActionResponse, ShellApprovalStatus, ShellApprovalToolName, ShellCloseRequest, ShellExecRequest, ShellExternalRef, ShellOutputChunk, ShellQueryRequest, ShellReadRequest, ShellSessionSnapshot, ShellSessionStatus, ShellStartRequest, ShellWaitRequest, ShellWriteRequest, } from "./types/ShellAction.js";
|
|
11
|
+
export * from "./types/ShellRuntimeOptions.js";
|
|
12
|
+
export * from "./types/ShellHostContext.js";
|
|
13
|
+
export * from "./Shell.js";
|
|
14
|
+
export * from "./sandbox/types/Sandbox.js";
|
|
15
|
+
export * from "./sandbox/types/SandboxRuntime.js";
|
|
16
|
+
export * from "./sandbox/SandboxRunner.js";
|
|
17
|
+
export * from "./sandbox/SandboxConfigResolver.js";
|
|
18
|
+
export * from "./sandbox/SandboxPreflight.js";
|
|
19
|
+
export * from "./session/ShellActionRuntime.js";
|
|
20
|
+
export * from "./session/ShellActionResponse.js";
|
|
21
|
+
export * from "./session/ShellRuntimeEnvironment.js";
|
|
22
|
+
export * from "./session/ShellRuntimeTypes.js";
|
|
23
|
+
export * from "./session/ShellRunScope.js";
|
|
24
|
+
export * from "./approval/ShellApprovalRuntime.js";
|
|
25
|
+
export * from "./tool/ShellTools.js";
|
|
26
|
+
export * from "./tool/ShellToolSchemas.js";
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,wBAAwB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,YAAY,CAAC;AAC3B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,sCAAsC,CAAC;AACrD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC"}
|
package/bin/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @downcity/shell 公开入口。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - 本包拥有 shell / sandbox 的领域能力,不依赖 agent session 或 plugin 系统。
|
|
6
|
+
* - Agent 与 plugins 通过这里复用本地命令执行、shell session、approval 与 sandbox backend。
|
|
7
|
+
*/
|
|
8
|
+
export * from "./types/Shell.js";
|
|
9
|
+
export * from "./types/ShellRuntime.js";
|
|
10
|
+
export * from "./types/ShellRuntimeOptions.js";
|
|
11
|
+
export * from "./types/ShellHostContext.js";
|
|
12
|
+
export * from "./Shell.js";
|
|
13
|
+
export * from "./sandbox/types/Sandbox.js";
|
|
14
|
+
export * from "./sandbox/types/SandboxRuntime.js";
|
|
15
|
+
export * from "./sandbox/SandboxRunner.js";
|
|
16
|
+
export * from "./sandbox/SandboxConfigResolver.js";
|
|
17
|
+
export * from "./sandbox/SandboxPreflight.js";
|
|
18
|
+
export * from "./session/ShellActionRuntime.js";
|
|
19
|
+
export * from "./session/ShellActionResponse.js";
|
|
20
|
+
export * from "./session/ShellRuntimeEnvironment.js";
|
|
21
|
+
export * from "./session/ShellRuntimeTypes.js";
|
|
22
|
+
export * from "./session/ShellRunScope.js";
|
|
23
|
+
export * from "./approval/ShellApprovalRuntime.js";
|
|
24
|
+
export * from "./tool/ShellTools.js";
|
|
25
|
+
export * from "./tool/ShellToolSchemas.js";
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
package/bin/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AAiBxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,YAAY,CAAC;AAC3B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mCAAmC,CAAC;AAClD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,sCAAsC,CAAC;AACrD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oCAAoC,CAAC;AACnD,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linux Bubblewrap sandbox backend。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - 基于 `bwrap` 提供 Linux 本机 shell sandbox。
|
|
6
|
+
* - 继续保持“shell 命令必须进入 sandbox”的安全语义,不提供宿主机裸跑回退。
|
|
7
|
+
* - 边界与 macOS backend 对齐:路径、环境变量、网络、agent 级共享 HOME/TMPDIR/cache。
|
|
8
|
+
*/
|
|
9
|
+
import type { SandboxSpawnParams, SandboxSpawnResult } from "../sandbox/types/SandboxRuntime.js";
|
|
10
|
+
export declare function buildLinuxBubblewrapArgs(params: SandboxSpawnParams & {
|
|
11
|
+
actualCwd: string;
|
|
12
|
+
}): string[];
|
|
13
|
+
/**
|
|
14
|
+
* 在 Linux bubblewrap sandbox 中启动 shell 子进程。
|
|
15
|
+
*/
|
|
16
|
+
export declare function spawnLinuxBubblewrapSandbox(params: SandboxSpawnParams & {
|
|
17
|
+
actualCwd: string;
|
|
18
|
+
}): Promise<SandboxSpawnResult>;
|
|
19
|
+
//# sourceMappingURL=LinuxBubblewrapSandbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinuxBubblewrapSandbox.d.ts","sourceRoot":"","sources":["../../src/sandbox/LinuxBubblewrapSandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,mCAAmC,CAAC;AA0G3C,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,kBAAkB,GAAG;IACpE,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,MAAM,EAAE,CA2DX;AAED;;GAEG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,kBAAkB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACjD,OAAO,CAAC,kBAAkB,CAAC,CAgC7B"}
|