@epoch-agent/plugin-terminal 6.0.0 → 6.2.0
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/README.md +6 -0
- package/dist/index.d.ts +1 -16
- package/dist/index.js +14 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -254,6 +254,12 @@ shell_list() → 看全部
|
|
|
254
254
|
shell_close({ id: 's1' }) → 关掉(杀整棵树)
|
|
255
255
|
```
|
|
256
256
|
|
|
257
|
+
⚠️ **`shell_open` 等 shell 打出第一段输出(提示符)再返回**(上限 250ms,见
|
|
258
|
+
`sessions.ts` 的 `READY_WAIT_MS`)。不等的话,紧接着的 `shell_send` 会落在两种
|
|
259
|
+
时序上:提示符先到 → 输入行被回显在提示符后面(`\x1b[?1034hsh-3.2$ pwd`);
|
|
260
|
+
输入先到 → 只有输入行本身。同一段输出两种形态,模型看到的世界就不确定,
|
|
261
|
+
评测录像也会因此「隔一次过期一次」。
|
|
262
|
+
|
|
257
263
|
`terminal` 三条路径**都是一次性的**,所以 `cd` 不留存、`source venv/bin/activate`
|
|
258
264
|
不留存、`export` 不留存、进了 REPL 就出不来 —— 这一族答的就是这个。
|
|
259
265
|
|
package/dist/index.d.ts
CHANGED
|
@@ -267,21 +267,6 @@ declare function clearAllTasks(): void;
|
|
|
267
267
|
/** 一行摘要,宿主展示用 */
|
|
268
268
|
declare function describeTask(info: BackgroundTaskInfo): string;
|
|
269
269
|
|
|
270
|
-
/**
|
|
271
|
-
* 持久 shell 会话的上限和契约类型(方案 49)。
|
|
272
|
-
*
|
|
273
|
-
* 单独一个文件的理由**和同包的 [../limits.ts](../limits.js) 逐字同款**:
|
|
274
|
-
* [sessions.ts](./sessions.js) 和 [notice.ts](./notice.js) 都要用它们,而那两个
|
|
275
|
-
* 文件之间不该为了几个常量互相 import —— 那会绕出一个
|
|
276
|
-
* `sessions → notice → sessions` 的环(会话表要用「写入失败」那句措辞,
|
|
277
|
-
* 措辞要用上限和状态类型)。常量和类型下沉成叶子,环就不存在了。
|
|
278
|
-
* `oxlint` 的 `import/no-cycle` 是 **error**,所以这不是风格问题。
|
|
279
|
-
*
|
|
280
|
-
* ## 四条上限的取值判据(方案 §1.3:不发明新数字,取值可以不同)
|
|
281
|
-
*
|
|
282
|
-
* 逐条对照后台任务那三条写在 [sessions.ts](./sessions.js) 的文件头,那里同时
|
|
283
|
-
* 交代了「为什么持久会话是 4 个而后台任务是 8 个」。
|
|
284
|
-
*/
|
|
285
270
|
/** **每个会话**同时最多开几个持久会话 */
|
|
286
271
|
declare const MAX_SHELLS = 4;
|
|
287
272
|
/** 单个会话留多少字节输出(环形,丢头保尾)。**真源在 infra 的 `JOB_OUTPUT_LIMIT`** */
|
|
@@ -416,7 +401,7 @@ interface ShellOpened {
|
|
|
416
401
|
* @param sandbox 这次的沙箱边界。**不传 = 不上沙箱**,如实标成 `not-requested`;
|
|
417
402
|
* 工具那条真实路径每次都传,且传的是**和 `terminal` 同一个** `sandboxPolicyFor()`
|
|
418
403
|
*/
|
|
419
|
-
declare function openShell(sessionId: string, cwd: string, homeDir?: string, sandbox?: SandboxPolicy): ShellOpened | ShellLimitReached | ShellSpawnFailed
|
|
404
|
+
declare function openShell(sessionId: string, cwd: string, homeDir?: string, sandbox?: SandboxPolicy): Promise<ShellOpened | ShellLimitReached | ShellSpawnFailed>;
|
|
420
405
|
interface ShellGone {
|
|
421
406
|
/** `undefined` = 压根没这个 id(或者是别的会话的) */
|
|
422
407
|
info?: ShellInfo;
|
package/dist/index.js
CHANGED
|
@@ -553,6 +553,7 @@ import {
|
|
|
553
553
|
} from "@epoch-agent/infra";
|
|
554
554
|
// src/shell/limits.ts
|
|
555
555
|
import { JOB_OUTPUT_LIMIT as JOB_OUTPUT_LIMIT2 } from "@epoch-agent/infra";
|
|
556
|
+
var READY_WAIT_MS = 250;
|
|
556
557
|
var MAX_SHELLS = 4;
|
|
557
558
|
var MAX_SHELL_OUTPUT = JOB_OUTPUT_LIMIT2;
|
|
558
559
|
var MAX_SHELL_CHUNK = 8 * 1024;
|
|
@@ -711,7 +712,7 @@ function shellIn(sessionId, id) {
|
|
|
711
712
|
function toShellRead(read, detail) {
|
|
712
713
|
return { ...read, info: toShellInfo(read.info, detail) };
|
|
713
714
|
}
|
|
714
|
-
function openShell(sessionId, cwd, homeDir, sandbox) {
|
|
715
|
+
async function openShell(sessionId, cwd, homeDir, sandbox) {
|
|
715
716
|
const running = listJobs2(sessionId, "shell").filter((s) => s.status === "running");
|
|
716
717
|
if (running.length >= MAX_SHELLS) {
|
|
717
718
|
return {
|
|
@@ -763,10 +764,16 @@ function openShell(sessionId, cwd, homeDir, sandbox) {
|
|
|
763
764
|
job.setPid(pty.pid);
|
|
764
765
|
detail.untrack = processTableFor3(sessionId).trackForeign(pty.pid, () => killPtyTree(pty));
|
|
765
766
|
armSweep();
|
|
767
|
+
let markReady = () => {
|
|
768
|
+
};
|
|
769
|
+
const ready = new Promise((resolve3) => {
|
|
770
|
+
markReady = resolve3;
|
|
771
|
+
});
|
|
766
772
|
pty.onData((chunk) => {
|
|
767
773
|
if (detail.fresh) {
|
|
768
774
|
detail.fresh = false;
|
|
769
775
|
job.append(dropConPtyPreamble(chunk));
|
|
776
|
+
markReady();
|
|
770
777
|
return;
|
|
771
778
|
}
|
|
772
779
|
job.append(chunk);
|
|
@@ -775,6 +782,10 @@ function openShell(sessionId, cwd, homeDir, sandbox) {
|
|
|
775
782
|
job.finish("exited", exitCode);
|
|
776
783
|
afterEnd(detail);
|
|
777
784
|
});
|
|
785
|
+
const timeout = setTimeout(() => markReady(), READY_WAIT_MS);
|
|
786
|
+
timeout.unref?.();
|
|
787
|
+
await ready;
|
|
788
|
+
clearTimeout(timeout);
|
|
778
789
|
return { shell: toShellInfo(job.info(), detail), sandbox: sh.outcome };
|
|
779
790
|
}
|
|
780
791
|
function afterEnd(detail) {
|
|
@@ -936,7 +947,7 @@ var shellOpen = {
|
|
|
936
947
|
},
|
|
937
948
|
operation: "command",
|
|
938
949
|
describeTarget: (args) => String(args["workdir"] ?? ""),
|
|
939
|
-
execute: (args, ctx) => {
|
|
950
|
+
execute: async (args, ctx) => {
|
|
940
951
|
const workdir = args["workdir"] ? String(args["workdir"]) : void 0;
|
|
941
952
|
const baseDir = ctx.workDir || process.cwd();
|
|
942
953
|
const roots = [...ctx.extraRoots ?? [], ...ctx.grantedPaths ?? []];
|
|
@@ -950,7 +961,7 @@ var shellOpen = {
|
|
|
950
961
|
);
|
|
951
962
|
}
|
|
952
963
|
const cwd = workdir ? resolveWorkdir(workdir, baseDir) : baseDir;
|
|
953
|
-
const opened = openShell(ctx.sessionId, cwd, ctx.homeDir, sandboxPolicyFor(ctx, baseDir));
|
|
964
|
+
const opened = await openShell(ctx.sessionId, cwd, ctx.homeDir, sandboxPolicyFor(ctx, baseDir));
|
|
954
965
|
if ("error" in opened) {
|
|
955
966
|
if (opened.error === "limit") {
|
|
956
967
|
const list = opened.running.map(describeShell).join("\n");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epoch-agent/plugin-terminal",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "epoch-agent 终端命令执行插件",
|
|
6
6
|
"repository": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"node-pty": "^1.1.0",
|
|
25
|
-
"@epoch-agent/infra": "6.
|
|
26
|
-
"@epoch-agent/protocol": "6.
|
|
25
|
+
"@epoch-agent/infra": "6.2.0",
|
|
26
|
+
"@epoch-agent/protocol": "6.2.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^26.1.2",
|