@astralyn/pi 1.4.1 → 1.4.3
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/CHANGELOG.md +14 -0
- package/dist/bundle/chunks/{chunk-N77PYEXG.js → chunk-ISXCH6TG.js} +1 -1
- package/dist/bundle/chunks/{chunk-KSKBY3VV.js → chunk-Z2YN4E74.js} +117 -111
- package/dist/bundle/chunks/{virtual-modules-XNEYDLXF.js → virtual-modules-QX6D3D7X.js} +1 -1
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/agent-session.d.ts +15 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1 -8
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/distribution-api.d.ts +1 -1
- package/dist/core/extensions/distribution-api.d.ts.map +1 -1
- package/dist/core/extensions/distribution-api.js.map +1 -1
- package/dist/core/extensions/index.d.ts +2 -2
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +3 -2
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +29 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/keybinding-registry.d.ts +16 -1
- package/dist/core/keybinding-registry.d.ts.map +1 -1
- package/dist/core/keybinding-registry.js +20 -0
- package/dist/core/keybinding-registry.js.map +1 -1
- package/dist/core/keybindings-schema.d.ts.map +1 -1
- package/dist/core/keybindings-schema.js +2 -1
- package/dist/core/keybindings-schema.js.map +1 -1
- package/dist/core/keybindings.d.ts +4 -106
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +0 -13
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +0 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tasks/format.d.ts.map +1 -1
- package/dist/core/tasks/format.js +10 -4
- package/dist/core/tasks/format.js.map +1 -1
- package/dist/core/tasks/limits.d.ts +5 -0
- package/dist/core/tasks/limits.d.ts.map +1 -0
- package/dist/core/tasks/limits.js +5 -0
- package/dist/core/tasks/limits.js.map +1 -0
- package/dist/core/tasks/runtime.d.ts +1 -0
- package/dist/core/tasks/runtime.d.ts.map +1 -1
- package/dist/core/tasks/runtime.js +7 -3
- package/dist/core/tasks/runtime.js.map +1 -1
- package/dist/core/tasks/session.d.ts +1 -1
- package/dist/core/tasks/session.d.ts.map +1 -1
- package/dist/core/tasks/session.js +10 -2
- package/dist/core/tasks/session.js.map +1 -1
- package/dist/core/tasks/types.d.ts +13 -0
- package/dist/core/tasks/types.d.ts.map +1 -1
- package/dist/core/tasks/types.js.map +1 -1
- package/dist/core/tools/bash.d.ts +98 -9
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +308 -11
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/index.d.ts +5 -4
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +3 -11
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/powershell.d.ts +2 -1
- package/dist/core/tools/powershell.d.ts.map +1 -1
- package/dist/core/tools/powershell.js +2 -1
- package/dist/core/tools/powershell.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/core/tools/renderers/index.d.ts.map +1 -1
- package/dist/core/tools/renderers/index.js +7 -5
- package/dist/core/tools/renderers/index.js.map +1 -1
- package/dist/core/tools/shell-execution.d.ts +2 -2
- package/dist/core/tools/shell-execution.d.ts.map +1 -1
- package/dist/core/tools/shell-execution.js +0 -21
- package/dist/core/tools/shell-execution.js.map +1 -1
- package/dist/core/tools/shell-operations.d.ts +12 -0
- package/dist/core/tools/shell-operations.d.ts.map +1 -0
- package/dist/core/tools/shell-operations.js +38 -0
- package/dist/core/tools/shell-operations.js.map +1 -0
- package/dist/core/tools/shell-tool.d.ts +8 -64
- package/dist/core/tools/shell-tool.d.ts.map +1 -1
- package/dist/core/tools/shell-tool.js +27 -125
- package/dist/core/tools/shell-tool.js.map +1 -1
- package/dist/extensions/index.d.ts +1 -0
- package/dist/extensions/index.d.ts.map +1 -1
- package/dist/extensions/index.js +5 -0
- package/dist/extensions/index.js.map +1 -1
- package/dist/extensions/keybindings.d.ts +6 -0
- package/dist/extensions/keybindings.d.ts.map +1 -0
- package/dist/extensions/keybindings.js +6 -0
- package/dist/extensions/keybindings.js.map +1 -0
- package/dist/extensions/tasks/index.d.ts +5 -0
- package/dist/extensions/tasks/index.d.ts.map +1 -0
- package/dist/extensions/tasks/index.js +42 -0
- package/dist/extensions/tasks/index.js.map +1 -0
- package/dist/extensions/tasks/keybindings.d.ts +19 -0
- package/dist/extensions/tasks/keybindings.d.ts.map +1 -0
- package/dist/extensions/tasks/keybindings.js +30 -0
- package/dist/extensions/tasks/keybindings.js.map +1 -0
- package/dist/{core/tools/tasks → extensions/tasks/tool}/actions.d.ts +2 -2
- package/dist/extensions/tasks/tool/actions.d.ts.map +1 -0
- package/dist/{core/tools/tasks → extensions/tasks/tool}/actions.js +4 -4
- package/dist/extensions/tasks/tool/actions.js.map +1 -0
- package/dist/{core/tools/tasks → extensions/tasks/tool}/constants.d.ts +1 -3
- package/dist/extensions/tasks/tool/constants.d.ts.map +1 -0
- package/dist/{core/tools/tasks → extensions/tasks/tool}/constants.js +1 -3
- package/dist/extensions/tasks/tool/constants.js.map +1 -0
- package/dist/extensions/tasks/tool/schema.d.ts.map +1 -0
- package/dist/{core/tools/tasks → extensions/tasks/tool}/schema.js +5 -4
- package/dist/extensions/tasks/tool/schema.js.map +1 -0
- package/dist/{core/tools/tasks → extensions/tasks/tool}/types.d.ts +1 -1
- package/dist/extensions/tasks/tool/types.d.ts.map +1 -0
- package/dist/extensions/tasks/tool/types.js.map +1 -0
- package/dist/extensions/tasks/tool.d.ts +6 -0
- package/dist/extensions/tasks/tool.d.ts.map +1 -0
- package/dist/{core/tools/tasks.js → extensions/tasks/tool.js} +6 -10
- package/dist/extensions/tasks/tool.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/completion-render.d.ts +1 -1
- package/dist/extensions/tasks/ui/completion-render.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/completion-render.js +2 -2
- package/dist/extensions/tasks/ui/completion-render.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/index.d.ts +1 -1
- package/dist/extensions/tasks/ui/index.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/index.js +4 -4
- package/dist/extensions/tasks/ui/index.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/inspector.d.ts +1 -1
- package/dist/extensions/tasks/ui/inspector.d.ts.map +1 -0
- package/dist/extensions/tasks/ui/inspector.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/layout.d.ts +1 -1
- package/dist/extensions/tasks/ui/layout.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/layout.js +1 -1
- package/dist/extensions/tasks/ui/layout.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/list.d.ts +1 -1
- package/dist/extensions/tasks/ui/list.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/list.js +1 -1
- package/dist/extensions/tasks/ui/list.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/manager.d.ts +2 -1
- package/dist/extensions/tasks/ui/manager.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/manager.js +2 -1
- package/dist/extensions/tasks/ui/manager.js.map +1 -0
- package/dist/extensions/tasks/ui/model.d.ts.map +1 -0
- package/dist/extensions/tasks/ui/model.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/render.d.ts +3 -3
- package/dist/extensions/tasks/ui/render.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/render.js +2 -2
- package/dist/extensions/tasks/ui/render.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/task-view.d.ts +1 -1
- package/dist/extensions/tasks/ui/task-view.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/task-view.js +1 -1
- package/dist/extensions/tasks/ui/task-view.js.map +1 -0
- package/dist/extensions/tasks/ui/text.d.ts.map +1 -0
- package/dist/extensions/tasks/ui/text.js.map +1 -0
- package/dist/extensions/tasks/ui/tree.d.ts +7 -0
- package/dist/extensions/tasks/ui/tree.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks/host-hooks.js → extensions/tasks/ui/tree.js} +1 -18
- package/dist/extensions/tasks/ui/tree.js.map +1 -0
- package/dist/extensions/tasks/ui/viewport.d.ts.map +1 -0
- package/dist/extensions/tasks/ui/viewport.js.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/views.d.ts +1 -1
- package/dist/extensions/tasks/ui/views.d.ts.map +1 -0
- package/dist/{modes/interactive/tasks → extensions/tasks/ui}/views.js +1 -1
- package/dist/extensions/tasks/ui/views.js.map +1 -0
- package/dist/extensions/tool-presentation/index.d.ts +7 -0
- package/dist/extensions/tool-presentation/index.d.ts.map +1 -0
- package/dist/extensions/tool-presentation/index.js +9 -0
- package/dist/extensions/tool-presentation/index.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +3 -2
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +65 -18
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +1 -3
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -1
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -1
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +85 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution.js +362 -0
- package/dist/modes/interactive/components/tool-execution.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +5 -3
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +14 -29
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/tool-view/chat.d.ts +1 -1
- package/dist/modes/interactive/tool-view/chat.d.ts.map +1 -1
- package/dist/modes/interactive/tool-view/chat.js +2 -3
- package/dist/modes/interactive/tool-view/chat.js.map +1 -1
- package/dist/modes/interactive/tool-view/shell.d.ts +15 -0
- package/dist/modes/interactive/tool-view/shell.d.ts.map +1 -0
- package/dist/modes/interactive/tool-view/shell.js +51 -0
- package/dist/modes/interactive/tool-view/shell.js.map +1 -0
- package/dist/modes/interactive/tool-view/tool-execution.d.ts +10 -79
- package/dist/modes/interactive/tool-view/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/tool-view/tool-execution.js +7 -298
- package/dist/modes/interactive/tool-view/tool-execution.js.map +1 -1
- package/docs/bundled/README.md +1 -4
- package/docs/bundled/tasks.md +3 -3
- package/docs/bundled/tool-presentation.md +9 -7
- package/docs/extensions.md +9 -4
- package/docs/settings.md +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/schemas/keybindings.schema.json +84 -52
- package/dist/core/tools/tasks/actions.d.ts.map +0 -1
- package/dist/core/tools/tasks/actions.js.map +0 -1
- package/dist/core/tools/tasks/constants.d.ts.map +0 -1
- package/dist/core/tools/tasks/constants.js.map +0 -1
- package/dist/core/tools/tasks/schema.d.ts.map +0 -1
- package/dist/core/tools/tasks/schema.js.map +0 -1
- package/dist/core/tools/tasks/types.d.ts.map +0 -1
- package/dist/core/tools/tasks/types.js.map +0 -1
- package/dist/core/tools/tasks.d.ts +0 -14
- package/dist/core/tools/tasks.d.ts.map +0 -1
- package/dist/core/tools/tasks.js.map +0 -1
- package/dist/modes/interactive/tasks/completion-render.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/completion-render.js.map +0 -1
- package/dist/modes/interactive/tasks/host-hooks.d.ts +0 -14
- package/dist/modes/interactive/tasks/host-hooks.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/host-hooks.js.map +0 -1
- package/dist/modes/interactive/tasks/index.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/index.js.map +0 -1
- package/dist/modes/interactive/tasks/inspector.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/inspector.js.map +0 -1
- package/dist/modes/interactive/tasks/layout.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/layout.js.map +0 -1
- package/dist/modes/interactive/tasks/list.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/list.js.map +0 -1
- package/dist/modes/interactive/tasks/manager.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/manager.js.map +0 -1
- package/dist/modes/interactive/tasks/model.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/model.js.map +0 -1
- package/dist/modes/interactive/tasks/render.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/render.js.map +0 -1
- package/dist/modes/interactive/tasks/task-view.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/task-view.js.map +0 -1
- package/dist/modes/interactive/tasks/text.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/text.js.map +0 -1
- package/dist/modes/interactive/tasks/viewport.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/viewport.js.map +0 -1
- package/dist/modes/interactive/tasks/views.d.ts.map +0 -1
- package/dist/modes/interactive/tasks/views.js.map +0 -1
- /package/dist/{core/tools/tasks → extensions/tasks/tool}/schema.d.ts +0 -0
- /package/dist/{core/tools/tasks → extensions/tasks/tool}/types.js +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/inspector.js +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/model.d.ts +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/model.js +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/text.d.ts +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/text.js +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/viewport.d.ts +0 -0
- /package/dist/{modes/interactive/tasks → extensions/tasks/ui}/viewport.js +0 -0
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
import { constants } from "node:fs";
|
|
2
|
-
import { access as fsAccess } from "node:fs/promises";
|
|
3
|
-
import { constants as osConstants } from "node:os";
|
|
4
|
-
import { spawn } from "child_process";
|
|
5
1
|
import { Type } from "typebox";
|
|
6
|
-
import { waitForChildProcess } from "../../utils/child-process.js";
|
|
7
|
-
import { getShellEnv, killProcessTree, trackDetachedChildPid, untrackDetachedChildPid, } from "../../utils/shell.js";
|
|
8
2
|
import { TaskExecutionError } from "../tasks/types.js";
|
|
3
|
+
import { resolveSpawnContext, resolveTimeoutMs, } from "./bash.js";
|
|
9
4
|
import { createShellRenderers } from "./renderers/bash.js";
|
|
10
5
|
import { runShellCommand } from "./shell-execution.js";
|
|
6
|
+
import { createLocalBashOperations } from "./shell-operations.js";
|
|
7
|
+
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
11
8
|
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES } from "./truncate.js";
|
|
12
|
-
const MAX_TIMEOUT_MS = 2_147_483_647;
|
|
13
|
-
const MAX_TIMEOUT_SECONDS = MAX_TIMEOUT_MS / 1000;
|
|
14
|
-
function resolveTimeoutMs(timeout) {
|
|
15
|
-
if (timeout === undefined)
|
|
16
|
-
return undefined;
|
|
17
|
-
if (!Number.isFinite(timeout) || timeout <= 0) {
|
|
18
|
-
throw new Error("Invalid timeout: must be a finite number of seconds");
|
|
19
|
-
}
|
|
20
|
-
const timeoutMs = timeout * 1000;
|
|
21
|
-
if (timeoutMs > MAX_TIMEOUT_MS) {
|
|
22
|
-
throw new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);
|
|
23
|
-
}
|
|
24
|
-
return timeoutMs;
|
|
25
|
-
}
|
|
26
9
|
const bashSchema = Type.Object({
|
|
27
10
|
command: Type.String({ description: "Shell command to execute" }),
|
|
28
11
|
timeout: Type.Optional(Type.Number({ description: "Timeout in seconds (optional, no default timeout)" })),
|
|
@@ -46,111 +29,6 @@ const bashOutputSchema = Type.Union([
|
|
|
46
29
|
}),
|
|
47
30
|
Type.Object({ task_id: Type.String(), status: Type.String() }),
|
|
48
31
|
]);
|
|
49
|
-
/** Shared process execution used by the built-in shell tools. */
|
|
50
|
-
export function createLocalShellOperations(shellName, resolveShellConfig, normalizeCommand = (command) => command) {
|
|
51
|
-
return {
|
|
52
|
-
exec: async (command, cwd, { onData, signal, timeout, env }) => {
|
|
53
|
-
const timeoutMs = resolveTimeoutMs(timeout);
|
|
54
|
-
if (signal?.aborted) {
|
|
55
|
-
throw new Error("aborted");
|
|
56
|
-
}
|
|
57
|
-
const shellConfig = resolveShellConfig();
|
|
58
|
-
try {
|
|
59
|
-
await fsAccess(cwd, constants.F_OK);
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
throw new Error(`Working directory does not exist: ${cwd}\nCannot execute ${shellName} commands.`);
|
|
63
|
-
}
|
|
64
|
-
if (signal?.aborted)
|
|
65
|
-
throw new Error("aborted");
|
|
66
|
-
const commandFromStdin = shellConfig.commandTransport === "stdin";
|
|
67
|
-
const normalizedCommand = normalizeCommand(command);
|
|
68
|
-
const child = spawn(shellConfig.shell, commandFromStdin ? shellConfig.args : [...shellConfig.args, normalizedCommand], {
|
|
69
|
-
cwd,
|
|
70
|
-
detached: process.platform !== "win32",
|
|
71
|
-
env: env ?? getShellEnv(),
|
|
72
|
-
stdio: [commandFromStdin ? "pipe" : "ignore", "pipe", "pipe"],
|
|
73
|
-
windowsHide: true,
|
|
74
|
-
});
|
|
75
|
-
if (commandFromStdin) {
|
|
76
|
-
child.stdin?.on("error", () => { });
|
|
77
|
-
child.stdin?.end(normalizedCommand);
|
|
78
|
-
}
|
|
79
|
-
if (child.pid)
|
|
80
|
-
trackDetachedChildPid(child.pid);
|
|
81
|
-
let timedOut = false;
|
|
82
|
-
let timeoutHandle;
|
|
83
|
-
const onAbort = () => {
|
|
84
|
-
if (child.pid)
|
|
85
|
-
killProcessTree(child.pid);
|
|
86
|
-
};
|
|
87
|
-
try {
|
|
88
|
-
// Set timeout if provided.
|
|
89
|
-
if (timeoutMs !== undefined) {
|
|
90
|
-
timeoutHandle = setTimeout(() => {
|
|
91
|
-
timedOut = true;
|
|
92
|
-
if (child.pid)
|
|
93
|
-
killProcessTree(child.pid);
|
|
94
|
-
}, timeoutMs);
|
|
95
|
-
}
|
|
96
|
-
// Stream stdout and stderr.
|
|
97
|
-
child.stdout?.on("data", onData);
|
|
98
|
-
child.stderr?.on("data", onData);
|
|
99
|
-
// Handle abort signal by killing the entire process tree.
|
|
100
|
-
if (signal) {
|
|
101
|
-
if (signal.aborted)
|
|
102
|
-
onAbort();
|
|
103
|
-
else
|
|
104
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
105
|
-
}
|
|
106
|
-
// Handle shell spawn errors and wait for the process to terminate without hanging
|
|
107
|
-
// on inherited stdio handles held by detached descendants.
|
|
108
|
-
const exitCode = await waitForChildProcess(child);
|
|
109
|
-
if (signal?.aborted) {
|
|
110
|
-
throw new Error("aborted");
|
|
111
|
-
}
|
|
112
|
-
if (timedOut) {
|
|
113
|
-
throw new Error(`timeout:${timeout}`);
|
|
114
|
-
}
|
|
115
|
-
// A signal-killed shell has no exit code. Use the standard shell convention so
|
|
116
|
-
// callers do not mistake the termination for a successful command.
|
|
117
|
-
const signalCode = child.signalCode;
|
|
118
|
-
return { exitCode: exitCode ?? (signalCode ? 128 + (osConstants.signals[signalCode] ?? 0) : 1) };
|
|
119
|
-
}
|
|
120
|
-
finally {
|
|
121
|
-
if (child.pid)
|
|
122
|
-
untrackDetachedChildPid(child.pid);
|
|
123
|
-
if (timeoutHandle)
|
|
124
|
-
clearTimeout(timeoutHandle);
|
|
125
|
-
if (signal)
|
|
126
|
-
signal.removeEventListener("abort", onAbort);
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
export function resolveSpawnContext(command, cwd, spawnHook, exposeSessionEnvironment, ctx) {
|
|
132
|
-
const env = { ...getShellEnv() };
|
|
133
|
-
delete env.PI_SESSION_ID;
|
|
134
|
-
delete env.PI_SESSION_FILE;
|
|
135
|
-
delete env.PI_PROVIDER;
|
|
136
|
-
delete env.PI_MODEL;
|
|
137
|
-
delete env.PI_REASONING_LEVEL;
|
|
138
|
-
if (exposeSessionEnvironment && ctx) {
|
|
139
|
-
const model = ctx.model;
|
|
140
|
-
env.PI_SESSION_ID = ctx.sessionManager.getSessionId();
|
|
141
|
-
const sessionFile = ctx.sessionManager.getSessionFile();
|
|
142
|
-
if (sessionFile)
|
|
143
|
-
env.PI_SESSION_FILE = sessionFile;
|
|
144
|
-
if (model) {
|
|
145
|
-
env.PI_PROVIDER = model.provider;
|
|
146
|
-
env.PI_MODEL = model.id;
|
|
147
|
-
}
|
|
148
|
-
if (ctx.thinkingLevel)
|
|
149
|
-
env.PI_REASONING_LEVEL = ctx.thinkingLevel;
|
|
150
|
-
}
|
|
151
|
-
const baseContext = { command, cwd, env };
|
|
152
|
-
return spawnHook ? spawnHook(baseContext) : baseContext;
|
|
153
|
-
}
|
|
154
32
|
/** Translate terminal shell failures to the native foreground tool contract once. */
|
|
155
33
|
function shellToolResult(completion, managed) {
|
|
156
34
|
const status = completion.status;
|
|
@@ -253,4 +131,28 @@ export function createShellToolDefinition(cwd, config, options) {
|
|
|
253
131
|
...createShellRenderers(config),
|
|
254
132
|
};
|
|
255
133
|
}
|
|
134
|
+
const bashToolConfig = {
|
|
135
|
+
name: "bash",
|
|
136
|
+
label: "bash",
|
|
137
|
+
shellName: "bash",
|
|
138
|
+
prompt: "$",
|
|
139
|
+
promptSnippet: bashToolSystemPromptContribution.snippet,
|
|
140
|
+
promptGuidelines: bashToolSystemPromptContribution.guidelines,
|
|
141
|
+
tempFilePrefix: "pi-bash",
|
|
142
|
+
};
|
|
143
|
+
export function createBashToolDefinition(cwd, options) {
|
|
144
|
+
return createShellToolDefinition(cwd, bashToolConfig, {
|
|
145
|
+
...options,
|
|
146
|
+
operations: options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath }),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
export function createBashTool(cwd, options) {
|
|
150
|
+
const definition = createBashToolDefinition(cwd, options);
|
|
151
|
+
const tool = wrapToolDefinition(definition);
|
|
152
|
+
Object.assign(tool, {
|
|
153
|
+
promptSnippet: definition.promptSnippet,
|
|
154
|
+
promptGuidelines: definition.promptGuidelines,
|
|
155
|
+
});
|
|
156
|
+
return tool;
|
|
157
|
+
}
|
|
256
158
|
//# sourceMappingURL=shell-tool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell-tool.js","sourceRoot":"","sources":["../../../src/core/tools/shell-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAe,IAAI,EAAE,MA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AAO,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC;aAClC,CAAC,CAAC;YACH,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ;gBAAE,OAAO,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACrE,MAAM,IAAI,GAAG,YAAY,OAAO,CAAC,IAAI,CAAC,EAAE,aAAa,OAAO,CAAC,IAAI,CAAC,MAAM,iVAAiV,CAAC;YAC1Z,0FAA0F;YAC1F,wFAAwF;YACxF,2DAA2D;YAC3D,MAAM,OAAO,GACZ,UAAU,KAAK,IAAI;gBAClB,CAAC,CAAC,iCAAiC,IAAI,EAAE;gBACzC,CAAC,CAAC,gSAAgS,IAAI,EAAE,CAAC;YAC3S,OAAO;gBACN,iBAAiB,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE;gBAC5E,OAAO,EAAE;oBACR;wBACC,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,GAAG,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,kBAAkB,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;qBAC/F;iBACD;gBACD,OAAO,EAAE;oBACR,UAAU,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE;oBAC3D,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,UAAU;iBACvC;aACD,CAAC;QACH,CAAC;QACD,GAAG,oBAAoB,CAAC,MAAM,CAAC;KAC/B,CAAC;AACH,CAAC","sourcesContent":["import { constants } from \"node:fs\";\nimport { access as fsAccess } from \"node:fs/promises\";\nimport { constants as osConstants } from \"node:os\";\nimport { spawn } from \"child_process\";\nimport { type Static, Type } from \"typebox\";\nimport { waitForChildProcess } from \"../../utils/child-process.ts\";\nimport {\n\tgetShellEnv,\n\tkillProcessTree,\n\ttype ShellConfig,\n\ttrackDetachedChildPid,\n\tuntrackDetachedChildPid,\n} from \"../../utils/shell.ts\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { type TaskCompletion, TaskExecutionError } from \"../tasks/types.ts\";\nimport { createShellRenderers } from \"./renderers/bash.ts\";\nimport { type ManagedShellExecution, runShellCommand } from \"./shell-execution.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult } from \"./truncate.ts\";\n\nconst MAX_TIMEOUT_MS = 2_147_483_647;\nconst MAX_TIMEOUT_SECONDS = MAX_TIMEOUT_MS / 1000;\n\nfunction resolveTimeoutMs(timeout: number | undefined): number | undefined {\n\tif (timeout === undefined) return undefined;\n\tif (!Number.isFinite(timeout) || timeout <= 0) {\n\t\tthrow new Error(\"Invalid timeout: must be a finite number of seconds\");\n\t}\n\n\tconst timeoutMs = timeout * 1000;\n\tif (timeoutMs > MAX_TIMEOUT_MS) {\n\t\tthrow new Error(`Invalid timeout: maximum is ${MAX_TIMEOUT_SECONDS} seconds`);\n\t}\n\treturn timeoutMs;\n}\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Shell command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n\tbackground: Type.Optional(\n\t\tType.Boolean({\n\t\t\tdescription:\n\t\t\t\t\"true returns a managed task ID immediately and runs the command in the background, and you are notified when it completes — do not poll for its result; omit or false to block until exit\",\n\t\t}),\n\t),\n});\n\nexport const bashToolSystemPromptContribution = {\n\tsnippet: \"Execute bash commands, foreground or background\",\n\tguidelines: [\"You can inspect PI_* environment variables for current model and session details.\"],\n} as const;\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nconst bashOutputSchema = Type.Union([\n\tType.Object({\n\t\toutput: Type.String({\n\t\t\tdescription: \"Combined stdout and stderr, up to 1 MiB, keeping head and tail when truncated.\",\n\t\t}),\n\t\ttruncated: Type.Boolean(),\n\t\tfull_output_path: Type.Optional(Type.String()),\n\t\texit_code: Type.Number(),\n\t\twall_time_seconds: Type.Number(),\n\t}),\n\tType.Object({ task_id: Type.String(), status: Type.String() }),\n]);\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n\t/** Settled handoff snapshot, not a command completion or exit code. */\n\tbackground?: { kind: \"background\"; taskId: string };\n}\n\n/**\n * Pluggable operations for the bash tool.\n * Override these to delegate command execution to remote systems (for example SSH).\n */\nexport interface BashOperations {\n\t/**\n\t * Execute a command and stream output.\n\t * @param command The command to execute\n\t * @param cwd Working directory\n\t * @param options Execution options\n\t * @returns Promise resolving to the exit code. Report signal terminations as 128 + signal number;\n\t * a null exit code is treated as a failed command.\n\t *\n\t * Error contract: reject with `new Error(\"aborted\")` when aborted via `signal`,\n\t * and `new Error(\"timeout:<seconds>\")` on timeout expiry. The shared shell\n\t * execution pipeline classifies outcomes from these exact markers.\n\t */\n\texec: (\n\t\tcommand: string,\n\t\tcwd: string,\n\t\toptions: {\n\t\t\tonData: (data: Buffer) => void;\n\t\t\tsignal?: AbortSignal;\n\t\t\ttimeout?: number;\n\t\t\tenv?: NodeJS.ProcessEnv;\n\t\t},\n\t) => Promise<{ exitCode: number | null }>;\n}\n\n/** Shared process execution used by the built-in shell tools. */\nexport function createLocalShellOperations(\n\tshellName: string,\n\tresolveShellConfig: () => ShellConfig,\n\tnormalizeCommand: (command: string) => string = (command) => command,\n): BashOperations {\n\treturn {\n\t\texec: async (command, cwd, { onData, signal, timeout, env }) => {\n\t\t\tconst timeoutMs = resolveTimeoutMs(timeout);\n\t\t\tif (signal?.aborted) {\n\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t}\n\t\t\tconst shellConfig = resolveShellConfig();\n\t\t\ttry {\n\t\t\t\tawait fsAccess(cwd, constants.F_OK);\n\t\t\t} catch {\n\t\t\t\tthrow new Error(`Working directory does not exist: ${cwd}\\nCannot execute ${shellName} commands.`);\n\t\t\t}\n\n\t\t\tif (signal?.aborted) throw new Error(\"aborted\");\n\t\t\tconst commandFromStdin = shellConfig.commandTransport === \"stdin\";\n\t\t\tconst normalizedCommand = normalizeCommand(command);\n\t\t\tconst child = spawn(\n\t\t\t\tshellConfig.shell,\n\t\t\t\tcommandFromStdin ? shellConfig.args : [...shellConfig.args, normalizedCommand],\n\t\t\t\t{\n\t\t\t\t\tcwd,\n\t\t\t\t\tdetached: process.platform !== \"win32\",\n\t\t\t\t\tenv: env ?? getShellEnv(),\n\t\t\t\t\tstdio: [commandFromStdin ? \"pipe\" : \"ignore\", \"pipe\", \"pipe\"],\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t},\n\t\t\t);\n\t\t\tif (commandFromStdin) {\n\t\t\t\tchild.stdin?.on(\"error\", () => {});\n\t\t\t\tchild.stdin?.end(normalizedCommand);\n\t\t\t}\n\t\t\tif (child.pid) trackDetachedChildPid(child.pid);\n\t\t\tlet timedOut = false;\n\t\t\tlet timeoutHandle: NodeJS.Timeout | undefined;\n\t\t\tconst onAbort = () => {\n\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\t// Set timeout if provided.\n\t\t\t\tif (timeoutMs !== undefined) {\n\t\t\t\t\ttimeoutHandle = setTimeout(() => {\n\t\t\t\t\t\ttimedOut = true;\n\t\t\t\t\t\tif (child.pid) killProcessTree(child.pid);\n\t\t\t\t\t}, timeoutMs);\n\t\t\t\t}\n\t\t\t\t// Stream stdout and stderr.\n\t\t\t\tchild.stdout?.on(\"data\", onData);\n\t\t\t\tchild.stderr?.on(\"data\", onData);\n\t\t\t\t// Handle abort signal by killing the entire process tree.\n\t\t\t\tif (signal) {\n\t\t\t\t\tif (signal.aborted) onAbort();\n\t\t\t\t\telse signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}\n\t\t\t\t// Handle shell spawn errors and wait for the process to terminate without hanging\n\t\t\t\t// on inherited stdio handles held by detached descendants.\n\t\t\t\tconst exitCode = await waitForChildProcess(child);\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\tthrow new Error(\"aborted\");\n\t\t\t\t}\n\t\t\t\tif (timedOut) {\n\t\t\t\t\tthrow new Error(`timeout:${timeout}`);\n\t\t\t\t}\n\t\t\t\t// A signal-killed shell has no exit code. Use the standard shell convention so\n\t\t\t\t// callers do not mistake the termination for a successful command.\n\t\t\t\tconst signalCode = child.signalCode;\n\t\t\t\treturn { exitCode: exitCode ?? (signalCode ? 128 + (osConstants.signals[signalCode] ?? 0) : 1) };\n\t\t\t} finally {\n\t\t\t\tif (child.pid) untrackDetachedChildPid(child.pid);\n\t\t\t\tif (timeoutHandle) clearTimeout(timeoutHandle);\n\t\t\t\tif (signal) signal.removeEventListener(\"abort\", onAbort);\n\t\t\t}\n\t\t},\n\t};\n}\n\n/**\n * Create bash operations using pi's built-in local shell execution backend.\n *\n * This is useful for extensions that intercept user_bash and still want pi's\n * standard local shell behavior while wrapping or rewriting commands.\n */\n\nexport interface BashSpawnContext {\n\tcommand: string;\n\tcwd: string;\n\tenv: NodeJS.ProcessEnv;\n}\n\nexport type BashSpawnHook = (context: BashSpawnContext) => BashSpawnContext;\n\nexport function resolveSpawnContext(\n\tcommand: string,\n\tcwd: string,\n\tspawnHook: BashSpawnHook | undefined,\n\texposeSessionEnvironment: boolean,\n\tctx: ExtensionContext | undefined,\n): BashSpawnContext {\n\tconst env = { ...getShellEnv() };\n\tdelete env.PI_SESSION_ID;\n\tdelete env.PI_SESSION_FILE;\n\tdelete env.PI_PROVIDER;\n\tdelete env.PI_MODEL;\n\tdelete env.PI_REASONING_LEVEL;\n\tif (exposeSessionEnvironment && ctx) {\n\t\tconst model = ctx.model;\n\t\tenv.PI_SESSION_ID = ctx.sessionManager.getSessionId();\n\t\tconst sessionFile = ctx.sessionManager.getSessionFile();\n\t\tif (sessionFile) env.PI_SESSION_FILE = sessionFile;\n\t\tif (model) {\n\t\t\tenv.PI_PROVIDER = model.provider;\n\t\t\tenv.PI_MODEL = model.id;\n\t\t}\n\t\tif (ctx.thinkingLevel) env.PI_REASONING_LEVEL = ctx.thinkingLevel;\n\t}\n\tconst baseContext: BashSpawnContext = { command, cwd, env };\n\treturn spawnHook ? spawnHook(baseContext) : baseContext;\n}\n\nexport interface BashToolOptions {\n\t/** Custom operations for command execution. Default: local shell */\n\toperations?: BashOperations;\n\t/** Command prefix prepended to every command (for example shell setup commands) */\n\tcommandPrefix?: string;\n\t/** Optional explicit shell path from settings */\n\tshellPath?: string;\n\t/** Expose current Pi session metadata as PI_* environment variables. Default: true */\n\texposeSessionEnvironment?: boolean;\n\t/** Hook to adjust command, cwd, or env before execution */\n\tspawnHook?: BashSpawnHook;\n}\n\nexport type BashRenderState = {\n\tdispose?: () => void;\n};\n\nexport interface ShellToolConfig {\n\tname: string;\n\tlabel: string;\n\tshellName: string;\n\tprompt: string;\n\tpromptSnippet: string;\n\tpromptGuidelines?: readonly string[];\n\ttempFilePrefix: string;\n}\n\n/** Translate terminal shell failures to the native foreground tool contract once. */\nfunction shellToolResult(completion: TaskCompletion<BashToolDetails | undefined>, managed: boolean) {\n\tconst status = completion.status;\n\tif (completion.result.structuredContent) return completion.result;\n\tif (status === \"failed\" || status === \"timeout\" || status === \"cancelled\") {\n\t\tconst text = completion.result.content\n\t\t\t.filter((part) => part.type === \"text\")\n\t\t\t.map((part) => part.text)\n\t\t\t.join(\"\\n\");\n\t\tconst message = completion.error ? text || completion.error : `${text ? `${text}\\n\\n` : \"\"}Command ${status}`;\n\t\tthrow managed ? new TaskExecutionError(message, status) : new Error(message);\n\t}\n\treturn completion.result;\n}\n\nexport function createShellToolDefinition(\n\tcwd: string,\n\tconfig: ShellToolConfig,\n\toptions: BashToolOptions & { operations: BashOperations },\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst ops = options.operations;\n\tconst commandPrefix = options?.commandPrefix;\n\tconst exposeSessionEnvironment = options?.exposeSessionEnvironment ?? true;\n\tconst spawnHook = options?.spawnHook;\n\treturn {\n\t\tname: config.name,\n\t\tlabel: config.label,\n\t\tdescription: `Execute a ${config.shellName} command in the current working directory. Returns stdout and stderr, truncated to the last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first); the full output is saved to a temp file. Optionally provide a timeout in seconds (no default). Choose the mode per call: foreground (default) blocks until the command exits — use it when your next step needs the output; background: true returns immediately with a task ID — use it for long-running work (builds, servers, watchers, big test suites) or when you have independent work to continue. A handoff is not completion: the result arrives later as an automatic completion notification; meanwhile use tasks read to inspect output, tasks wait with an ID for one task or without one for any running task, and tasks kill to stop it. Steering interrupts only a wait, never execution. Background output is limited to 20 MiB; an expired tasks wait window never stops the command.`,\n\t\tpromptSnippet: config.promptSnippet,\n\t\tpromptGuidelines: exposeSessionEnvironment && config.promptGuidelines ? [...config.promptGuidelines] : undefined,\n\t\tparameters: bashSchema,\n\t\toutputSchema: bashOutputSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\ttoolCallId,\n\t\t\t{ command, timeout, background }: BashToolInput,\n\t\t\tparentSignal?: AbortSignal,\n\t\t\toriginalUpdate?,\n\t\t\tctx?: ExtensionContext,\n\t\t) {\n\t\t\tconst host = ctx?.tasks;\n\t\t\tif (host?.closed) throw new Error(\"Task service is closed\");\n\t\t\tconst run = async (managed?: ManagedShellExecution): Promise<TaskCompletion<BashToolDetails | undefined>> => {\n\t\t\t\tconst signal = managed?.control.signal ?? parentSignal;\n\t\t\t\ttry {\n\t\t\t\t\tif (managed) {\n\t\t\t\t\t\tif (signal?.aborted) throw new Error(\"Command aborted\");\n\t\t\t\t\t\tresolveTimeoutMs(timeout);\n\t\t\t\t\t}\n\t\t\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${command}` : command;\n\t\t\t\t\tconst spawnContext = resolveSpawnContext(\n\t\t\t\t\t\tresolvedCommand,\n\t\t\t\t\t\tctx?.cwd || cwd,\n\t\t\t\t\t\tspawnHook,\n\t\t\t\t\t\texposeSessionEnvironment,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t);\n\t\t\t\t\treturn await runShellCommand({\n\t\t\t\t\t\toperations: ops,\n\t\t\t\t\t\tcontext: spawnContext,\n\t\t\t\t\t\ttempFilePrefix: config.tempFilePrefix,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tonUpdate: originalUpdate,\n\t\t\t\t\t\tmanaged,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Setup and cleanup exceptions carry an explicit terminal status.\n\t\t\t\t\tif (!managed) throw error;\n\t\t\t\t\tthrow new TaskExecutionError(\n\t\t\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\t\t\tmanaged.control.signal.aborted ? \"cancelled\" : \"failed\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\t\t\tif (!host) {\n\t\t\t\tif (background)\n\t\t\t\t\tthrow new Error(\"Background execution is not available in this host. No command was started.\");\n\t\t\t\treturn shellToolResult(await run(), false);\n\t\t\t}\n\t\t\tconst outcome = await host.execute<BashToolDetails | undefined>({\n\t\t\t\tkind: config.name,\n\t\t\t\ttitle: command,\n\t\t\t\ttoolCallId,\n\t\t\t\tcommand,\n\t\t\t\tcwd: ctx?.cwd || cwd,\n\t\t\t\tbackground,\n\t\t\t\tsignal: parentSignal,\n\t\t\t\tonUpdate: originalUpdate,\n\t\t\t\trun: (control) => run({ control }),\n\t\t\t});\n\t\t\tif (outcome.kind === \"result\") return shellToolResult(outcome, true);\n\t\t\tconst tail = `Task ID: ${outcome.task.id}. Status: ${outcome.task.status}. Completion arrives automatically as a notification — do not poll or immediately wait on it; continue with other work or hand back to the user. Use tasks read to inspect output, tasks wait only when your next step is blocked on a result (one ID or any running task; prefer foreground next time in that case), or tasks kill to stop it.`;\n\t\t\t// Shell execution can become background work in two ways, and the model has to know which\n\t\t\t// one it got: a submitted background command starts from an empty log, while a detached\n\t\t\t// one already holds output and keeps its original timeout.\n\t\t\tconst handoff =\n\t\t\t\tbackground === true\n\t\t\t\t\t? `Command handed to background. ${tail}`\n\t\t\t\t\t: `Command moved to the background while it was running, by the user. The execution continues unchanged — no restart, and a supplied timeout is still measured from command startup. Output produced so far is already in the log, so tasks read now returns partial output, not a fresh start. ${tail}`;\n\t\t\treturn {\n\t\t\t\tstructuredContent: { task_id: outcome.task.id, status: outcome.task.status },\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: `${handoff}${outcome.task.outputPath ? `\\nFull output: ${outcome.task.outputPath}` : \"\"}`,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: {\n\t\t\t\t\tbackground: { kind: \"background\", taskId: outcome.task.id },\n\t\t\t\t\tfullOutputPath: outcome.task.outputPath,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\t...createShellRenderers(config),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"shell-tool.js","sourceRoot":"","sources":["../../../src/core/tools/shell-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAuB,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAGN,mBAAmB,EACnB,gBAAgB,GAEhB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAA8B,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAyB,MAAM,eAAe,CAAC;AAE5F,MAAM,UAAU,GAAG,IA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G,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC1D,MAAM,IAAI,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC5C,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACnB,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;KAC7C,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["import { type Static, Type } from \"typebox\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { type TaskCompletion, TaskExecutionError } from \"../tasks/types.ts\";\nimport {\n\ttype BashOperations,\n\ttype BashToolOptions,\n\tresolveSpawnContext,\n\tresolveTimeoutMs,\n\ttype ShellToolConfig,\n} from \"./bash.ts\";\nimport { createShellRenderers } from \"./renderers/bash.ts\";\nimport { type ManagedShellExecution, runShellCommand } from \"./shell-execution.ts\";\nimport { createLocalBashOperations } from \"./shell-operations.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult } from \"./truncate.ts\";\n\nconst bashSchema = Type.Object({\n\tcommand: Type.String({ description: \"Shell command to execute\" }),\n\ttimeout: Type.Optional(Type.Number({ description: \"Timeout in seconds (optional, no default timeout)\" })),\n\tbackground: Type.Optional(\n\t\tType.Boolean({\n\t\t\tdescription:\n\t\t\t\t\"true returns a managed task ID immediately and runs the command in the background, and you are notified when it completes — do not poll for its result; omit or false to block until exit\",\n\t\t}),\n\t),\n});\n\nexport const bashToolSystemPromptContribution = {\n\tsnippet: \"Execute bash commands, foreground or background\",\n\tguidelines: [\"You can inspect PI_* environment variables for current model and session details.\"],\n} as const;\n\nexport type BashToolInput = Static<typeof bashSchema>;\n\nconst bashOutputSchema = Type.Union([\n\tType.Object({\n\t\toutput: Type.String({\n\t\t\tdescription: \"Combined stdout and stderr, up to 1 MiB, keeping head and tail when truncated.\",\n\t\t}),\n\t\ttruncated: Type.Boolean(),\n\t\tfull_output_path: Type.Optional(Type.String()),\n\t\texit_code: Type.Number(),\n\t\twall_time_seconds: Type.Number(),\n\t}),\n\tType.Object({ task_id: Type.String(), status: Type.String() }),\n]);\n\nexport interface BashToolDetails {\n\ttruncation?: TruncationResult;\n\tfullOutputPath?: string;\n\t/** Settled handoff snapshot, not a command completion or exit code. */\n\tbackground?: { kind: \"background\"; taskId: string };\n}\n\nexport type BashRenderState = {\n\tdispose?: () => void;\n};\n\n/** Translate terminal shell failures to the native foreground tool contract once. */\nfunction shellToolResult(completion: TaskCompletion<BashToolDetails | undefined>, managed: boolean) {\n\tconst status = completion.status;\n\tif (completion.result.structuredContent) return completion.result;\n\tif (status === \"failed\" || status === \"timeout\" || status === \"cancelled\") {\n\t\tconst text = completion.result.content\n\t\t\t.filter((part) => part.type === \"text\")\n\t\t\t.map((part) => part.text)\n\t\t\t.join(\"\\n\");\n\t\tconst message = completion.error ? text || completion.error : `${text ? `${text}\\n\\n` : \"\"}Command ${status}`;\n\t\tthrow managed ? new TaskExecutionError(message, status) : new Error(message);\n\t}\n\treturn completion.result;\n}\n\nexport function createShellToolDefinition(\n\tcwd: string,\n\tconfig: ShellToolConfig,\n\toptions: BashToolOptions & { operations: BashOperations },\n): ToolDefinition<typeof bashSchema, BashToolDetails | undefined, BashRenderState> {\n\tconst ops = options.operations;\n\tconst commandPrefix = options?.commandPrefix;\n\tconst exposeSessionEnvironment = options?.exposeSessionEnvironment ?? true;\n\tconst spawnHook = options?.spawnHook;\n\treturn {\n\t\tname: config.name,\n\t\tlabel: config.label,\n\t\tdescription: `Execute a ${config.shellName} command in the current working directory. Returns stdout and stderr, truncated to the last ${DEFAULT_MAX_LINES} lines or ${DEFAULT_MAX_BYTES / 1024}KB (whichever is hit first); the full output is saved to a temp file. Optionally provide a timeout in seconds (no default). Choose the mode per call: foreground (default) blocks until the command exits — use it when your next step needs the output; background: true returns immediately with a task ID — use it for long-running work (builds, servers, watchers, big test suites) or when you have independent work to continue. A handoff is not completion: the result arrives later as an automatic completion notification; meanwhile use tasks read to inspect output, tasks wait with an ID for one task or without one for any running task, and tasks kill to stop it. Steering interrupts only a wait, never execution. Background output is limited to 20 MiB; an expired tasks wait window never stops the command.`,\n\t\tpromptSnippet: config.promptSnippet,\n\t\tpromptGuidelines: exposeSessionEnvironment && config.promptGuidelines ? [...config.promptGuidelines] : undefined,\n\t\tparameters: bashSchema,\n\t\toutputSchema: bashOutputSchema,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tasync execute(\n\t\t\ttoolCallId,\n\t\t\t{ command, timeout, background }: BashToolInput,\n\t\t\tparentSignal?: AbortSignal,\n\t\t\toriginalUpdate?,\n\t\t\tctx?: ExtensionContext,\n\t\t) {\n\t\t\tconst host = ctx?.tasks;\n\t\t\tif (host?.closed) throw new Error(\"Task service is closed\");\n\t\t\tconst run = async (managed?: ManagedShellExecution): Promise<TaskCompletion<BashToolDetails | undefined>> => {\n\t\t\t\tconst signal = managed?.control.signal ?? parentSignal;\n\t\t\t\ttry {\n\t\t\t\t\tif (managed) {\n\t\t\t\t\t\tif (signal?.aborted) throw new Error(\"Command aborted\");\n\t\t\t\t\t\tresolveTimeoutMs(timeout);\n\t\t\t\t\t}\n\t\t\t\t\tconst resolvedCommand = commandPrefix ? `${commandPrefix}\\n${command}` : command;\n\t\t\t\t\tconst spawnContext = resolveSpawnContext(\n\t\t\t\t\t\tresolvedCommand,\n\t\t\t\t\t\tctx?.cwd || cwd,\n\t\t\t\t\t\tspawnHook,\n\t\t\t\t\t\texposeSessionEnvironment,\n\t\t\t\t\t\tctx,\n\t\t\t\t\t);\n\t\t\t\t\treturn await runShellCommand({\n\t\t\t\t\t\toperations: ops,\n\t\t\t\t\t\tcontext: spawnContext,\n\t\t\t\t\t\ttempFilePrefix: config.tempFilePrefix,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tonUpdate: originalUpdate,\n\t\t\t\t\t\tmanaged,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Setup and cleanup exceptions carry an explicit terminal status.\n\t\t\t\t\tif (!managed) throw error;\n\t\t\t\t\tthrow new TaskExecutionError(\n\t\t\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t\t\t\tmanaged.control.signal.aborted ? \"cancelled\" : \"failed\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t};\n\t\t\tif (!host) {\n\t\t\t\tif (background)\n\t\t\t\t\tthrow new Error(\"Background execution is not available in this host. No command was started.\");\n\t\t\t\treturn shellToolResult(await run(), false);\n\t\t\t}\n\t\t\tconst outcome = await host.execute<BashToolDetails | undefined>({\n\t\t\t\tkind: config.name,\n\t\t\t\ttitle: command,\n\t\t\t\ttoolCallId,\n\t\t\t\tcommand,\n\t\t\t\tcwd: ctx?.cwd || cwd,\n\t\t\t\tbackground,\n\t\t\t\tsignal: parentSignal,\n\t\t\t\tonUpdate: originalUpdate,\n\t\t\t\trun: (control) => run({ control }),\n\t\t\t});\n\t\t\tif (outcome.kind === \"result\") return shellToolResult(outcome, true);\n\t\t\tconst tail = `Task ID: ${outcome.task.id}. Status: ${outcome.task.status}. Completion arrives automatically as a notification — do not poll or immediately wait on it; continue with other work or hand back to the user. Use tasks read to inspect output, tasks wait only when your next step is blocked on a result (one ID or any running task; prefer foreground next time in that case), or tasks kill to stop it.`;\n\t\t\t// Shell execution can become background work in two ways, and the model has to know which\n\t\t\t// one it got: a submitted background command starts from an empty log, while a detached\n\t\t\t// one already holds output and keeps its original timeout.\n\t\t\tconst handoff =\n\t\t\t\tbackground === true\n\t\t\t\t\t? `Command handed to background. ${tail}`\n\t\t\t\t\t: `Command moved to the background while it was running, by the user. The execution continues unchanged — no restart, and a supplied timeout is still measured from command startup. Output produced so far is already in the log, so tasks read now returns partial output, not a fresh start. ${tail}`;\n\t\t\treturn {\n\t\t\t\tstructuredContent: { task_id: outcome.task.id, status: outcome.task.status },\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: `${handoff}${outcome.task.outputPath ? `\\nFull output: ${outcome.task.outputPath}` : \"\"}`,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: {\n\t\t\t\t\tbackground: { kind: \"background\", taskId: outcome.task.id },\n\t\t\t\t\tfullOutputPath: outcome.task.outputPath,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t\t...createShellRenderers(config),\n\t};\n}\n\nconst bashToolConfig: ShellToolConfig = {\n\tname: \"bash\",\n\tlabel: \"bash\",\n\tshellName: \"bash\",\n\tprompt: \"$\",\n\tpromptSnippet: bashToolSystemPromptContribution.snippet,\n\tpromptGuidelines: bashToolSystemPromptContribution.guidelines,\n\ttempFilePrefix: \"pi-bash\",\n};\n\nexport function createBashToolDefinition(\n\tcwd: string,\n\toptions?: BashToolOptions,\n): ReturnType<typeof createShellToolDefinition> {\n\treturn createShellToolDefinition(cwd, bashToolConfig, {\n\t\t...options,\n\t\toperations: options?.operations ?? createLocalBashOperations({ shellPath: options?.shellPath }),\n\t});\n}\n\nexport function createBashTool(cwd: string, options?: BashToolOptions) {\n\tconst definition = createBashToolDefinition(cwd, options);\n\tconst tool = wrapToolDefinition(definition);\n\tObject.assign(tool, {\n\t\tpromptSnippet: definition.promptSnippet,\n\t\tpromptGuidelines: definition.promptGuidelines,\n\t});\n\treturn tool;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAenE,eAAO,MAAM,iBAAiB,EAAE,eAAe,EAc9C,CAAC"}
|
package/dist/extensions/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "./keybindings.js";
|
|
1
2
|
import btwExtension from "./btw/index.js";
|
|
2
3
|
import cachedCompactionExtension from "./cached-compaction/index.js";
|
|
3
4
|
import codemodeExtension from "./codemode/index.js";
|
|
@@ -8,6 +9,8 @@ import providerExtension from "./provider/index.js";
|
|
|
8
9
|
import questionExtension from "./question/index.js";
|
|
9
10
|
import searchExtension from "./search/index.js";
|
|
10
11
|
import statuslineExtension from "./statusline/index.js";
|
|
12
|
+
import tasksExtension from "./tasks/index.js";
|
|
13
|
+
import toolPresentationExtension from "./tool-presentation/index.js";
|
|
11
14
|
import toolSearchExtension from "./tool-search/index.js";
|
|
12
15
|
export const builtInExtensions = [
|
|
13
16
|
{ name: "codemode", factory: codemodeExtension, replaceable: true, builtin: true },
|
|
@@ -20,6 +23,8 @@ export const builtInExtensions = [
|
|
|
20
23
|
{ name: "provider", factory: providerExtension, builtin: true },
|
|
21
24
|
{ name: "question", factory: questionExtension, builtin: true },
|
|
22
25
|
{ name: "statusline", factory: statuslineExtension, builtin: true },
|
|
26
|
+
{ name: "tool-presentation", factory: toolPresentationExtension, builtin: true },
|
|
27
|
+
{ name: "tasks", factory: tasksExtension, replaceable: true, builtin: true },
|
|
23
28
|
{ name: "search", factory: searchExtension, builtin: true },
|
|
24
29
|
];
|
|
25
30
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,yBAAyB,MAAM,8BAA8B,CAAC;AACrE,O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B,EAAE,OAAO,EAAE,IAAI,EAAE;IAC/D,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,IAAI,EAAE;IAC/D,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,IAAI,EAAE;IACnE,EAAE,IAAI,EAAE,mBAAmB,EAAE,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,IAAI,EAAE;IAChF,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;IAC5E,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE;CAC3D,CAAC","sourcesContent":["import \"./keybindings.ts\";\nimport type { InlineExtension } from \"../core/extensions/types.ts\";\nimport btwExtension from \"./btw/index.ts\";\nimport cachedCompactionExtension from \"./cached-compaction/index.ts\";\nimport codemodeExtension from \"./codemode/index.ts\";\nimport deepwikiExtension from \"./deepwiki/index.ts\";\nimport llamaExtension from \"./llama/index.ts\";\nimport mcpExtension from \"./mcp/index.ts\";\nimport providerExtension from \"./provider/index.ts\";\nimport questionExtension from \"./question/index.ts\";\nimport searchExtension from \"./search/index.ts\";\nimport statuslineExtension from \"./statusline/index.ts\";\nimport tasksExtension from \"./tasks/index.ts\";\nimport toolPresentationExtension from \"./tool-presentation/index.ts\";\nimport toolSearchExtension from \"./tool-search/index.ts\";\n\nexport const builtInExtensions: InlineExtension[] = [\n\t{ name: \"codemode\", factory: codemodeExtension, replaceable: true, builtin: true },\n\t{ name: \"mcp\", factory: mcpExtension, replaceable: true, builtin: true },\n\t{ name: \"tool-search\", factory: toolSearchExtension, replaceable: true, builtin: true },\n\t{ name: \"cached-compaction\", factory: cachedCompactionExtension, replaceable: true, builtin: true },\n\t{ name: \"llama.cpp\", factory: llamaExtension, builtin: true },\n\t{ name: \"btw\", factory: btwExtension, builtin: true },\n\t{ name: \"deepwiki\", factory: deepwikiExtension, builtin: true },\n\t{ name: \"provider\", factory: providerExtension, builtin: true },\n\t{ name: \"question\", factory: questionExtension, builtin: true },\n\t{ name: \"statusline\", factory: statuslineExtension, builtin: true },\n\t{ name: \"tool-presentation\", factory: toolPresentationExtension, builtin: true },\n\t{ name: \"tasks\", factory: tasksExtension, replaceable: true, builtin: true },\n\t{ name: \"search\", factory: searchExtension, builtin: true },\n];\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Load every bundled extension-owned keybinding before building managers or generated schemas. */
|
|
2
|
+
import "./btw/keybindings.ts";
|
|
3
|
+
import "./provider/keybindings.ts";
|
|
4
|
+
import "./question/keybindings.ts";
|
|
5
|
+
import "./tasks/keybindings.ts";
|
|
6
|
+
//# sourceMappingURL=keybindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keybindings.d.ts","sourceRoot":"","sources":["../../src/extensions/keybindings.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,OAAO,sBAAsB,CAAC;AAC9B,OAAO,2BAA2B,CAAC;AACnC,OAAO,2BAA2B,CAAC;AACnC,OAAO,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Load every bundled extension-owned keybinding before building managers or generated schemas. */
|
|
2
|
+
import "./btw/keybindings.js";
|
|
3
|
+
import "./provider/keybindings.js";
|
|
4
|
+
import "./question/keybindings.js";
|
|
5
|
+
import "./tasks/keybindings.js";
|
|
6
|
+
//# sourceMappingURL=keybindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keybindings.js","sourceRoot":"","sources":["../../src/extensions/keybindings.ts"],"names":[],"mappings":"AAAA,mGAAmG;AACnG,OAAO,sBAAsB,CAAC;AAC9B,OAAO,2BAA2B,CAAC;AACnC,OAAO,2BAA2B,CAAC;AACnC,OAAO,wBAAwB,CAAC","sourcesContent":["/** Load every bundled extension-owned keybinding before building managers or generated schemas. */\nimport \"./btw/keybindings.ts\";\nimport \"./provider/keybindings.ts\";\nimport \"./question/keybindings.ts\";\nimport \"./tasks/keybindings.ts\";\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import "./keybindings.ts";
|
|
2
|
+
import type { ExtensionAPI } from "../../core/extensions/types.ts";
|
|
3
|
+
/** User-facing Tasks management; execution and durable delivery remain session-owned. */
|
|
4
|
+
export default function tasksExtension(pi: ExtensionAPI): void;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/tasks/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAoB,MAAM,gCAAgC,CAAC;AAOrF,yFAAyF;AACzF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAoC7D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import "./keybindings.js";
|
|
2
|
+
import { boundedText, describeTaskLine } from "./tool/actions.js";
|
|
3
|
+
import { createTasksToolDefinition } from "./tool.js";
|
|
4
|
+
import { renderTaskCompletion } from "./ui/completion-render.js";
|
|
5
|
+
import { bindTasksUI } from "./ui/index.js";
|
|
6
|
+
import { confirmStopBranchTasks } from "./ui/tree.js";
|
|
7
|
+
/** User-facing Tasks management; execution and durable delivery remain session-owned. */
|
|
8
|
+
export default function tasksExtension(pi) {
|
|
9
|
+
let ui;
|
|
10
|
+
const bind = (ctx) => {
|
|
11
|
+
ui?.dispose();
|
|
12
|
+
ui = bindTasksUI(ctx);
|
|
13
|
+
};
|
|
14
|
+
pi.on("session_start", (_event, ctx) => bind(ctx));
|
|
15
|
+
pi.on("session_shutdown", () => {
|
|
16
|
+
ui?.dispose();
|
|
17
|
+
ui = undefined;
|
|
18
|
+
});
|
|
19
|
+
pi.on("session_before_tree", async (event, ctx) => {
|
|
20
|
+
if (!ctx.hasUI)
|
|
21
|
+
return;
|
|
22
|
+
const stopped = ctx.tasks.session?.stoppedByTreeNavigation(event.preparation.targetId) ?? [];
|
|
23
|
+
if (!(await confirmStopBranchTasks(stopped, (title, message) => ctx.ui.confirm(title, message))))
|
|
24
|
+
return { cancel: true };
|
|
25
|
+
});
|
|
26
|
+
pi.registerTool(createTasksToolDefinition());
|
|
27
|
+
pi.registerMessageRenderer("task-completion", renderTaskCompletion);
|
|
28
|
+
pi.registerCommand("tasks", {
|
|
29
|
+
description: "View and manage session tasks",
|
|
30
|
+
handler: async (_args, ctx) => {
|
|
31
|
+
if (ctx.mode !== "tui") {
|
|
32
|
+
const tasks = ctx.tasks.list().filter((task) => task.mode === "background");
|
|
33
|
+
ctx.ui.notify(boundedText(tasks.slice(0, 10).map(describeTaskLine).join("\n")) || "No background tasks.", "info");
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (!ui)
|
|
37
|
+
bind(ctx);
|
|
38
|
+
await ui.open();
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/tasks/index.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAgB,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,yFAAyF;AACzF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EAAgB;IACtD,IA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,KAAK,KAAK,EAAE,CAAC;gBACxB,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;gBAC5E,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,sBAAsB,EAC1F,MAAM,CACN,CAAC;gBACF,OAAO;YACR,CAAC;YACD,IAAI,CAAC,EAAE;gBAAE,IAAI,CAAC,GAAG,CAAC,CAAC;YACnB,MAAM,EAAG,CAAC,IAAI,EAAE,CAAC;QAClB,CAAC;KACD,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import \"./keybindings.ts\";\nimport type { ExtensionAPI, ExtensionContext } from \"../../core/extensions/types.ts\";\nimport { boundedText, describeTaskLine } from \"./tool/actions.ts\";\nimport { createTasksToolDefinition } from \"./tool.ts\";\nimport { renderTaskCompletion } from \"./ui/completion-render.ts\";\nimport { bindTasksUI, type TasksUI } from \"./ui/index.ts\";\nimport { confirmStopBranchTasks } from \"./ui/tree.ts\";\n\n/** User-facing Tasks management; execution and durable delivery remain session-owned. */\nexport default function tasksExtension(pi: ExtensionAPI): void {\n\tlet ui: TasksUI | undefined;\n\tconst bind = (ctx: ExtensionContext) => {\n\t\tui?.dispose();\n\t\tui = bindTasksUI(ctx);\n\t};\n\n\tpi.on(\"session_start\", (_event, ctx) => bind(ctx));\n\tpi.on(\"session_shutdown\", () => {\n\t\tui?.dispose();\n\t\tui = undefined;\n\t});\n\tpi.on(\"session_before_tree\", async (event, ctx) => {\n\t\tif (!ctx.hasUI) return;\n\t\tconst stopped = ctx.tasks.session?.stoppedByTreeNavigation(event.preparation.targetId) ?? [];\n\t\tif (!(await confirmStopBranchTasks(stopped, (title, message) => ctx.ui.confirm(title, message))))\n\t\t\treturn { cancel: true };\n\t});\n\n\tpi.registerTool(createTasksToolDefinition());\n\tpi.registerMessageRenderer(\"task-completion\", renderTaskCompletion);\n\tpi.registerCommand(\"tasks\", {\n\t\tdescription: \"View and manage session tasks\",\n\t\thandler: async (_args, ctx) => {\n\t\t\tif (ctx.mode !== \"tui\") {\n\t\t\t\tconst tasks = ctx.tasks.list().filter((task) => task.mode === \"background\");\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\tboundedText(tasks.slice(0, 10).map(describeTaskLine).join(\"\\n\")) || \"No background tasks.\",\n\t\t\t\t\t\"info\",\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (!ui) bind(ctx);\n\t\t\tawait ui!.open();\n\t\t},\n\t});\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare module "@earendil-works/pi-tui" {
|
|
2
|
+
interface Keybindings {
|
|
3
|
+
"app.tasks.detach": true;
|
|
4
|
+
"app.tasks.previousTab": true;
|
|
5
|
+
"app.tasks.nextTab": true;
|
|
6
|
+
"app.tasks.kill": true;
|
|
7
|
+
"app.tasks.confirmStop": true;
|
|
8
|
+
"app.tasks.detachSelected": true;
|
|
9
|
+
"app.tasks.search": true;
|
|
10
|
+
"app.tasks.follow": true;
|
|
11
|
+
"app.tasks.top": true;
|
|
12
|
+
"app.tasks.bottom": true;
|
|
13
|
+
"app.tasks.nextFocus": true;
|
|
14
|
+
"app.tasks.previousFocus": true;
|
|
15
|
+
"app.tasks.help": true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=keybindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keybindings.d.ts","sourceRoot":"","sources":["../../../src/extensions/tasks/keybindings.ts"],"names":[],"mappings":"AAMA,OAAO,QAAQ,wBAAwB,CAAC;IACvC,UAAU,WAAW;QACpB,kBAAkB,EAAE,IAAI,CAAC;QACzB,uBAAuB,EAAE,IAAI,CAAC;QAC9B,mBAAmB,EAAE,IAAI,CAAC;QAC1B,gBAAgB,EAAE,IAAI,CAAC;QACvB,uBAAuB,EAAE,IAAI,CAAC;QAC9B,0BAA0B,EAAE,IAAI,CAAC;QACjC,kBAAkB,EAAE,IAAI,CAAC;QACzB,kBAAkB,EAAE,IAAI,CAAC;QACzB,eAAe,EAAE,IAAI,CAAC;QACtB,kBAAkB,EAAE,IAAI,CAAC;QACzB,qBAAqB,EAAE,IAAI,CAAC;QAC5B,yBAAyB,EAAE,IAAI,CAAC;QAChC,gBAAgB,EAAE,IAAI,CAAC;KACvB;CACD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { registerKeybindingHelpSection, registerKeybindings, registerReservedKeybindings, } from "../../core/keybinding-registry.js";
|
|
2
|
+
const TASK_KEYBINDINGS = {
|
|
3
|
+
"app.tasks.detach": { defaultKeys: "ctrl+b", description: "Move foreground tasks to the background" },
|
|
4
|
+
"app.tasks.previousTab": { defaultKeys: "left", description: "Show Output in the focused task inspector" },
|
|
5
|
+
"app.tasks.nextTab": { defaultKeys: "right", description: "Show Details in the focused task inspector" },
|
|
6
|
+
"app.tasks.kill": { defaultKeys: "k", description: "Stop the selected task" },
|
|
7
|
+
"app.tasks.confirmStop": { defaultKeys: "enter", description: "Confirm stopping the selected task" },
|
|
8
|
+
"app.tasks.detachSelected": { defaultKeys: "b", description: "Move the selected task to the background" },
|
|
9
|
+
"app.tasks.search": { defaultKeys: "/", description: "Search retained task identities and labels" },
|
|
10
|
+
"app.tasks.follow": { defaultKeys: "f", description: "Follow the selected task's output" },
|
|
11
|
+
"app.tasks.top": { defaultKeys: "home", description: "Go to the top of the task list or preview" },
|
|
12
|
+
"app.tasks.bottom": { defaultKeys: "end", description: "Go to the bottom of the task list or preview" },
|
|
13
|
+
"app.tasks.nextFocus": { defaultKeys: "tab", description: "Switch between task list and inspector" },
|
|
14
|
+
"app.tasks.previousFocus": { defaultKeys: "shift+tab", description: "Switch between task inspector and list" },
|
|
15
|
+
"app.tasks.help": { defaultKeys: "?", description: "Show task controls" },
|
|
16
|
+
};
|
|
17
|
+
registerKeybindings(TASK_KEYBINDINGS);
|
|
18
|
+
registerReservedKeybindings("app.tasks.detach");
|
|
19
|
+
registerKeybindingHelpSection({
|
|
20
|
+
id: "tasks",
|
|
21
|
+
title: "Tasks",
|
|
22
|
+
rows: [
|
|
23
|
+
{ action: "app.tasks.detach", description: TASK_KEYBINDINGS["app.tasks.detach"].description },
|
|
24
|
+
{
|
|
25
|
+
action: "app.tasks.detachSelected",
|
|
26
|
+
description: `${TASK_KEYBINDINGS["app.tasks.detachSelected"].description} (while /tasks is open)`,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=keybindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keybindings.js","sourceRoot":"","sources":["../../../src/extensions/tasks/keybindings.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,6BAA6B,EAC7B,mBAAmB,EACnB,2BAA2B,GAC3B,MAAM,mCAAmC,CAAC;AAoB3C,MAAM,gBAAgB,GAAG;IACxB,kBAAkB,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,yCAAyC,EAAE;IACrG,uBAAuB,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,2CAA2C,EAAE;IAC1G,mBAAmB,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,4CAA4C,EAAE;IACxG,gBAAgB,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,wBAAwB,EAAE;IAC7E,uBAAuB,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,EAAE,oCAAoC,EAAE;IACpG,0BAA0B,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,0CAA0C,EAAE;IACzG,kBAAkB,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,4CAA4C,EAAE;IACnG,kBAAkB,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,mCAAmC,EAAE;IAC1F,eAAe,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,2CAA2C,EAAE;IAClG,kBAAkB,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,8CAA8C,EAAE;IACvG,qBAAqB,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,wCAAwC,EAAE;IACpG,yBAAyB,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,wCAAwC,EAAE;IAC9G,gBAAgB,EAAE,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,oBAAoB,EAAE;CAChE,CAAC;AAEX,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;AAEtC,2BAA2B,CAAC,kBAAkB,CAAC,CAAC;AAEhD,6BAA6B,CAAC;IAC7B,EAAE,EAAE,OAAO;IACX,KAAK,EAAE,OAAO;IACd,IAAI,EAAE;QACL,EAAE,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,CAAC,WAAW,EAAE;QAC7F;YACC,MAAM,EAAE,0BAA0B;YAClC,WAAW,EAAE,GAAG,gBAAgB,CAAC,0BAA0B,CAAC,CAAC,WAAW,yBAAyB;SACjG;KACD;CACD,CAAC,CAAC","sourcesContent":["import {\n\tregisterKeybindingHelpSection,\n\tregisterKeybindings,\n\tregisterReservedKeybindings,\n} from \"../../core/keybinding-registry.ts\";\n\ndeclare module \"@earendil-works/pi-tui\" {\n\tinterface Keybindings {\n\t\t\"app.tasks.detach\": true;\n\t\t\"app.tasks.previousTab\": true;\n\t\t\"app.tasks.nextTab\": true;\n\t\t\"app.tasks.kill\": true;\n\t\t\"app.tasks.confirmStop\": true;\n\t\t\"app.tasks.detachSelected\": true;\n\t\t\"app.tasks.search\": true;\n\t\t\"app.tasks.follow\": true;\n\t\t\"app.tasks.top\": true;\n\t\t\"app.tasks.bottom\": true;\n\t\t\"app.tasks.nextFocus\": true;\n\t\t\"app.tasks.previousFocus\": true;\n\t\t\"app.tasks.help\": true;\n\t}\n}\n\nconst TASK_KEYBINDINGS = {\n\t\"app.tasks.detach\": { defaultKeys: \"ctrl+b\", description: \"Move foreground tasks to the background\" },\n\t\"app.tasks.previousTab\": { defaultKeys: \"left\", description: \"Show Output in the focused task inspector\" },\n\t\"app.tasks.nextTab\": { defaultKeys: \"right\", description: \"Show Details in the focused task inspector\" },\n\t\"app.tasks.kill\": { defaultKeys: \"k\", description: \"Stop the selected task\" },\n\t\"app.tasks.confirmStop\": { defaultKeys: \"enter\", description: \"Confirm stopping the selected task\" },\n\t\"app.tasks.detachSelected\": { defaultKeys: \"b\", description: \"Move the selected task to the background\" },\n\t\"app.tasks.search\": { defaultKeys: \"/\", description: \"Search retained task identities and labels\" },\n\t\"app.tasks.follow\": { defaultKeys: \"f\", description: \"Follow the selected task's output\" },\n\t\"app.tasks.top\": { defaultKeys: \"home\", description: \"Go to the top of the task list or preview\" },\n\t\"app.tasks.bottom\": { defaultKeys: \"end\", description: \"Go to the bottom of the task list or preview\" },\n\t\"app.tasks.nextFocus\": { defaultKeys: \"tab\", description: \"Switch between task list and inspector\" },\n\t\"app.tasks.previousFocus\": { defaultKeys: \"shift+tab\", description: \"Switch between task inspector and list\" },\n\t\"app.tasks.help\": { defaultKeys: \"?\", description: \"Show task controls\" },\n} as const;\n\nregisterKeybindings(TASK_KEYBINDINGS);\n\nregisterReservedKeybindings(\"app.tasks.detach\");\n\nregisterKeybindingHelpSection({\n\tid: \"tasks\",\n\ttitle: \"Tasks\",\n\trows: [\n\t\t{ action: \"app.tasks.detach\", description: TASK_KEYBINDINGS[\"app.tasks.detach\"].description },\n\t\t{\n\t\t\taction: \"app.tasks.detachSelected\",\n\t\t\tdescription: `${TASK_KEYBINDINGS[\"app.tasks.detachSelected\"].description} (while /tasks is open)`,\n\t\t},\n\t],\n});\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Management only: execution and delivery belong to the session task runtime. */
|
|
2
|
-
import type { AgentToolResult } from "
|
|
3
|
-
import { type TaskSnapshot, type TasksContext } from "
|
|
2
|
+
import type { AgentToolResult } from "../../../core/extensions/types.ts";
|
|
3
|
+
import { type TaskSnapshot, type TasksContext } from "../../../core/tasks/types.ts";
|
|
4
4
|
import { type TasksInput } from "./schema.ts";
|
|
5
5
|
import type { TasksKillDetails, TasksListDetails, TasksReadDetails, TasksWaitDetails } from "./types.ts";
|
|
6
6
|
export declare function boundedText(text: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../../src/extensions/tasks/tool/actions.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAElF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAGzE,OAAO,EAIN,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,MAAM,8BAA8B,CAAC;AAItC,OAAO,EAA+D,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAC3G,OAAO,KAAK,EAAgB,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEvH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAID,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,SAAa,GAAG,MAAM,CAE7E;AAwFD,wBAAsB,OAAO,CAAC,UAAU,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,CAkBrH;AAyFD,wBAAsB,OAAO,CAC5B,UAAU,EAAE,YAAY,EACxB,KAAK,EAAE,UAAU,EACjB,MAAM,CAAC,EAAE,WAAW,EACpB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,EAClC,eAAe,CAAC,EAAE,WAAW,GAC3B,OAAO,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC,CAmE5C;AACD,wBAAgB,OAAO,CAAC,UAAU,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAoBtG;AACD,wBAAgB,OAAO,CAAC,UAAU,EAAE,YAAY,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAmBnF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** Management only: execution and delivery belong to the session task runtime. */
|
|
2
|
+
import { runtimeLabel } from "../../../core/tasks/format.js";
|
|
3
|
+
import { boundText } from "../../../core/tasks/output.js";
|
|
4
|
+
import { isTaskTerminal, TaskLookupError, } from "../../../core/tasks/types.js";
|
|
5
|
+
import { truncateHead } from "../../../core/tools/truncate.js";
|
|
2
6
|
import { sanitizeBinaryOutput } from "../../../utils/shell.js";
|
|
3
|
-
import { runtimeLabel } from "../../tasks/format.js";
|
|
4
|
-
import { boundText } from "../../tasks/output.js";
|
|
5
|
-
import { isTaskTerminal, TaskLookupError, } from "../../tasks/types.js";
|
|
6
|
-
import { truncateHead } from "../truncate.js";
|
|
7
7
|
import { TASKS_LIST_FINISHED_SHOWN, TASKS_WAIT_DELTA_BYTES } from "./constants.js";
|
|
8
8
|
import { clampReadBytes, clampSinceBytes, clampWaitMs, requireTaskId } from "./schema.js";
|
|
9
9
|
export function boundedText(text) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../../src/extensions/tasks/tool/actions.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAGlF,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EACN,cAAc,EAC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AAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM,0BAA0B,CAAC,CAAC,CAAC,EAAE,GAAG,sBAAsB,CAAC,iBAAiB,CAAC,EAAE;QACnK,CAAC,CAAC,iFAAiF,sBAAsB,CAAC,iBAAiB,CAAC,EAAE,EAC/H;QACC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,QAAQ,EAAE,QAAQ,CAAC,MAAM;QACzB,KAAK,EAAE,KAAK,CAAC,MAAM;QACnB,MAAM;QACN,GAAG,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvD,CACD,CAAC;AACH,CAAC","sourcesContent":["/** Management only: execution and delivery belong to the session task runtime. */\n\nimport type { AgentToolResult } from \"../../../core/extensions/types.ts\";\nimport { runtimeLabel } from \"../../../core/tasks/format.ts\";\nimport { boundText } from \"../../../core/tasks/output.ts\";\nimport {\n\tisTaskTerminal,\n\tTaskLookupError,\n\ttype TaskRead,\n\ttype TaskSnapshot,\n\ttype TasksContext,\n} from \"../../../core/tasks/types.ts\";\nimport { truncateHead } from \"../../../core/tools/truncate.ts\";\nimport { sanitizeBinaryOutput } from \"../../../utils/shell.ts\";\nimport { TASKS_LIST_FINISHED_SHOWN, TASKS_WAIT_DELTA_BYTES } from \"./constants.ts\";\nimport { clampReadBytes, clampSinceBytes, clampWaitMs, requireTaskId, type TasksInput } from \"./schema.ts\";\nimport type { TasksDetails, TasksKillDetails, TasksListDetails, TasksReadDetails, TasksWaitDetails } from \"./types.ts\";\n\nexport function boundedText(text: string): string {\n\treturn truncateHead(sanitizeBinaryOutput(text), { maxBytes: 50 * 1024, maxLines: 2000 }).content;\n}\nfunction result<T extends TasksDetails>(text: string, details: T): AgentToolResult<T> {\n\treturn { content: [{ type: \"text\", text: boundedText(text) }], details };\n}\nexport function describeTaskLine(task: TaskSnapshot, now = Date.now()): string {\n\treturn `${task.id} ${task.kind} ${task.status} (${task.mode}) ${runtimeLabel(task, now)} ${task.title.slice(0, 200)}`;\n}\n\nconst LOOKUP_LIST_LIMIT = 10;\n\n/**\n * Finished rows sort most-recent first. list() is creation-ordered, so an\n * unsorted slice would surface the oldest completions rather than the recent\n * finishes a caller is most likely looking for.\n */\nfunction recentFinishedFirst(tasks: TaskSnapshot[]): TaskSnapshot[] {\n\treturn tasks.sort((left, right) => (right.endedAt ?? 0) - (left.endedAt ?? 0));\n}\n\n/**\n * Listings cover backgrounded work only; foreground executions deliver inline\n * in the transcript, so they are counted rather than shown. Every listing\n * (tasks list output and lookup-failure messages) shares this scope.\n */\nfunction listedTasks(background: TasksContext): { tasks: TaskSnapshot[]; foregroundOmitted: number } {\n\tconst all = background.list();\n\tconst tasks = all.filter((task) => task.mode === \"background\");\n\treturn { tasks, foregroundOmitted: all.length - tasks.length };\n}\n\nfunction foregroundOmissionNote(omitted: number): string {\n\treturn omitted > 0\n\t\t? `\\n${omitted} foreground ${omitted === 1 ? \"execution\" : \"executions\"} omitted — foreground work is delivered inline in the transcript.`\n\t\t: \"\";\n}\n\n/**\n * Rewrite the service's bare lookup failure into an actionable one: an\n * unknown id gets the session's current tasks (active first, then recent\n * finishes) so the next call can use a real id without a separate list call,\n * and an ambiguous prefix gets exactly the tasks it matched — including\n * records outside the current branch, which listings hide but the prefix\n * still collides with.\n */\nfunction lookupFailure(background: TasksContext, id: string, error: unknown): Error {\n\tif (!(error instanceof TaskLookupError)) return error instanceof Error ? error : new Error(String(error));\n\tif (error.kind === \"ambiguous\") {\n\t\tconst lines = error.matches.map((task) => describeTaskLine(task)).join(\"\\n\");\n\t\treturn new Error(`Ambiguous task ID \"${id}\" matches ${error.matches.length} tasks:\\n${lines}`);\n\t}\n\tconst { tasks, foregroundOmitted } = listedTasks(background);\n\tconst active = tasks.filter((task) => !isTaskTerminal(task.status));\n\tconst finished = recentFinishedFirst(tasks.filter((task) => isTaskTerminal(task.status)));\n\tconst shown = [...active, ...finished].slice(0, LOOKUP_LIST_LIMIT);\n\tif (shown.length === 0) {\n\t\treturn new Error(`No task \"${id}\" in this session. No background tasks in this session.`);\n\t}\n\tconst lines = shown.map((task) => describeTaskLine(task)).join(\"\\n\");\n\treturn new Error(\n\t\t`No task \"${id}\" in this session. IDs from other sessions are not valid here.\\nCurrent background tasks:\\n${lines}${foregroundOmissionNote(foregroundOmitted)}`,\n\t);\n}\n\n/**\n * Where this slice sits in the output, so the next wait can continue from it.\n * A wait whose new output exceeds its budget returns the newest bytes and says what it skipped.\n */\nfunction rangeText(slice: TaskRead, sinceBytes?: number): string {\n\tconst from = slice.fromByte ?? 0;\n\tconst to = from + Buffer.byteLength(slice.text);\n\tconst floor = sinceBytes === undefined || sinceBytes > slice.totalBytes ? 0 : sinceBytes;\n\treturn [\n\t\t`bytes ${from}–${to} of ${slice.totalBytes}`,\n\t\tsinceBytes !== undefined && from > floor ? `skipped ${from - floor} bytes after sinceBytes ${floor}` : \"\",\n\t\t`next sinceBytes ${to}`,\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\" · \");\n}\n\n/** Reserve space for each independent diagnostic before allowing raw output to fill the budget. */\nfunction readText(header: string, slice: TaskRead): string {\n\tconst boundedField = (text: string, maxBytes: number) =>\n\t\ttruncateHead(boundText(sanitizeBinaryOutput(text), maxBytes), { maxBytes, maxLines: 100 }).content;\n\treturn [\n\t\tboundedField(header, 4096),\n\t\tslice.task.error ? `Task error: ${boundedField(slice.task.error, 4096)}` : \"\",\n\t\tslice.readError ? `Output read error: ${boundedField(slice.readError, 4096)}` : \"\",\n\t\tboundedField(slice.task.outputPath ?? \"\", 8192),\n\t\tslice.text || \"(no output yet)\",\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\"\\n\");\n}\nexport async function runRead(background: TasksContext, input: TasksInput): Promise<AgentToolResult<TasksReadDetails>> {\n\tconst id = requireTaskId(input);\n\ttry {\n\t\tconst mode = input.mode ?? \"tail\";\n\t\tconst slice = await background.read(id, { mode, bytes: clampReadBytes(input.bytes) });\n\t\treturn result(readText(`[${describeTaskLine(slice.task)} · ${rangeText(slice)}]`, slice), {\n\t\t\taction: \"read\",\n\t\t\ttaskId: slice.task.id,\n\t\t\tmode,\n\t\t\tsliceBytes: Buffer.byteLength(slice.text),\n\t\t\ttotalBytes: slice.totalBytes,\n\t\t\toutputPath: slice.task.outputPath ?? \"\",\n\t\t\tkind: slice.task.kind,\n\t\t\tstatus: slice.task.status,\n\t\t});\n\t} catch (error) {\n\t\tthrow lookupFailure(background, id, error);\n\t}\n}\nfunction activeBackgroundTasks(background: TasksContext): TaskSnapshot[] {\n\treturn background.list().filter((task) => task.mode === \"background\" && !isTaskTerminal(task.status));\n}\n\nfunction stillRunningText(tasks: TaskSnapshot[]): string {\n\treturn tasks.length > 0 ? `\\n\\n[still_running]\\n${tasks.map((task) => describeTaskLine(task)).join(\"\\n\")}` : \"\";\n}\n\nfunction emptyWaitDetails(\n\toutcome: \"interrupted\" | \"timed_out\" | \"no_tasks\",\n\twaitedMs: number,\n\trunning: number,\n): TasksWaitDetails {\n\treturn {\n\t\taction: \"wait\",\n\t\toutcome,\n\t\ttimedOut: outcome === \"timed_out\",\n\t\texitCode: undefined,\n\t\twaitedMs,\n\t\tdeltaBytes: 0,\n\t\ttotalBytes: 0,\n\t\tdeltaTruncated: false,\n\t\toutputPath: \"\",\n\t\trunning,\n\t};\n}\n\nasync function runWaitAny(\n\tbackground: TasksContext,\n\tinput: TasksInput,\n\tsignal?: AbortSignal,\n\tonReady?: (taskId: string) => void,\n\tinterruptSignal?: AbortSignal,\n): Promise<AgentToolResult<TasksWaitDetails>> {\n\tconst candidates = activeBackgroundTasks(background);\n\tif (candidates.length === 0) {\n\t\treturn result(\n\t\t\t\"No background tasks are running, so there is nothing to wait for. Finished tasks report back via automatic notification.\",\n\t\t\temptyWaitDetails(\"no_tasks\", 0, 0),\n\t\t);\n\t}\n\t// Holds cover the whole initial cohort until the winning result is ready for\n\t// persistence. Other completed tasks resume ordinary notification delivery on release.\n\tconst releases = candidates.map((task) => background.holdDelivery(task.id));\n\tconst start = Date.now();\n\ttry {\n\t\tconst task = await background.waitAny(clampWaitMs(input.waitMs), signal, interruptSignal);\n\t\tconst ids = new Set(candidates.map((candidate) => candidate.id));\n\t\tconst running = activeBackgroundTasks(background).filter((candidate) => ids.has(candidate.id));\n\t\tif (!task) {\n\t\t\tconst interrupted = !background.closed && interruptSignal?.aborted === true;\n\t\t\tconst outcome = interrupted ? \"interrupted\" : \"timed_out\";\n\t\t\tconst note = background.closed\n\t\t\t\t? \"The host closed; execution state is unconfirmed.\"\n\t\t\t\t: interrupted\n\t\t\t\t\t? \"New steering input ended this wait early. Read the new input before deciding what to do next; no task was stopped.\"\n\t\t\t\t\t: \"The wait window expired; running tasks continue. Prefer other work over waiting again.\";\n\t\t\treturn result(\n\t\t\t\t`${note}${stillRunningText(running)}`,\n\t\t\t\temptyWaitDetails(outcome, Date.now() - start, running.length),\n\t\t\t);\n\t\t}\n\t\tconst slice = await background.read(task.id, { bytes: TASKS_WAIT_DELTA_BYTES });\n\t\tsignal?.throwIfAborted();\n\t\tonReady?.(task.id);\n\t\treturn result(\n\t\t\t`${readText(`[${describeTaskLine(task)} · waitAny settled · ${rangeText(slice)}]`, slice)}${stillRunningText(running)}`,\n\t\t\t{\n\t\t\t\taction: \"wait\",\n\t\t\t\toutcome: \"settled\",\n\t\t\t\ttaskId: task.id,\n\t\t\t\tstatus: task.status,\n\t\t\t\tkind: task.kind,\n\t\t\t\ttimedOut: false,\n\t\t\t\texitCode: task.exitCode,\n\t\t\t\twaitedMs: Date.now() - start,\n\t\t\t\tdeltaBytes: Buffer.byteLength(slice.text),\n\t\t\t\ttotalBytes: slice.totalBytes,\n\t\t\t\tdeltaTruncated: slice.truncated,\n\t\t\t\toutputPath: task.outputPath ?? \"\",\n\t\t\t\trunning: running.length,\n\t\t\t},\n\t\t);\n\t} finally {\n\t\tfor (const release of releases) release();\n\t}\n}\n\nexport async function runWait(\n\tbackground: TasksContext,\n\tinput: TasksInput,\n\tsignal?: AbortSignal,\n\tonReady?: (taskId: string) => void,\n\tinterruptSignal?: AbortSignal,\n): Promise<AgentToolResult<TasksWaitDetails>> {\n\tif (!input.taskId?.trim()) {\n\t\tif (input.sinceBytes !== undefined)\n\t\t\tthrow new Error(\"action 'wait' without 'taskId' does not accept 'sinceBytes'; offsets belong to one task.\");\n\t\treturn runWaitAny(background, input, signal, onReady, interruptSignal);\n\t}\n\tconst id = requireTaskId(input);\n\ttry {\n\t\tconst release = background.holdDelivery(id);\n\t\ttry {\n\t\t\tconst start = Date.now();\n\t\t\tconst task = await background.wait(id, clampWaitMs(input.waitMs), signal, interruptSignal);\n\t\t\tconst settled = isTaskTerminal(task.status);\n\t\t\tconst interrupted = !settled && !background.closed && interruptSignal?.aborted === true;\n\t\t\tconst timedOut = !settled && !interrupted;\n\t\t\tconst outcome = settled ? \"settled\" : interrupted ? \"interrupted\" : \"timed_out\";\n\t\t\tconst waitedMs = Date.now() - start;\n\t\t\tif (interrupted) {\n\t\t\t\treturn result(\n\t\t\t\t\t`[${describeTaskLine(task)} · interrupted by steering; execution continues]\\nRead the new input before deciding whether to wait again; the task was not stopped.`,\n\t\t\t\t\t{\n\t\t\t\t\t\taction: \"wait\",\n\t\t\t\t\t\toutcome,\n\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\tstatus: task.status,\n\t\t\t\t\t\tkind: task.kind,\n\t\t\t\t\t\ttimedOut: false,\n\t\t\t\t\t\texitCode: task.exitCode,\n\t\t\t\t\t\twaitedMs,\n\t\t\t\t\t\tdeltaBytes: 0,\n\t\t\t\t\t\ttotalBytes: 0,\n\t\t\t\t\t\tdeltaTruncated: false,\n\t\t\t\t\t\toutputPath: task.outputPath ?? \"\",\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t\t// A closed host resolves waits early without settling anything; do not claim\n\t\t\t// the execution merely outlived the wait window.\n\t\t\tconst windowNote = background.closed\n\t\t\t\t? \" · host closed; execution state unconfirmed\"\n\t\t\t\t: timedOut\n\t\t\t\t\t? \" · wait window expired; execution continues\"\n\t\t\t\t\t: \"\";\n\t\t\tconst sinceBytes = clampSinceBytes(input.sinceBytes);\n\t\t\tconst slice = await background.read(id, { bytes: TASKS_WAIT_DELTA_BYTES, sinceBytes });\n\t\t\tsignal?.throwIfAborted();\n\t\t\tif (settled) onReady?.(task.id);\n\t\t\treturn result(readText(`[${describeTaskLine(task)}${windowNote} · ${rangeText(slice, sinceBytes)}]`, slice), {\n\t\t\t\taction: \"wait\",\n\t\t\t\toutcome,\n\t\t\t\ttaskId: task.id,\n\t\t\t\tstatus: task.status,\n\t\t\t\tkind: task.kind,\n\t\t\t\ttimedOut,\n\t\t\t\texitCode: task.exitCode,\n\t\t\t\twaitedMs,\n\t\t\t\tdeltaBytes: Buffer.byteLength(slice.text),\n\t\t\t\ttotalBytes: slice.totalBytes,\n\t\t\t\tdeltaTruncated: slice.truncated,\n\t\t\t\toutputPath: task.outputPath ?? \"\",\n\t\t\t});\n\t\t} finally {\n\t\t\trelease();\n\t\t}\n\t} catch (error) {\n\t\tthrow lookupFailure(background, id, error);\n\t}\n}\nexport function runKill(background: TasksContext, input: TasksInput): AgentToolResult<TasksKillDetails> {\n\tconst id = requireTaskId(input);\n\ttry {\n\t\tconst task = background.get(id);\n\t\tconst requested = background.kill(task.id);\n\t\treturn result(\n\t\t\trequested\n\t\t\t\t? `Cancellation requested for ${task.id}. The task or whole group is stopping; cleanup may still be in progress.`\n\t\t\t\t: `No new cancellation requested for ${task.id} (${background.get(task.id).status}).`,\n\t\t\t{\n\t\t\t\taction: \"kill\",\n\t\t\t\ttaskId: task.id,\n\t\t\t\tcommand: task.command ?? task.title,\n\t\t\t\trequested,\n\t\t\t\tstatus: background.get(task.id).status,\n\t\t\t},\n\t\t);\n\t} catch (error) {\n\t\tthrow lookupFailure(background, id, error);\n\t}\n}\nexport function runList(background: TasksContext): AgentToolResult<TasksListDetails> {\n\tconst { tasks, foregroundOmitted } = listedTasks(background);\n\tconst active = tasks.filter((task) => !isTaskTerminal(task.status));\n\tconst finished = recentFinishedFirst(tasks.filter((task) => isTaskTerminal(task.status)));\n\tconst shown = [...active, ...finished.slice(0, TASKS_LIST_FINISHED_SHOWN)].slice(0, 100);\n\tconst hidden = tasks.length - shown.length;\n\treturn result(\n\t\tshown.length\n\t\t\t? `${shown.map((task) => describeTaskLine(task)).join(\"\\n\")}${hidden > 0 ? `\\n${hidden} more records not shown.` : \"\"}${foregroundOmissionNote(foregroundOmitted)}`\n\t\t\t: `No background tasks. Start work through its owning tool with background: true.${foregroundOmissionNote(foregroundOmitted)}`,\n\t\t{\n\t\t\taction: \"list\",\n\t\t\trunning: active.length,\n\t\t\tfinished: finished.length,\n\t\t\tshown: shown.length,\n\t\t\thidden,\n\t\t\t...(foregroundOmitted > 0 ? { foregroundOmitted } : {}),\n\t\t},\n\t);\n}\n"]}
|
|
@@ -12,9 +12,7 @@ export declare const TASKS_LIST_FINISHED_SHOWN = 5;
|
|
|
12
12
|
/** Bounded output delta returned by a successful wait. */
|
|
13
13
|
export declare const TASKS_WAIT_DELTA_BYTES: number;
|
|
14
14
|
/** Wait-window bounds shared by execution and the pending-call renderer. */
|
|
15
|
-
export
|
|
16
|
-
export declare const TASKS_WAIT_MIN_MS = 1000;
|
|
17
|
-
export declare const TASKS_WAIT_MAX_MS = 60000;
|
|
15
|
+
export { TASKS_WAIT_DEFAULT_MS, TASKS_WAIT_MAX_MS, TASKS_WAIT_MIN_MS } from "../../../core/tasks/limits.ts";
|
|
18
16
|
/** How long a foreground execution runs before the statusline advertises the detach key. */
|
|
19
17
|
export declare const TASKS_DETACH_HINT_DELAY_MS = 10000;
|
|
20
18
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/extensions/tasks/tool/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,yFAAyF;AACzF,eAAO,MAAM,wBAAwB,QAAW,CAAC;AACjD,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,wEAAwE;AACxE,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C,0DAA0D;AAC1D,eAAO,MAAM,sBAAsB,QAAY,CAAC;AAEhD,4EAA4E;AAC5E,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAE5G,4FAA4F;AAC5F,eAAO,MAAM,0BAA0B,QAAS,CAAC"}
|
|
@@ -12,9 +12,7 @@ export const TASKS_LIST_FINISHED_SHOWN = 5;
|
|
|
12
12
|
/** Bounded output delta returned by a successful wait. */
|
|
13
13
|
export const TASKS_WAIT_DELTA_BYTES = 32 * 1024;
|
|
14
14
|
/** Wait-window bounds shared by execution and the pending-call renderer. */
|
|
15
|
-
export
|
|
16
|
-
export const TASKS_WAIT_MIN_MS = 1_000;
|
|
17
|
-
export const TASKS_WAIT_MAX_MS = 60_000;
|
|
15
|
+
export { TASKS_WAIT_DEFAULT_MS, TASKS_WAIT_MAX_MS, TASKS_WAIT_MIN_MS } from "../../../core/tasks/limits.js";
|
|
18
16
|
/** How long a foreground execution runs before the statusline advertises the detach key. */
|
|
19
17
|
export const TASKS_DETACH_HINT_DELAY_MS = 10_000;
|
|
20
18
|
//# sourceMappingURL=constants.js.map
|