dsh-bash-terminal-ts 0.7.2-compat.2 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.de.md +3 -2
- package/README.en.md +102 -3
- package/README.es.md +3 -2
- package/README.fr.md +3 -2
- package/README.it.md +3 -2
- package/README.md +198 -4
- package/README.ru.md +3 -2
- package/cordis.patch.yml +66 -0
- package/dist/client.core.js +7888 -79
- package/dist/client.js +7888 -79
- package/dsh.plugin.json +22 -22
- package/lib/browser-i18n.d.ts +4 -0
- package/lib/browser-i18n.js +23 -0
- package/lib/client.js +7888 -79
- package/lib/dsh-types.d.ts +10 -0
- package/lib/dsh.d.ts +2 -0
- package/lib/index.d.ts +43 -0
- package/lib/index.js +176 -91
- package/lib/locales.d.ts +4 -0
- package/lib/locales.js +422 -0
- package/lib/settings-surface.d.ts +20 -0
- package/lib/settings-surface.js +49 -0
- package/lib/shell-id.d.ts +2 -0
- package/lib/shell-id.js +9 -0
- package/lib/shells.d.ts +114 -0
- package/lib/shells.js +187 -0
- package/lib/terminal.d.ts +30 -1
- package/lib/terminal.js +18 -5
- package/lib/webterminals/catalog.d.ts +36 -0
- package/lib/webterminals/catalog.js +93 -0
- package/lib/webterminals/host.d.ts +67 -0
- package/lib/webterminals/host.js +278 -0
- package/lib/webterminals/mount.d.ts +46 -0
- package/lib/webterminals/mount.js +171 -0
- package/lib/webterminals/protocol.d.ts +94 -0
- package/lib/webterminals/protocol.js +9 -0
- package/lib/webterminals/pty.d.ts +42 -0
- package/lib/webterminals/pty.js +64 -0
- package/lib/webterminals/registry.d.ts +139 -0
- package/lib/webterminals/registry.js +353 -0
- package/lib/webterminals/ws.d.ts +54 -0
- package/lib/webterminals/ws.js +140 -0
- package/locale/de.json +4 -0
- package/locale/en.json +4 -0
- package/locale/es.json +4 -0
- package/locale/fr.json +4 -0
- package/locale/it.json +4 -0
- package/locale/ja.json +4 -0
- package/locale/ko.json +4 -0
- package/locale/ru.json +4 -0
- package/locale/zh.json +4 -0
- package/package.json +131 -121
- package/scripts/build-browser-tests.mjs +36 -0
- package/scripts/build-client.mjs +10 -0
- package/scripts/check-artifacts.mjs +93 -0
- package/scripts/link-shells.mjs +75 -0
- package/src/browser-i18n.ts +27 -0
- package/src/client.tsx +539 -134
- package/src/dsh-types.ts +6 -0
- package/src/dsh.ts +2 -0
- package/src/index.ts +146 -35
- package/src/locales.ts +434 -0
- package/src/settings-surface.ts +59 -0
- package/src/shell-id.ts +11 -0
- package/src/shells.ts +250 -0
- package/src/terminal.ts +34 -5
- package/src/webterminals/browser/api.ts +212 -0
- package/src/webterminals/browser/bridge.ts +188 -0
- package/src/webterminals/browser/css.d.ts +16 -0
- package/src/webterminals/browser/face.ts +151 -0
- package/src/webterminals/browser/shell-picker.tsx +98 -0
- package/src/webterminals/browser/store.ts +40 -0
- package/src/webterminals/browser/tab.tsx +136 -0
- package/src/webterminals/browser/testkit.ts +21 -0
- package/src/webterminals/browser/url.ts +70 -0
- package/src/webterminals/browser/view.ts +381 -0
- package/src/webterminals/browser/xterm.ts +269 -0
- package/src/webterminals/catalog.ts +114 -0
- package/src/webterminals/host.ts +361 -0
- package/src/webterminals/mount.ts +227 -0
- package/src/webterminals/protocol.ts +78 -0
- package/src/webterminals/pty.ts +90 -0
- package/src/webterminals/registry.ts +447 -0
- package/src/webterminals/ws.ts +166 -0
- package/tsconfig.client.json +9 -1
- package/tsconfig.json +1 -1
package/lib/dsh-types.d.ts
CHANGED
|
@@ -254,6 +254,16 @@ export interface BashTerminalContext {
|
|
|
254
254
|
sandbox: SandboxSeam;
|
|
255
255
|
get(key: string): unknown;
|
|
256
256
|
effect(fn: () => void | (() => void), name?: string): unknown;
|
|
257
|
+
/**
|
|
258
|
+
* Service-arrival callback (cordis core). Both host channels mount through it:
|
|
259
|
+
* the six-line settings bridge and the browser terminal's routes. Typed to the
|
|
260
|
+
* services they actually read; the derived context carries more.
|
|
261
|
+
*/
|
|
262
|
+
inject?(deps: string[], callback: (svcCtx: {
|
|
263
|
+
webServer?: unknown;
|
|
264
|
+
settings?: unknown;
|
|
265
|
+
effect(fn: () => void | (() => void), name?: string): unknown;
|
|
266
|
+
}) => void): void;
|
|
257
267
|
/** Injected via `inject: ["subprocess"]`; tests may defer assignment. */
|
|
258
268
|
subprocess: SubprocessSeam | null;
|
|
259
269
|
}
|
package/lib/dsh.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface Schemastery {
|
|
|
27
27
|
object(fields: Record<string, SchemasterySchema>): SchemasterySchema;
|
|
28
28
|
string(): SchemasterySchema;
|
|
29
29
|
number(): SchemasterySchema;
|
|
30
|
+
/** Accept booleans (the fork's `Static.boolean`; renders as a switch). */
|
|
31
|
+
boolean(): SchemasterySchema;
|
|
30
32
|
const(value: string): SchemasterySchema;
|
|
31
33
|
union(schemas: SchemasterySchema[]): SchemasterySchema;
|
|
32
34
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -16,6 +16,33 @@ export interface ConfigValues {
|
|
|
16
16
|
gitBashPath: string;
|
|
17
17
|
msys2Path: string;
|
|
18
18
|
wslPath: string;
|
|
19
|
+
/**
|
|
20
|
+
* The bottom terminal's MASTER switch. Off outranks every child choice: the
|
|
21
|
+
* settings row hides the per-shell switches (a switch for something that cannot
|
|
22
|
+
* run is a lie) and the routes refuse allocations.
|
|
23
|
+
*/
|
|
24
|
+
bottomTerminal: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Opt in to publishing the client-side `webTerminals` service, which is what powers
|
|
27
|
+
* dsh-better-sidebar's OFFICIAL bottom "Terminal" row on a deployment that has no
|
|
28
|
+
* terminal controller. Default false: the name is also provided by the host's own
|
|
29
|
+
* controller client, cordis refuses the second provider, and the controller's provide
|
|
30
|
+
* is unguarded - so claiming it by default breaks the first-party terminal and the
|
|
31
|
+
* whole web boot on DSH 0.2.0+ (measured). Turn it on only where the official row is
|
|
32
|
+
* dead because no controller exists.
|
|
33
|
+
*/
|
|
34
|
+
shimOfficialTerminal: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Browser-terminal activation (R1/R2). The default is `true` for all three:
|
|
37
|
+
* a switch means "allowed", and availability is ANDed with it by the catalog -
|
|
38
|
+
* so "detected means on" needs no probe at schema level, while an explicit
|
|
39
|
+
* `false` is a real opt-out even on a machine that has the shell.
|
|
40
|
+
*/
|
|
41
|
+
shellGitBash: boolean;
|
|
42
|
+
shellMsys2: boolean;
|
|
43
|
+
shellWsl: boolean;
|
|
44
|
+
/** WSL distribution for the browser terminal; '' means the WSL default. */
|
|
45
|
+
wslDistro: string;
|
|
19
46
|
}
|
|
20
47
|
/** Runtime configuration schema. */
|
|
21
48
|
export declare const Config: import("./dsh.js").SchemasterySchema;
|
|
@@ -178,6 +205,22 @@ export interface BackgroundResult {
|
|
|
178
205
|
jobId: string;
|
|
179
206
|
}
|
|
180
207
|
export type ShellToolResult = ForegroundResult | BackgroundResult;
|
|
208
|
+
/**
|
|
209
|
+
* Persist one config path through the host settings service.
|
|
210
|
+
*
|
|
211
|
+
* Shared by the model tool's `defaultShell` write and the browser terminal's
|
|
212
|
+
* activation switches, because the line-dependent part is the whole difficulty:
|
|
213
|
+
* ≤0.1.6 loaders do not register a plugin's settings namespace automatically, so
|
|
214
|
+
* the first `mutate` fails with "not registered" and the caller has to register it
|
|
215
|
+
* (with the written value as the base, so the retry sees it) and retry. On rc.1+
|
|
216
|
+
* the namespace is already owned by the loader, that branch never fires, and the
|
|
217
|
+
* plain `mutate` is the whole story.
|
|
218
|
+
* @param svc - the host `settings` service (untyped: shapes differ per line).
|
|
219
|
+
* @param path - the config path inside this plugin's entry (one level today).
|
|
220
|
+
* @throws when the line has no `mutate` at all - the caller reports it, and the
|
|
221
|
+
* value then applies for this process only.
|
|
222
|
+
*/
|
|
223
|
+
export declare function persistConfigValue(svc: unknown, path: readonly string[], value: unknown): Promise<void>;
|
|
181
224
|
export declare function apply(ctx: BashTerminalContext, config?: Partial<ConfigValues>): void;
|
|
182
225
|
export declare const internals: {
|
|
183
226
|
candidateExists: typeof candidateExists;
|
package/lib/index.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
// "CreateFileMapping ... Win32 error 5" during startup.
|
|
24
24
|
import { lstatSync } from "node:fs";
|
|
25
25
|
import { isAbsolute, join, resolve } from "node:path";
|
|
26
|
+
import { mountBrowserTerminals } from "./webterminals/mount.js";
|
|
26
27
|
import { ESCALATION_TARGETS, TOOL_ABORTED, approveEscalation, defineTool, escalationHintMarker, clampTimeout, deadline, parseExitStatus, timeoutOf, sandboxDenialMarker, validateEscalationArgs, z, HarnessError } from "./dsh.js";
|
|
27
28
|
import { createTerminalRegistry, terminalTool } from "./terminal.js";
|
|
28
29
|
/** Stable Cordis plugin name. */
|
|
@@ -62,7 +63,16 @@ export const Config = z.object({
|
|
|
62
63
|
pwshPath: z.string().default(""),
|
|
63
64
|
gitBashPath: z.string().default(""),
|
|
64
65
|
msys2Path: z.string().default(""),
|
|
65
|
-
wslPath: z.string().default("")
|
|
66
|
+
wslPath: z.string().default(""),
|
|
67
|
+
// `.volatile()` on the new fields: the browser terminal reads them on every
|
|
68
|
+
// allocation, and a flip in the settings page has to take effect without a
|
|
69
|
+
// restart (0.1.7+ hands apply a live ref; older lines re-read the same value).
|
|
70
|
+
bottomTerminal: z.boolean().default(true).volatile(),
|
|
71
|
+
shimOfficialTerminal: z.boolean().default(false).volatile(),
|
|
72
|
+
shellGitBash: z.boolean().default(true).volatile(),
|
|
73
|
+
shellMsys2: z.boolean().default(true).volatile(),
|
|
74
|
+
shellWsl: z.boolean().default(true).volatile(),
|
|
75
|
+
wslDistro: z.string().default("").volatile()
|
|
66
76
|
});
|
|
67
77
|
// ---- executable resolution ------------------------------------------------
|
|
68
78
|
function candidateExists(candidate) {
|
|
@@ -492,13 +502,43 @@ const BACKGROUND_OUTPUT_PROPERTIES = {
|
|
|
492
502
|
kind: { type: "string", required: true, const: "background" },
|
|
493
503
|
jobId: { type: "string", required: true }
|
|
494
504
|
};
|
|
505
|
+
/**
|
|
506
|
+
* Persist one config path through the host settings service.
|
|
507
|
+
*
|
|
508
|
+
* Shared by the model tool's `defaultShell` write and the browser terminal's
|
|
509
|
+
* activation switches, because the line-dependent part is the whole difficulty:
|
|
510
|
+
* ≤0.1.6 loaders do not register a plugin's settings namespace automatically, so
|
|
511
|
+
* the first `mutate` fails with "not registered" and the caller has to register it
|
|
512
|
+
* (with the written value as the base, so the retry sees it) and retry. On rc.1+
|
|
513
|
+
* the namespace is already owned by the loader, that branch never fires, and the
|
|
514
|
+
* plain `mutate` is the whole story.
|
|
515
|
+
* @param svc - the host `settings` service (untyped: shapes differ per line).
|
|
516
|
+
* @param path - the config path inside this plugin's entry (one level today).
|
|
517
|
+
* @throws when the line has no `mutate` at all - the caller reports it, and the
|
|
518
|
+
* value then applies for this process only.
|
|
519
|
+
*/
|
|
520
|
+
export async function persistConfigValue(svc, path, value) {
|
|
521
|
+
const service = svc;
|
|
522
|
+
if (typeof service?.mutate !== "function") {
|
|
523
|
+
throw new Error("settings service exposes no mutate on this host line - the value applies for this process only; persist via cordis.patch.yml");
|
|
524
|
+
}
|
|
525
|
+
const ops = [{ op: "set", path: [...path], value }];
|
|
526
|
+
try {
|
|
527
|
+
await service.mutate(ENTRY_ID, ops);
|
|
528
|
+
}
|
|
529
|
+
catch (e) {
|
|
530
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
531
|
+
if (!/not registered/i.test(message) || typeof service.register !== "function") {
|
|
532
|
+
throw e;
|
|
533
|
+
}
|
|
534
|
+
console.warn(`[dsh-bash-terminal-ts] legacy line: registering settings namespace ${ENTRY_ID}`);
|
|
535
|
+
service.register(ENTRY_ID, Config, { base: { [path.join(".")]: value } });
|
|
536
|
+
await service.mutate(ENTRY_ID, ops);
|
|
537
|
+
console.warn("[dsh-bash-terminal-ts] legacy settings namespace registered");
|
|
538
|
+
}
|
|
539
|
+
}
|
|
495
540
|
// ---- plugin -------------------------------------------------------------------
|
|
496
541
|
export function apply(ctx, config = {}) {
|
|
497
|
-
if (process.platform !== "win32") {
|
|
498
|
-
ctx.logger?.info?.("dsh-bash-terminal-ts: only meaningful on win32; skipping tool registration");
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
const backgroundEnabled = true;
|
|
502
542
|
const paths = resolveAllPaths(config);
|
|
503
543
|
// 0.1.7: `defaultShell` is a `.volatile()` config field — the loader hands
|
|
504
544
|
// `apply` a live ref and the latest value is resolved on every read; there
|
|
@@ -506,7 +546,8 @@ export function apply(ctx, config = {}) {
|
|
|
506
546
|
// compat-legacy: ≤0.1.6 的宿主没有配置热重载,bridge 写入走这个覆盖值
|
|
507
547
|
// (rc.1+ 上 volatile 与覆盖值同源同写,二者一致)。
|
|
508
548
|
let shellOverride;
|
|
509
|
-
|
|
549
|
+
/** The stored value, verbatim - including one that is no longer selectable. */
|
|
550
|
+
const storedShell = () => {
|
|
510
551
|
if (typeof shellOverride === "string" && SHELLS.includes(shellOverride)) {
|
|
511
552
|
return shellOverride;
|
|
512
553
|
}
|
|
@@ -516,9 +557,60 @@ export function apply(ctx, config = {}) {
|
|
|
516
557
|
const got = typeof v?.get === "function" ? v.get() : undefined;
|
|
517
558
|
return typeof got === "string" ? got : DEFAULT_SHELL;
|
|
518
559
|
};
|
|
519
|
-
|
|
520
|
-
|
|
560
|
+
let warnedStale = false;
|
|
561
|
+
/**
|
|
562
|
+
* The shell the TOOL will run. Deliberately the stored value, un-sanitised:
|
|
563
|
+
* `buildArgv`/`terminalArgv` throw for anything outside SHELLS, so an
|
|
564
|
+
* out-of-enum choice fails closed at call time rather than quietly running the
|
|
565
|
+
* command in a different shell than the model was told about.
|
|
566
|
+
*/
|
|
567
|
+
const currentShell = storedShell;
|
|
568
|
+
/**
|
|
569
|
+
* What the model is TOLD. Sanitised, because this one runs on every prompt
|
|
570
|
+
* assembly: an invalid stored value must not break the whole prompt, and naming
|
|
571
|
+
* the floor is honest about what a successful call would use.
|
|
572
|
+
*/
|
|
573
|
+
const describedShell = () => {
|
|
574
|
+
const stored = storedShell();
|
|
575
|
+
if (SHELLS.includes(stored))
|
|
576
|
+
return stored;
|
|
577
|
+
if (!warnedStale) {
|
|
578
|
+
warnedStale = true;
|
|
579
|
+
ctx.logger?.warn?.(`dsh-bash-terminal-ts: defaultShell ${JSON.stringify(stored)} is not a selectable backend; shell calls will fail closed and the bottom terminal falls back to ${DEFAULT_SHELL}`);
|
|
580
|
+
}
|
|
581
|
+
return DEFAULT_SHELL;
|
|
582
|
+
};
|
|
583
|
+
// The browser terminal (bottom dock / embedded shell). Mounted BEFORE the
|
|
584
|
+
// win32 return below: the model tool is Windows-only, the terminal is not
|
|
585
|
+
// (finding F1). Its routes report their own availability, so a host without
|
|
586
|
+
// `registerUpgrade` or without any PTY backend shows a reason instead of a
|
|
587
|
+
// dead panel.
|
|
588
|
+
const browserTerminals = mountBrowserTerminals({
|
|
589
|
+
ctx: ctx,
|
|
590
|
+
config: config,
|
|
591
|
+
paths,
|
|
592
|
+
configuredShell: storedShell,
|
|
593
|
+
persist: async (svc, path, value) => {
|
|
594
|
+
await persistConfigValue(svc, path, value);
|
|
595
|
+
// ≤0.1.6 hosts have no config hot-reload, so mirror a defaultShell write into
|
|
596
|
+
// the same in-process override the legacy bridge uses. Without it, choosing a
|
|
597
|
+
// shell in the bottom-terminal section would only reach the model tool after
|
|
598
|
+
// a restart - the exact divergence the bridge's `shellOverride` exists to kill.
|
|
599
|
+
if (path.length === 1 && path[0] === "defaultShell" && typeof value === "string") {
|
|
600
|
+
shellOverride = value;
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
});
|
|
604
|
+
ctx.effect(() => () => browserTerminals.dispose(), "bash-terminal: browser terminal teardown");
|
|
605
|
+
if (process.platform !== "win32") {
|
|
606
|
+
ctx.logger?.info?.("dsh-bash-terminal-ts: only meaningful on win32; skipping tool registration");
|
|
607
|
+
return;
|
|
521
608
|
}
|
|
609
|
+
const backgroundEnabled = true;
|
|
610
|
+
// R5/R6 and finding F8: an invalid stored value used to throw here, which failed
|
|
611
|
+
// the whole entry - the tool, the settings row and the browser terminal all
|
|
612
|
+
// disappeared. The entry now stays mounted, the tool fails closed per call, and
|
|
613
|
+
// the browser terminal substitutes the floor and says so.
|
|
522
614
|
/** Official sandbox-escalation surface (mirrors tool-bash): advertise the
|
|
523
615
|
* escalation modes whenever the deployment confines. */
|
|
524
616
|
const escalationModes = ESCALATION_TARGETS;
|
|
@@ -547,93 +639,86 @@ export function apply(ctx, config = {}) {
|
|
|
547
639
|
// rc.1+ 命名空间由 loader 占用,该分支自然不命中。GET 带回当前值与可选集。
|
|
548
640
|
// 宿主 context 类型未收录 inject/局部服务形状,compat 桥按宽化面调用。
|
|
549
641
|
const compatCtx = ctx;
|
|
550
|
-
compatCtx.inject
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
throw e;
|
|
566
|
-
}
|
|
567
|
-
console.warn(`[dsh-bash-terminal-ts] legacy line: registering settings namespace ${ENTRY_ID}`);
|
|
568
|
-
svc.register(ENTRY_ID, Config, { base: { defaultShell: value } });
|
|
569
|
-
await svc.mutate(ENTRY_ID, [{ op: "set", path: ["defaultShell"], value }]);
|
|
570
|
-
console.warn("[dsh-bash-terminal-ts] legacy settings namespace registered");
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
svcCtx.effect(() => {
|
|
574
|
-
const json = (res, status, body) => {
|
|
575
|
-
res.writeHead(status, { "content-type": "application/json; charset=utf-8" });
|
|
576
|
-
res.end(JSON.stringify(body));
|
|
642
|
+
if (typeof compatCtx.inject !== "function") {
|
|
643
|
+
// A context without `inject` (a bare mock, or a host that resolves services
|
|
644
|
+
// only synchronously) cannot receive the bridge at all. Skipping it must not
|
|
645
|
+
// take the tool down with it - the tool is what the model calls.
|
|
646
|
+
ctx.logger?.warn?.("dsh-bash-terminal-ts: ctx.inject unavailable - the settings bridge is not mounted (defaultShell reads still work, writes will not)");
|
|
647
|
+
}
|
|
648
|
+
else
|
|
649
|
+
compatCtx.inject(["webServer", "settings"], (svcCtx) => {
|
|
650
|
+
const svc = svcCtx.settings;
|
|
651
|
+
const writeShell = async (value) => {
|
|
652
|
+
// One implementation for every config write (the browser terminal's switches
|
|
653
|
+
// go through the same helper), so the legacy self-registration dance exists
|
|
654
|
+
// in exactly one place.
|
|
655
|
+
await persistConfigValue(svc, ["defaultShell"], value);
|
|
656
|
+
shellOverride = value;
|
|
577
657
|
};
|
|
578
|
-
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
json(res, 200, {
|
|
589
|
-
ok: true,
|
|
590
|
-
value: {
|
|
591
|
-
defaultShell: currentShell(),
|
|
592
|
-
shells: SHELLS,
|
|
593
|
-
seam: { spawn: typeof sp?.spawn, spawnTerminal: typeof sp?.spawnTerminal },
|
|
594
|
-
},
|
|
595
|
-
});
|
|
596
|
-
return;
|
|
597
|
-
}
|
|
598
|
-
if (req.method !== "POST") {
|
|
599
|
-
json(res, 405, { ok: false, code: "method-not-allowed" });
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
const chunks = [];
|
|
603
|
-
let size = 0;
|
|
604
|
-
req.on("data", (c) => {
|
|
605
|
-
size += c.length;
|
|
606
|
-
if (size <= 65536)
|
|
607
|
-
chunks.push(c);
|
|
608
|
-
});
|
|
609
|
-
req.on("end", () => {
|
|
610
|
-
let body = {};
|
|
611
|
-
try {
|
|
612
|
-
body = JSON.parse(Buffer.concat(chunks).toString("utf8") || "{}");
|
|
658
|
+
svcCtx.effect(() => {
|
|
659
|
+
const json = (res, status, body) => {
|
|
660
|
+
res.writeHead(status, { "content-type": "application/json; charset=utf-8" });
|
|
661
|
+
res.end(JSON.stringify(body));
|
|
662
|
+
};
|
|
663
|
+
const handler = (req, res) => {
|
|
664
|
+
const addr = req.socket?.remoteAddress ?? "";
|
|
665
|
+
if (addr !== "127.0.0.1" && addr !== "::1" && addr !== "::ffff:127.0.0.1") {
|
|
666
|
+
json(res, 403, { ok: false, code: "loopback-only" });
|
|
667
|
+
return;
|
|
613
668
|
}
|
|
614
|
-
|
|
615
|
-
|
|
669
|
+
if (req.method === "GET") {
|
|
670
|
+
// 缝内省:compat 验证用——当前线 ctx.subprocess 的真实能力面
|
|
671
|
+
const seam = ctx;
|
|
672
|
+
const sp = seam.subprocess;
|
|
673
|
+
json(res, 200, {
|
|
674
|
+
ok: true,
|
|
675
|
+
value: {
|
|
676
|
+
defaultShell: currentShell(),
|
|
677
|
+
shells: SHELLS,
|
|
678
|
+
seam: { spawn: typeof sp?.spawn, spawnTerminal: typeof sp?.spawnTerminal },
|
|
679
|
+
},
|
|
680
|
+
});
|
|
616
681
|
return;
|
|
617
682
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
json(res, 400, { ok: false, code: "invalid-shell" });
|
|
683
|
+
if (req.method !== "POST") {
|
|
684
|
+
json(res, 405, { ok: false, code: "method-not-allowed" });
|
|
621
685
|
return;
|
|
622
686
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
687
|
+
const chunks = [];
|
|
688
|
+
let size = 0;
|
|
689
|
+
req.on("data", (c) => {
|
|
690
|
+
size += c.length;
|
|
691
|
+
if (size <= 65536)
|
|
692
|
+
chunks.push(c);
|
|
693
|
+
});
|
|
694
|
+
req.on("end", () => {
|
|
695
|
+
let body = {};
|
|
696
|
+
try {
|
|
697
|
+
body = JSON.parse(Buffer.concat(chunks).toString("utf8") || "{}");
|
|
698
|
+
}
|
|
699
|
+
catch {
|
|
700
|
+
json(res, 400, { ok: false, code: "bad-json" });
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
const value = typeof body.defaultShell === "string" ? body.defaultShell : "";
|
|
704
|
+
if (!SHELLS.includes(value)) {
|
|
705
|
+
json(res, 400, { ok: false, code: "invalid-shell" });
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
void writeShell(value)
|
|
709
|
+
.then(() => json(res, 200, { ok: true, value: { defaultShell: value } }))
|
|
710
|
+
.catch((e) => json(res, 500, { ok: false, code: "write-failed", message: e instanceof Error ? e.message : String(e) }));
|
|
711
|
+
});
|
|
712
|
+
};
|
|
713
|
+
const registered = [
|
|
714
|
+
svcCtx.webServer.register({ kind: "exact", path: "/api/bash-terminal/config", handler }),
|
|
715
|
+
];
|
|
716
|
+
return () => {
|
|
717
|
+
for (const dispose of registered)
|
|
718
|
+
dispose();
|
|
719
|
+
};
|
|
720
|
+
}, "bash-terminal: compat config bridge");
|
|
721
|
+
});
|
|
637
722
|
const toolName = "shell";
|
|
638
723
|
const terminalRegistry = createTerminalRegistry(ctx);
|
|
639
724
|
ctx.tools.register(terminalTool(ctx, terminalRegistry, paths, () => currentShell()));
|
|
@@ -644,7 +729,7 @@ export function apply(ctx, config = {}) {
|
|
|
644
729
|
// without a restart.
|
|
645
730
|
ctx.on("system-prompt/assemble", async (_assembly, _context, next) => {
|
|
646
731
|
const assembled = await next();
|
|
647
|
-
const description = toolDescription(backgroundEnabled,
|
|
732
|
+
const description = toolDescription(backgroundEnabled, describedShell());
|
|
648
733
|
const tools = Array.isArray(assembled.tools)
|
|
649
734
|
? assembled.tools.map((tool) => (tool.name === toolName ? { ...tool, description } : tool))
|
|
650
735
|
: assembled.tools;
|
package/lib/locales.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The registered dictionary, one row per host language. */
|
|
2
|
+
export declare const dictionaries: Record<string, Record<string, string>>;
|
|
3
|
+
/** The Chinese fallback used when the host exposes no `locale.bind` (0.1.0/0.1.1). */
|
|
4
|
+
export declare const fallbackDict: Record<string, string>;
|