@toddzheng024/dscode-bundle 0.1.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/LICENSE +21 -0
- package/README.md +5 -0
- package/THIRD_PARTY_NOTICES.md +11 -0
- package/bin/apply_patch +4 -0
- package/bootstrap.mjs +21 -0
- package/cordis.patch.yml +756 -0
- package/package.json +327 -0
- package/plugins/auto-review/audit.mjs +20 -0
- package/plugins/auto-review/index.mjs +181 -0
- package/plugins/auto-review/policy.mjs +59 -0
- package/plugins/dscode/index.mjs +35 -0
- package/plugins/session-metrics/index.mjs +44 -0
- package/plugins/session-metrics/pricing.mjs +18 -0
- package/plugins/session-metrics/store.mjs +24 -0
- package/plugins/session-metrics/view.mjs +58 -0
- package/plugins/tui-tools/hooks.mjs +23 -0
- package/plugins/tui-tools/index.mjs +164 -0
- package/plugins/ultra/policy.mjs +11 -0
- package/presets/dscode/agent.cordis.yml +288 -0
- package/presets/dscode/preset.yml +3 -0
- package/vendor/bash/LICENSE +21 -0
- package/vendor/bash/index.js +449 -0
- package/vendor/bash/types/background.d.ts +19 -0
- package/vendor/bash/types/index.d.ts +22 -0
- package/vendor/bash/types/render.d.ts +38 -0
- package/vendor/deepseek/LICENSE +21 -0
- package/vendor/deepseek/index.js +2102 -0
- package/vendor/deepseek/types/adapter.d.ts +163 -0
- package/vendor/deepseek/types/file-id.d.ts +19 -0
- package/vendor/deepseek/types/file-store.d.ts +83 -0
- package/vendor/deepseek/types/files-api.d.ts +103 -0
- package/vendor/deepseek/types/image-tokens.d.ts +19 -0
- package/vendor/deepseek/types/index.d.ts +106 -0
- package/vendor/deepseek/types/request-pricing.d.ts +48 -0
- package/vendor/deepseek/types/serialize.d.ts +85 -0
- package/vendor/deepseek/types/sse.d.ts +24 -0
- package/vendor/deepseek/types/translate.d.ts +37 -0
- package/vendor/deepseek/types/types.d.ts +178 -0
- package/vendor/deepseek/types/upload-index.d.ts +68 -0
- package/vendor/persistent/LICENSE +21 -0
- package/vendor/persistent/index.js +386 -0
- package/vendor/persistent/types/index.d.ts +24 -0
- package/vendor/tui/LICENSE +21 -0
- package/vendor/tui/devtools-CdTl3MNy.mjs +3643 -0
- package/vendor/tui/index.mjs +39105 -0
- package/vendor/tui/invariant.mjs +21 -0
- package/vendor/tui/rolldown-runtime-CMFfr-1z.mjs +26 -0
- package/vendor/tui/startup.mjs +109 -0
- package/vendor/tui/theme-DCT8Y2xf.mjs +628 -0
- package/vendor/tui/types/app.d.ts +304 -0
- package/vendor/tui/types/approval.d.ts +59 -0
- package/vendor/tui/types/attachments.d.ts +52 -0
- package/vendor/tui/types/authorization-panel.d.ts +22 -0
- package/vendor/tui/types/authorization.d.ts +36 -0
- package/vendor/tui/types/commands.d.ts +52 -0
- package/vendor/tui/types/editor-keys.d.ts +105 -0
- package/vendor/tui/types/editor.d.ts +6 -0
- package/vendor/tui/types/fork.d.ts +8 -0
- package/vendor/tui/types/git-workflow.d.ts +32 -0
- package/vendor/tui/types/history.d.ts +97 -0
- package/vendor/tui/types/index.d.ts +124 -0
- package/vendor/tui/types/input-split.d.ts +54 -0
- package/vendor/tui/types/internals.d.ts +26 -0
- package/vendor/tui/types/invariant.d.ts +15 -0
- package/vendor/tui/types/kernel-panels.d.ts +167 -0
- package/vendor/tui/types/keyboard.d.ts +80 -0
- package/vendor/tui/types/mentions.d.ts +81 -0
- package/vendor/tui/types/model-capabilities.d.ts +82 -0
- package/vendor/tui/types/models.d.ts +119 -0
- package/vendor/tui/types/permissions.d.ts +27 -0
- package/vendor/tui/types/plugin-inventory.d.ts +11 -0
- package/vendor/tui/types/presets.d.ts +22 -0
- package/vendor/tui/types/provider-settings.d.ts +239 -0
- package/vendor/tui/types/questions.d.ts +54 -0
- package/vendor/tui/types/render/animations.d.ts +265 -0
- package/vendor/tui/types/render/editor.d.ts +162 -0
- package/vendor/tui/types/render/export.d.ts +9 -0
- package/vendor/tui/types/render/fuzzy.d.ts +21 -0
- package/vendor/tui/types/render/inspector.d.ts +36 -0
- package/vendor/tui/types/render/lines.d.ts +66 -0
- package/vendor/tui/types/render/markdown.d.ts +29 -0
- package/vendor/tui/types/render/projection.d.ts +461 -0
- package/vendor/tui/types/render/status.d.ts +196 -0
- package/vendor/tui/types/render/text.d.ts +58 -0
- package/vendor/tui/types/render/tool-detail.d.ts +94 -0
- package/vendor/tui/types/render/tool-preview.d.ts +28 -0
- package/vendor/tui/types/render/width.d.ts +29 -0
- package/vendor/tui/types/session-directory.d.ts +173 -0
- package/vendor/tui/types/session-switch.d.ts +17 -0
- package/vendor/tui/types/settings-file.d.ts +41 -0
- package/vendor/tui/types/skills.d.ts +47 -0
- package/vendor/tui/types/startup.d.ts +65 -0
- package/vendor/tui/types/store.d.ts +58 -0
- package/vendor/tui/types/subagents.d.ts +70 -0
- package/vendor/tui/types/theme-panel.d.ts +24 -0
- package/vendor/tui/types/theme.d.ts +215 -0
- package/vendor/tui/types/version.d.ts +18 -0
- package/vendor/tui/types/whale-glyph.d.ts +6 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
// dscode-shell-reset-v1
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import z from "@deepseek-ai/schemastery";
|
|
4
|
+
import { deadline, timeoutOf } from "@deepseek-ai/dsh-timeout";
|
|
5
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
6
|
+
//#region lib/types/index.js
|
|
7
|
+
/**
|
|
8
|
+
* Model-facing persistent `bash` tool over the owner-scoped PTY seam.
|
|
9
|
+
* @module @deepseek-ai/dsh-tool-bash-persistent
|
|
10
|
+
*/
|
|
11
|
+
var __addDisposableResource = function(env, value, async) {
|
|
12
|
+
if (value !== null && value !== void 0) {
|
|
13
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
14
|
+
var dispose, inner;
|
|
15
|
+
if (async) {
|
|
16
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
17
|
+
dispose = value[Symbol.asyncDispose];
|
|
18
|
+
}
|
|
19
|
+
if (dispose === void 0) {
|
|
20
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
21
|
+
dispose = value[Symbol.dispose];
|
|
22
|
+
if (async) inner = dispose;
|
|
23
|
+
}
|
|
24
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
25
|
+
if (inner) dispose = function() {
|
|
26
|
+
try {
|
|
27
|
+
inner.call(this);
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return Promise.reject(e);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
env.stack.push({
|
|
33
|
+
value,
|
|
34
|
+
dispose,
|
|
35
|
+
async
|
|
36
|
+
});
|
|
37
|
+
} else if (async) env.stack.push({ async: true });
|
|
38
|
+
return value;
|
|
39
|
+
};
|
|
40
|
+
var __disposeResources = (function(SuppressedError) {
|
|
41
|
+
return function(env) {
|
|
42
|
+
function fail(e) {
|
|
43
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
44
|
+
env.hasError = true;
|
|
45
|
+
}
|
|
46
|
+
var r, s = 0;
|
|
47
|
+
function next() {
|
|
48
|
+
while (r = env.stack.pop()) try {
|
|
49
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
50
|
+
if (r.dispose) {
|
|
51
|
+
var result = r.dispose.call(r.value);
|
|
52
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
53
|
+
fail(e);
|
|
54
|
+
return next();
|
|
55
|
+
});
|
|
56
|
+
} else s |= 1;
|
|
57
|
+
} catch (e) {
|
|
58
|
+
fail(e);
|
|
59
|
+
}
|
|
60
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
61
|
+
if (env.hasError) throw env.error;
|
|
62
|
+
}
|
|
63
|
+
return next();
|
|
64
|
+
};
|
|
65
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
|
|
66
|
+
var e = new Error(message);
|
|
67
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
68
|
+
});
|
|
69
|
+
const TRUNCATED_MESSAGE = "<response clipped><NOTE>To save on context only part of this file has been shown to you. You should retry this tool after you have searched inside the file with `grep -n` in order to find the line numbers of what you are looking for.</NOTE>";
|
|
70
|
+
const LOST_PREFIX_MESSAGE = "<response clipped><NOTE>The beginning of this command output was dropped by the terminal scrollback limit. The following text is the earliest retained output.</NOTE>\n";
|
|
71
|
+
const SHELL_RESET_MESSAGE = "The persistent bash shell was reset; the next bash call starts from the workspace with a fresh current directory and environment.";
|
|
72
|
+
const TIMEOUT_STATUS_MARKER = "[Command timed out or OOM]";
|
|
73
|
+
const TIMEOUT_CODE = "PERSISTENT_BASH_TIMEOUT";
|
|
74
|
+
const SCROLLBACK_PAGE_LINES = 1e3;
|
|
75
|
+
const POLL_INTERVAL_MS = 25;
|
|
76
|
+
const DEFAULT_DESCRIPTION = "Run commands in a persistent bash shell. State, including the current directory and exported environment variables, persists across calls for this agent.";
|
|
77
|
+
function maybeTruncate(content, maxOutputChars, incomplete = false) {
|
|
78
|
+
if (content.length <= maxOutputChars && !incomplete) return content;
|
|
79
|
+
return content.length <= maxOutputChars ? content + TRUNCATED_MESSAGE : content.slice(0, maxOutputChars) + TRUNCATED_MESSAGE;
|
|
80
|
+
}
|
|
81
|
+
function markers() {
|
|
82
|
+
const nonce = randomUUID();
|
|
83
|
+
return {
|
|
84
|
+
start: `__DSH_PERSISTENT_BASH_START_${nonce}__`,
|
|
85
|
+
end: `__DSH_PERSISTENT_BASH_END_${nonce}:`
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function quoteForBash(value) {
|
|
89
|
+
return `$'${value.replaceAll("\\", "\\\\").replaceAll("'", "\\'").replaceAll("\r", "\\r").replaceAll("\n", "\\n")}'`;
|
|
90
|
+
}
|
|
91
|
+
function wrapCommand(command, marker) {
|
|
92
|
+
return `printf '%s\\n' ${quoteForBash(marker.start)}; eval -- ${quoteForBash(command)}; __dsh_persistent_bash_status=$?; printf '%s%s\\n' ${quoteForBash(marker.end)} "$__dsh_persistent_bash_status"`;
|
|
93
|
+
}
|
|
94
|
+
function trimTrailingNewline(text) {
|
|
95
|
+
return text.replace(/(?:\r?\n)+$/, "");
|
|
96
|
+
}
|
|
97
|
+
function commandOutput(snapshot, marker) {
|
|
98
|
+
const text = snapshot.text;
|
|
99
|
+
const end = text.lastIndexOf(marker.end);
|
|
100
|
+
const status = /^(\d+)\r?\n/.exec(text.slice(end + marker.end.length))?.[1];
|
|
101
|
+
if (status === void 0) return void 0;
|
|
102
|
+
const startMarker = text.lastIndexOf(marker.start, end);
|
|
103
|
+
const start = startMarker < 0 ? 0 : startMarker + marker.start.length;
|
|
104
|
+
return {
|
|
105
|
+
text: trimTrailingNewline(text.slice(start, end).replace(/^\r?\n/, "")),
|
|
106
|
+
incomplete: startMarker < 0,
|
|
107
|
+
exitCode: Number(status)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function partialOutput(snapshot, marker, fallback, fallbackTruncated = false) {
|
|
111
|
+
const startMarker = snapshot.text.lastIndexOf(marker.start);
|
|
112
|
+
if (startMarker >= 0) return {
|
|
113
|
+
text: trimTrailingNewline(snapshot.text.slice(startMarker + marker.start.length).replace(/^\r?\n/, "")),
|
|
114
|
+
incomplete: false
|
|
115
|
+
};
|
|
116
|
+
const fallbackStart = fallback.lastIndexOf(marker.start);
|
|
117
|
+
const afterStart = fallbackStart < 0 ? fallback : fallback.slice(fallbackStart + marker.start.length).replace(/^\r?\n/, "");
|
|
118
|
+
const fallbackEnd = afterStart.lastIndexOf(marker.end);
|
|
119
|
+
return {
|
|
120
|
+
text: trimTrailingNewline(fallbackEnd < 0 ? afterStart : afterStart.slice(0, fallbackEnd)),
|
|
121
|
+
incomplete: fallbackTruncated || fallbackStart < 0
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
async function pause() {
|
|
125
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
126
|
+
}
|
|
127
|
+
function nextScrollbackOffset(page, offset) {
|
|
128
|
+
if (page.text.length === 0 || page.lineEnd <= offset) return void 0;
|
|
129
|
+
return page.lineEnd;
|
|
130
|
+
}
|
|
131
|
+
function retainedScrollback(ctx, owner, id, latest = ctx.terminals.read(owner, id, {
|
|
132
|
+
offset: 0,
|
|
133
|
+
count: SCROLLBACK_PAGE_LINES
|
|
134
|
+
})) {
|
|
135
|
+
const pages = latest.text.length === 0 ? [] : [latest.text];
|
|
136
|
+
let offset = latest.lineEnd;
|
|
137
|
+
let truncated = latest.truncated;
|
|
138
|
+
while (true) {
|
|
139
|
+
if (offset >= latest.totalLines) break;
|
|
140
|
+
const page = ctx.terminals.read(owner, id, {
|
|
141
|
+
offset,
|
|
142
|
+
count: SCROLLBACK_PAGE_LINES
|
|
143
|
+
});
|
|
144
|
+
truncated ||= page.truncated;
|
|
145
|
+
if (page.text.length > 0) pages.unshift(page.text);
|
|
146
|
+
const next = nextScrollbackOffset(page, offset);
|
|
147
|
+
if (next === void 0 || next >= page.totalLines) break;
|
|
148
|
+
offset = next;
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
text: pages.join("\n"),
|
|
152
|
+
truncated
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function renderCaptured(output, maxOutputChars) {
|
|
156
|
+
const rendered = maybeTruncate(output.text, maxOutputChars, output.incomplete);
|
|
157
|
+
return appendStatusMarker(output.incomplete && output.text.length > 0 ? LOST_PREFIX_MESSAGE + rendered : rendered, output.exitCode !== void 0 ? `[Command finished with exit code ${output.exitCode}]` : void 0);
|
|
158
|
+
}
|
|
159
|
+
function appendStatusMarker(content, marker) {
|
|
160
|
+
if (marker === void 0) return content;
|
|
161
|
+
return content.length === 0 ? marker : `${content}\n${marker}`;
|
|
162
|
+
}
|
|
163
|
+
function renderShellExitStatus(content, exitCode, signal) {
|
|
164
|
+
return appendStatusMarker(content, signal !== null ? `[shell killed by signal: ${signal}]` : exitCode !== null ? `[shell exited: code ${exitCode}]` : "[shell exited]");
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Render the exited-session result, reset the owner's shell, and reset the
|
|
168
|
+
* message that tells the model the next call starts fresh.
|
|
169
|
+
* @param shells - the owner-scoped registry to reset.
|
|
170
|
+
* @param status - the exited session status (exit code and signal).
|
|
171
|
+
* @returns the complete model-facing result.
|
|
172
|
+
*/
|
|
173
|
+
async function respondToSessionExit(ctx, shells, owner, id, status, marker, fallback, fallbackTruncated, config) {
|
|
174
|
+
const snapshot = retainedScrollback(ctx, owner, id);
|
|
175
|
+
await shells.reset(owner, "persistent bash shell exited");
|
|
176
|
+
return [renderShellExitStatus(renderCaptured(partialOutput(snapshot, marker, fallback, fallbackTruncated), config.maxOutputChars), status.exitCode, status.signal), SHELL_RESET_MESSAGE].filter((part) => part.length > 0).join("\n");
|
|
177
|
+
}
|
|
178
|
+
function persistentShells(ctx, config) {
|
|
179
|
+
const pending = /* @__PURE__ */ new WeakMap();
|
|
180
|
+
const live = /* @__PURE__ */ new Map();
|
|
181
|
+
const creating = /* @__PURE__ */ new Set();
|
|
182
|
+
const ownerCleanupInstalled = /* @__PURE__ */ new WeakSet();
|
|
183
|
+
const lifecycle = new AbortController();
|
|
184
|
+
const close = async (owner, id, reason) => {
|
|
185
|
+
if (!ctx.terminals.list(owner).some((snapshot) => snapshot.sessionId === id)) return;
|
|
186
|
+
await ctx.terminals.kill(owner, id, reason);
|
|
187
|
+
};
|
|
188
|
+
ctx.effect(() => async () => {
|
|
189
|
+
lifecycle.abort(/* @__PURE__ */ new Error("tool-bash-persistent disposed during shell creation"));
|
|
190
|
+
await Promise.allSettled([...creating]);
|
|
191
|
+
const closing = [...live].map(async ([owner, id]) => {
|
|
192
|
+
await close(owner, id, "tool-bash-persistent disposed");
|
|
193
|
+
});
|
|
194
|
+
await Promise.all(closing);
|
|
195
|
+
live.clear();
|
|
196
|
+
}, "tool-bash-persistent shell cleanup");
|
|
197
|
+
const reset = async (owner, reason) => {
|
|
198
|
+
pending.delete(owner);
|
|
199
|
+
const id = live.get(owner);
|
|
200
|
+
live.delete(owner);
|
|
201
|
+
if (id !== void 0) await close(owner, id, reason);
|
|
202
|
+
};
|
|
203
|
+
const get = (owner, signal) => {
|
|
204
|
+
const liveId = live.get(owner);
|
|
205
|
+
if (liveId !== undefined && !ctx.terminals.list(owner).some(s => s.sessionId === liveId && s.status.kind !== "exited")) { pending.delete(owner); live.delete(owner); }
|
|
206
|
+
const existing = pending.get(owner);
|
|
207
|
+
if (existing !== void 0) return existing;
|
|
208
|
+
const combinedSignal = AbortSignal.any([signal, lifecycle.signal]);
|
|
209
|
+
const tracked = (async () => {
|
|
210
|
+
try {
|
|
211
|
+
const cwd = owner.session.header.cwd;
|
|
212
|
+
const spawned = await ctx.terminals.spawn(owner, {
|
|
213
|
+
type: config.backendType,
|
|
214
|
+
...cwd === void 0 ? {} : { cwd }
|
|
215
|
+
}, combinedSignal);
|
|
216
|
+
live.set(owner, spawned.sessionId);
|
|
217
|
+
if (!ownerCleanupInstalled.has(owner)) {
|
|
218
|
+
ownerCleanupInstalled.add(owner);
|
|
219
|
+
owner.ctx.effect(() => () => {
|
|
220
|
+
pending.delete(owner);
|
|
221
|
+
live.delete(owner);
|
|
222
|
+
}, "tool-bash-persistent owner cache cleanup");
|
|
223
|
+
}
|
|
224
|
+
const result = await ctx.terminals.startSend(owner, spawned.sessionId, {
|
|
225
|
+
text: "stty -echo",
|
|
226
|
+
submit: true,
|
|
227
|
+
signal: combinedSignal
|
|
228
|
+
}).done;
|
|
229
|
+
if (result.sessionStatus.kind === "exited" || result.waitReason === "timeout") throw new Error("persistent bash shell did not accept initialization");
|
|
230
|
+
return spawned.sessionId;
|
|
231
|
+
} catch (error) {
|
|
232
|
+
await reset(owner, "persistent bash initialization failed");
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
})().finally(() => {
|
|
236
|
+
creating.delete(tracked);
|
|
237
|
+
});
|
|
238
|
+
creating.add(tracked);
|
|
239
|
+
pending.set(owner, tracked);
|
|
240
|
+
return tracked;
|
|
241
|
+
};
|
|
242
|
+
return {
|
|
243
|
+
get,
|
|
244
|
+
reset
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
async function executeCommand(ctx, shells, owner, command, config, upstream) {
|
|
248
|
+
const env_1 = {
|
|
249
|
+
stack: [],
|
|
250
|
+
error: void 0,
|
|
251
|
+
hasError: false
|
|
252
|
+
};
|
|
253
|
+
try {
|
|
254
|
+
const commandDeadline = __addDisposableResource(env_1, deadline(upstream, config.timeoutMs, TIMEOUT_CODE), false);
|
|
255
|
+
const id = await shells.get(owner, commandDeadline.signal);
|
|
256
|
+
const marker = markers();
|
|
257
|
+
const wrapped = wrapCommand(command, marker);
|
|
258
|
+
let first = true;
|
|
259
|
+
let fallback = "";
|
|
260
|
+
let fallbackTruncated = false;
|
|
261
|
+
while (true) {
|
|
262
|
+
const status = ctx.terminals.list(owner).find((session) => session.sessionId === id)?.status;
|
|
263
|
+
if (status?.kind === "exited") return await respondToSessionExit(ctx, shells, owner, id, status, marker, fallback, fallbackTruncated, config);
|
|
264
|
+
let operation;
|
|
265
|
+
let result;
|
|
266
|
+
try {
|
|
267
|
+
operation = ctx.terminals.startSend(owner, id, {
|
|
268
|
+
text: first ? wrapped : "",
|
|
269
|
+
submit: first,
|
|
270
|
+
signal: commandDeadline.signal
|
|
271
|
+
});
|
|
272
|
+
first = false;
|
|
273
|
+
result = await operation.done;
|
|
274
|
+
} catch (error) {
|
|
275
|
+
await shells.reset(owner, "persistent bash send failed");
|
|
276
|
+
throw error;
|
|
277
|
+
}
|
|
278
|
+
const incremental = operation.readOutput();
|
|
279
|
+
fallback = incremental.delta.length > 0 ? fallback + incremental.delta : result.viewport;
|
|
280
|
+
fallbackTruncated ||= incremental.truncated || result.truncated;
|
|
281
|
+
const latest = ctx.terminals.read(owner, id, {
|
|
282
|
+
offset: 0,
|
|
283
|
+
count: SCROLLBACK_PAGE_LINES
|
|
284
|
+
});
|
|
285
|
+
const timedOut = timeoutOf(commandDeadline.signal, TIMEOUT_CODE);
|
|
286
|
+
if (timedOut !== void 0) {
|
|
287
|
+
const partial = renderCaptured(partialOutput(retainedScrollback(ctx, owner, id, latest), marker, fallback, fallbackTruncated), config.maxOutputChars);
|
|
288
|
+
await shells.reset(owner, "persistent bash command timed out");
|
|
289
|
+
return [
|
|
290
|
+
`Your command timed out after ${Math.round(timedOut.timeoutMs / 1e3)} seconds or experienced an OOM error. Below is partial output:`,
|
|
291
|
+
appendStatusMarker(partial, TIMEOUT_STATUS_MARKER),
|
|
292
|
+
SHELL_RESET_MESSAGE
|
|
293
|
+
].join("\n");
|
|
294
|
+
}
|
|
295
|
+
if (commandDeadline.signal.aborted) {
|
|
296
|
+
await shells.reset(owner, "persistent bash command aborted");
|
|
297
|
+
commandDeadline.signal.throwIfAborted();
|
|
298
|
+
}
|
|
299
|
+
if (latest.text.includes(marker.end)) {
|
|
300
|
+
const complete = commandOutput(retainedScrollback(ctx, owner, id, latest), marker);
|
|
301
|
+
if (complete !== void 0) return renderCaptured(complete, config.maxOutputChars);
|
|
302
|
+
}
|
|
303
|
+
if (result.sessionStatus.kind === "exited") return await respondToSessionExit(ctx, shells, owner, id, result.sessionStatus, marker, fallback, fallbackTruncated, config);
|
|
304
|
+
if (result.waitReason === "stdin_read") return renderCaptured(partialOutput(retainedScrollback(ctx, owner, id, latest), marker, fallback, fallbackTruncated), config.maxOutputChars);
|
|
305
|
+
await pause();
|
|
306
|
+
}
|
|
307
|
+
} catch (e_1) {
|
|
308
|
+
env_1.error = e_1;
|
|
309
|
+
env_1.hasError = true;
|
|
310
|
+
} finally {
|
|
311
|
+
__disposeResources(env_1);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Register the model-facing persistent `bash` tool.
|
|
316
|
+
* @param ctx - plugin context carrying tools and the owner-scoped PTY service.
|
|
317
|
+
* @param config - selected PTY backend and command deadline.
|
|
318
|
+
*/
|
|
319
|
+
function registerPersistentBash(ctx, config) {
|
|
320
|
+
const shells = persistentShells(ctx, config);
|
|
321
|
+
const queues = /* @__PURE__ */ new WeakMap();
|
|
322
|
+
const serialized = async (owner, operation) => {
|
|
323
|
+
const run = (queues.get(owner) ?? Promise.resolve()).then(operation, operation);
|
|
324
|
+
const tail = run.then(() => void 0, () => void 0);
|
|
325
|
+
queues.set(owner, tail);
|
|
326
|
+
try {
|
|
327
|
+
return await run;
|
|
328
|
+
} finally {
|
|
329
|
+
if (queues.get(owner) === tail) queues.delete(owner);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
ctx.tools.register(defineTool({
|
|
333
|
+
name: "bash",
|
|
334
|
+
description: config.description,
|
|
335
|
+
parameters: { command: {
|
|
336
|
+
type: "string",
|
|
337
|
+
required: true,
|
|
338
|
+
description: "The bash command to run. Relative path is preferred in the command."
|
|
339
|
+
} },
|
|
340
|
+
output: {
|
|
341
|
+
schema: { type: "string" },
|
|
342
|
+
render: (_args, value) => [{
|
|
343
|
+
type: "text",
|
|
344
|
+
text: value
|
|
345
|
+
}]
|
|
346
|
+
},
|
|
347
|
+
async execute(args, exec) {
|
|
348
|
+
if (args.command.trim().length === 0) throw new Error("command must be a non-empty string");
|
|
349
|
+
const owner = exec.agent;
|
|
350
|
+
if (owner === void 0) throw new Error("bash requires an owning agent session");
|
|
351
|
+
return serialized(owner, async () => {
|
|
352
|
+
exec.signal.throwIfAborted();
|
|
353
|
+
return executeCommand(ctx, shells, owner, args.command, config, exec.signal);
|
|
354
|
+
});
|
|
355
|
+
},
|
|
356
|
+
presentCall: (args) => ({
|
|
357
|
+
card: "terminal",
|
|
358
|
+
title: args.command
|
|
359
|
+
})
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
362
|
+
const name = "tool-bash-persistent";
|
|
363
|
+
const inject = ["tools", "terminals"];
|
|
364
|
+
/** Runtime configuration schema for the persistent Bash tool. */
|
|
365
|
+
const Config = z.object({
|
|
366
|
+
backendType: z.string().default("shell"),
|
|
367
|
+
timeoutMs: z.number().default(3e5),
|
|
368
|
+
maxOutputChars: z.number().default(16e3),
|
|
369
|
+
description: z.string().default(DEFAULT_DESCRIPTION)
|
|
370
|
+
});
|
|
371
|
+
/** Register one owner-scoped persistent `bash` tool. */
|
|
372
|
+
function apply(ctx, config) {
|
|
373
|
+
const resolved = {
|
|
374
|
+
backendType: config.backendType ?? "shell",
|
|
375
|
+
timeoutMs: config.timeoutMs ?? 3e5,
|
|
376
|
+
maxOutputChars: config.maxOutputChars ?? 16e3,
|
|
377
|
+
description: config.description ?? DEFAULT_DESCRIPTION
|
|
378
|
+
};
|
|
379
|
+
if (resolved.backendType.trim().length === 0) throw new Error("tool-bash-persistent: backendType must be non-empty");
|
|
380
|
+
if (!Number.isSafeInteger(resolved.timeoutMs) || resolved.timeoutMs <= 0) throw new Error("tool-bash-persistent: timeoutMs must be a positive safe integer");
|
|
381
|
+
if (!Number.isSafeInteger(resolved.maxOutputChars) || resolved.maxOutputChars <= 0) throw new Error("tool-bash-persistent: maxOutputChars must be a positive safe integer");
|
|
382
|
+
if (resolved.description.trim().length === 0) throw new Error("tool-bash-persistent: description must be non-empty");
|
|
383
|
+
registerPersistentBash(ctx, resolved);
|
|
384
|
+
}
|
|
385
|
+
//#endregion
|
|
386
|
+
export { Config, apply, inject, name };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing persistent `bash` tool over the owner-scoped PTY seam.
|
|
3
|
+
* @module @deepseek-ai/dsh-tool-bash-persistent
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
+
import z from '@deepseek-ai/schemastery';
|
|
7
|
+
export declare const name = "tool-bash-persistent";
|
|
8
|
+
export declare const inject: string[];
|
|
9
|
+
/** Configuration for the persistent Bash tool. */
|
|
10
|
+
export interface Config {
|
|
11
|
+
/** PTY backend used for each owner-isolated persistent shell (default `shell`). */
|
|
12
|
+
backendType?: string;
|
|
13
|
+
/** Wall-clock limit for one command (default 300000). */
|
|
14
|
+
timeoutMs?: number;
|
|
15
|
+
/** Maximum returned command-output characters before clipping (default 16000). */
|
|
16
|
+
maxOutputChars?: number;
|
|
17
|
+
/** Model-facing tool description; deployments may describe their environment. */
|
|
18
|
+
description?: string;
|
|
19
|
+
}
|
|
20
|
+
/** Runtime configuration schema for the persistent Bash tool. */
|
|
21
|
+
export declare const Config: z<Config>;
|
|
22
|
+
/** Register one owner-scoped persistent `bash` tool. */
|
|
23
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 unlinearity
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|