@devframes/plugin-terminals 0.0.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/LICENSE.md +21 -0
- package/bin.mjs +13 -0
- package/dist/cli.d.mts +12 -0
- package/dist/cli.mjs +13 -0
- package/dist/client/index.d.mts +16 -0
- package/dist/client/index.mjs +12095 -0
- package/dist/constants.d.mts +30 -0
- package/dist/constants.mjs +30 -0
- package/dist/index.d.mts +28 -0
- package/dist/index.mjs +3 -0
- package/dist/node/index.d.mts +157 -0
- package/dist/node/index.mjs +580 -0
- package/dist/rpc/index.d.mts +695 -0
- package/dist/rpc/index.mjs +2 -0
- package/dist/rpc-F1ncx7tt.mjs +247 -0
- package/dist/spa/assets/index-Dmm_EwpX.js +38 -0
- package/dist/spa/assets/index-IBTOt_--.css +1 -0
- package/dist/spa/index.html +19 -0
- package/dist/src-Cu5HYNrI.mjs +56 -0
- package/dist/types.d.mts +129 -0
- package/dist/types.mjs +1 -0
- package/dist/vite.d.mts +18 -0
- package/dist/vite.mjs +20 -0
- package/package.json +88 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/constants.d.ts
|
|
2
|
+
/** Stable devframe id for the terminals plugin. */
|
|
3
|
+
declare const PLUGIN_ID = "devframes-plugin-terminals";
|
|
4
|
+
/**
|
|
5
|
+
* Streaming channel carrying terminal output. Each session is a stream
|
|
6
|
+
* keyed by the session id, so clients subscribe by id the moment they
|
|
7
|
+
* see a session in the shared-state list.
|
|
8
|
+
*/
|
|
9
|
+
declare const TERMINAL_STREAM_CHANNEL = "devframes-plugin-terminals:output";
|
|
10
|
+
/**
|
|
11
|
+
* Streaming channel the hub's own terminals subsystem (`ctx.terminals`) uses
|
|
12
|
+
* for aggregated sessions contributed by *other* devframes (e.g. code-server).
|
|
13
|
+
* Mirrors `@devframes/hub`'s internal channel name; the plugin surfaces those
|
|
14
|
+
* sessions read-only and reads their output from here. Kept as a literal so the
|
|
15
|
+
* plugin needs no build dependency on the hub.
|
|
16
|
+
*/
|
|
17
|
+
declare const HUB_TERMINAL_STREAM_CHANNEL = "devframe:terminals";
|
|
18
|
+
/** Shared-state key holding the serializable session list. */
|
|
19
|
+
declare const SESSIONS_STATE_KEY = "devframes-plugin-terminals:sessions";
|
|
20
|
+
/** Shared-state key holding the spawnable command presets. */
|
|
21
|
+
declare const PRESETS_STATE_KEY = "devframes-plugin-terminals:presets";
|
|
22
|
+
/** Default dev-server port for the standalone CLI. */
|
|
23
|
+
declare const DEFAULT_PORT = 9011;
|
|
24
|
+
/** Default number of output chunks retained for replay on reconnect. */
|
|
25
|
+
declare const DEFAULT_SCROLLBACK = 5000;
|
|
26
|
+
/** Default terminal geometry before the client reports its real size. */
|
|
27
|
+
declare const DEFAULT_COLS = 80;
|
|
28
|
+
declare const DEFAULT_ROWS = 24;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { DEFAULT_COLS, DEFAULT_PORT, DEFAULT_ROWS, DEFAULT_SCROLLBACK, HUB_TERMINAL_STREAM_CHANNEL, PLUGIN_ID, PRESETS_STATE_KEY, SESSIONS_STATE_KEY, TERMINAL_STREAM_CHANNEL };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/constants.ts
|
|
2
|
+
/** Stable devframe id for the terminals plugin. */
|
|
3
|
+
const PLUGIN_ID = "devframes-plugin-terminals";
|
|
4
|
+
/**
|
|
5
|
+
* Streaming channel carrying terminal output. Each session is a stream
|
|
6
|
+
* keyed by the session id, so clients subscribe by id the moment they
|
|
7
|
+
* see a session in the shared-state list.
|
|
8
|
+
*/
|
|
9
|
+
const TERMINAL_STREAM_CHANNEL = "devframes-plugin-terminals:output";
|
|
10
|
+
/**
|
|
11
|
+
* Streaming channel the hub's own terminals subsystem (`ctx.terminals`) uses
|
|
12
|
+
* for aggregated sessions contributed by *other* devframes (e.g. code-server).
|
|
13
|
+
* Mirrors `@devframes/hub`'s internal channel name; the plugin surfaces those
|
|
14
|
+
* sessions read-only and reads their output from here. Kept as a literal so the
|
|
15
|
+
* plugin needs no build dependency on the hub.
|
|
16
|
+
*/
|
|
17
|
+
const HUB_TERMINAL_STREAM_CHANNEL = "devframe:terminals";
|
|
18
|
+
/** Shared-state key holding the serializable session list. */
|
|
19
|
+
const SESSIONS_STATE_KEY = "devframes-plugin-terminals:sessions";
|
|
20
|
+
/** Shared-state key holding the spawnable command presets. */
|
|
21
|
+
const PRESETS_STATE_KEY = "devframes-plugin-terminals:presets";
|
|
22
|
+
/** Default dev-server port for the standalone CLI. */
|
|
23
|
+
const DEFAULT_PORT = 9011;
|
|
24
|
+
/** Default number of output chunks retained for replay on reconnect. */
|
|
25
|
+
const DEFAULT_SCROLLBACK = 5e3;
|
|
26
|
+
/** Default terminal geometry before the client reports its real size. */
|
|
27
|
+
const DEFAULT_COLS = 80;
|
|
28
|
+
const DEFAULT_ROWS = 24;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { DEFAULT_COLS, DEFAULT_PORT, DEFAULT_ROWS, DEFAULT_SCROLLBACK, HUB_TERMINAL_STREAM_CHANNEL, PLUGIN_ID, PRESETS_STATE_KEY, SESSIONS_STATE_KEY, TERMINAL_STREAM_CHANNEL };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { SpawnRequest, TerminalBackend, TerminalMode, TerminalPreset, TerminalSessionInfo, TerminalStatus, TerminalsOptions, TerminalsSharedState } from "./types.mjs";
|
|
2
|
+
import { DEFAULT_PORT, PLUGIN_ID, PRESETS_STATE_KEY, SESSIONS_STATE_KEY, TERMINAL_STREAM_CHANNEL } from "./constants.mjs";
|
|
3
|
+
import { DevframeDefinition } from "devframe/types";
|
|
4
|
+
|
|
5
|
+
//#region src/index.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Build a {@link DevframeDefinition} for the terminals panel. The same
|
|
8
|
+
* definition runs standalone (`createCli`), mounts into a Vite host
|
|
9
|
+
* (`/vite`), or docks inside a hub — its `setup` only relies on the core
|
|
10
|
+
* devframe RPC surface.
|
|
11
|
+
*
|
|
12
|
+
* @experimental This plugin is experimental and may change without a major
|
|
13
|
+
* version bump until it stabilizes.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { createTerminalsDevframe } from '@devframes/plugin-terminals'
|
|
18
|
+
*
|
|
19
|
+
* export default createTerminalsDevframe({
|
|
20
|
+
* presets: [{ id: 'dev', title: 'pnpm dev', command: 'pnpm', args: ['dev'] }],
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
declare function createTerminalsDevframe(options?: TerminalsOptions): DevframeDefinition;
|
|
25
|
+
/** Default-configured terminals devframe (interactive shell, no presets). */
|
|
26
|
+
declare const terminals: DevframeDefinition;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { DEFAULT_PORT, PLUGIN_ID, PRESETS_STATE_KEY, SESSIONS_STATE_KEY, SpawnRequest, TERMINAL_STREAM_CHANNEL, TerminalBackend, TerminalMode, TerminalPreset, TerminalSessionInfo, TerminalStatus, TerminalsOptions, TerminalsSharedState, createTerminalsDevframe, terminals as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { n as terminals, t as createTerminalsDevframe } from "./src-Cu5HYNrI.mjs";
|
|
2
|
+
import { DEFAULT_PORT, PLUGIN_ID, PRESETS_STATE_KEY, SESSIONS_STATE_KEY, TERMINAL_STREAM_CHANNEL } from "./constants.mjs";
|
|
3
|
+
export { DEFAULT_PORT, PLUGIN_ID, PRESETS_STATE_KEY, SESSIONS_STATE_KEY, TERMINAL_STREAM_CHANNEL, createTerminalsDevframe, terminals as default };
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { SpawnRequest, TerminalMode, TerminalPreset, TerminalSessionInfo, TerminalsOptions } from "../types.mjs";
|
|
2
|
+
import { DevframeNodeContext } from "devframe/types";
|
|
3
|
+
import * as _$nostics from "nostics";
|
|
4
|
+
import { Diagnostic } from "nostics";
|
|
5
|
+
|
|
6
|
+
//#region src/node/manager.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Owns terminal session lifecycle: spawns PTY / piped backends, streams
|
|
9
|
+
* their output over the `devframes-plugin-terminals:output` channel (one
|
|
10
|
+
* stream per session, stable for the session's whole life so restarts reuse
|
|
11
|
+
* the same id), and mirrors a serializable session list into shared state.
|
|
12
|
+
*/
|
|
13
|
+
declare class TerminalManager {
|
|
14
|
+
private ctx;
|
|
15
|
+
private options;
|
|
16
|
+
readonly shell: string;
|
|
17
|
+
readonly shellArgs: string[];
|
|
18
|
+
readonly defaultCwd: string;
|
|
19
|
+
readonly defaultMode: TerminalMode;
|
|
20
|
+
readonly allowArbitraryCommands: boolean;
|
|
21
|
+
readonly presets: TerminalPreset[];
|
|
22
|
+
private channel;
|
|
23
|
+
private sessionsState?;
|
|
24
|
+
private sessions;
|
|
25
|
+
private ptyAvailable;
|
|
26
|
+
/** Session ids this manager has registered into the hub (when hubbed). */
|
|
27
|
+
private hubOwned;
|
|
28
|
+
constructor(ctx: DevframeNodeContext, options?: TerminalsOptions);
|
|
29
|
+
/** Resolve shared state, probe the PTY backend, publish the preset catalog. */
|
|
30
|
+
init(): Promise<void>;
|
|
31
|
+
/** The hub's terminals subsystem when mounted in a hub, else undefined. */
|
|
32
|
+
private hubTerminals;
|
|
33
|
+
list(): TerminalSessionInfo[];
|
|
34
|
+
getPresets(): TerminalPreset[];
|
|
35
|
+
private buildEnv;
|
|
36
|
+
private resolveSpawn;
|
|
37
|
+
/**
|
|
38
|
+
* Spawn a session and return its descriptor immediately. The OS process
|
|
39
|
+
* is launched in the background and streams into the session's stream as
|
|
40
|
+
* soon as it produces output; clients can subscribe by id right away.
|
|
41
|
+
*/
|
|
42
|
+
spawn(req?: SpawnRequest): TerminalSessionInfo;
|
|
43
|
+
private launch;
|
|
44
|
+
/**
|
|
45
|
+
* Poll the PTY foreground process name and reflect changes (e.g. `bash`
|
|
46
|
+
* → `vim` → `bash`) into the session info. The interval is `unref`'d so
|
|
47
|
+
* it never keeps the process alive on its own.
|
|
48
|
+
*/
|
|
49
|
+
private startProcessPoll;
|
|
50
|
+
private stopProcessPoll;
|
|
51
|
+
write(id: string, data: string): void;
|
|
52
|
+
resize(id: string, cols: number, rows: number): void;
|
|
53
|
+
/** Stop the process but keep the session (and its stream) around. */
|
|
54
|
+
terminate(id: string): void;
|
|
55
|
+
/** Set a custom display name. Pass an empty string to clear it. */
|
|
56
|
+
rename(id: string, title: string): void;
|
|
57
|
+
/** Restart the session's command in place, reusing the same stream id. */
|
|
58
|
+
restart(id: string): TerminalSessionInfo;
|
|
59
|
+
/** Kill the process, close the stream, and drop the session. */
|
|
60
|
+
remove(id: string): void;
|
|
61
|
+
/** Tear everything down — used on server shutdown and in tests. */
|
|
62
|
+
dispose(): void;
|
|
63
|
+
private publish;
|
|
64
|
+
/**
|
|
65
|
+
* Push the current session list (own + aggregated hub sessions) into shared
|
|
66
|
+
* state. Kept separate from {@link publish} so the hub-session listener can
|
|
67
|
+
* refresh without re-running {@link syncHub} (which would re-emit hub events
|
|
68
|
+
* and loop).
|
|
69
|
+
*/
|
|
70
|
+
private refreshSessionsState;
|
|
71
|
+
/**
|
|
72
|
+
* Reflect the live session list into the hub's terminals subsystem when this
|
|
73
|
+
* devframe is mounted in a hub. `ctx.terminals` only exists on a
|
|
74
|
+
* `DevframeHubContext`, so it's accessed by duck-typing — standalone runtimes
|
|
75
|
+
* (CLI / Vite / build) have no such property and skip silently. This is what
|
|
76
|
+
* surfaces the plugin's sessions in the hub's own terminals panel.
|
|
77
|
+
*/
|
|
78
|
+
private syncHub;
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/node/backend.d.ts
|
|
82
|
+
/**
|
|
83
|
+
* Whether real pseudo-terminals are available in this runtime — i.e. zigpty's
|
|
84
|
+
* native bindings loaded. Without them interactive sessions still run through
|
|
85
|
+
* zigpty's pipe-based emulation, with degraded TUI fidelity.
|
|
86
|
+
*/
|
|
87
|
+
declare function isPtyAvailable(): Promise<boolean>;
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/node/context.d.ts
|
|
90
|
+
declare function setTerminalManager(ctx: DevframeNodeContext, manager: TerminalManager): void;
|
|
91
|
+
declare function getTerminalManager(ctx: DevframeNodeContext): TerminalManager;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/node/diagnostics.d.ts
|
|
94
|
+
interface ReporterOptions {
|
|
95
|
+
method?: 'log' | 'warn' | 'error';
|
|
96
|
+
}
|
|
97
|
+
declare function reporter(d: Diagnostic, {
|
|
98
|
+
method
|
|
99
|
+
}?: ReporterOptions): void;
|
|
100
|
+
/**
|
|
101
|
+
* Structured diagnostics for the terminals plugin. Uses the plugin's own
|
|
102
|
+
* `DP_TERMINALS_` prefix per the built-in plugin convention, keeping it
|
|
103
|
+
* collision-free with devframe core (`DF`) and the hub (`DF8xxx`).
|
|
104
|
+
*/
|
|
105
|
+
declare const diagnostics: _$nostics.Diagnostics<{
|
|
106
|
+
readonly DP_TERMINALS_0001: {
|
|
107
|
+
readonly why: (p: {
|
|
108
|
+
id: string;
|
|
109
|
+
}) => string;
|
|
110
|
+
readonly fix: "Spawn a session first, or refresh the session list.";
|
|
111
|
+
};
|
|
112
|
+
readonly DP_TERMINALS_0002: {
|
|
113
|
+
readonly why: (p: {
|
|
114
|
+
command: string;
|
|
115
|
+
}) => string;
|
|
116
|
+
readonly fix: "Add it to `presets`, or pass `allowArbitraryCommands: true` to createTerminalsDevframe().";
|
|
117
|
+
};
|
|
118
|
+
readonly DP_TERMINALS_0003: {
|
|
119
|
+
readonly why: (p: {
|
|
120
|
+
id: string;
|
|
121
|
+
}) => string;
|
|
122
|
+
readonly fix: "Spawn the session with `mode: \"interactive\"` to accept input.";
|
|
123
|
+
};
|
|
124
|
+
readonly DP_TERMINALS_0004: {
|
|
125
|
+
readonly why: (p: {
|
|
126
|
+
command: string;
|
|
127
|
+
reason: string;
|
|
128
|
+
}) => string;
|
|
129
|
+
};
|
|
130
|
+
readonly DP_TERMINALS_0005: {
|
|
131
|
+
readonly why: "Native PTY bindings (zigpty) are unavailable; interactive sessions fall back to pipe-based terminal emulation. Full-screen TUIs may not render correctly.";
|
|
132
|
+
readonly fix: "Check that this platform is covered by zigpty's prebuilds (Linux/macOS/Windows, x64/arm64, glibc/musl) and that the dependency installed intact.";
|
|
133
|
+
};
|
|
134
|
+
readonly DP_TERMINALS_0006: {
|
|
135
|
+
readonly why: (p: {
|
|
136
|
+
id: string;
|
|
137
|
+
}) => string;
|
|
138
|
+
};
|
|
139
|
+
readonly DP_TERMINALS_0007: {
|
|
140
|
+
readonly why: "Terminals manager is not initialised on this context";
|
|
141
|
+
readonly fix: "Call setupTerminals(ctx) (or use createTerminalsDevframe) before invoking terminal RPCs.";
|
|
142
|
+
};
|
|
143
|
+
}, readonly [typeof reporter]>;
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/node/index.d.ts
|
|
146
|
+
/**
|
|
147
|
+
* Wire the terminals subsystem onto a devframe node context: create the
|
|
148
|
+
* {@link TerminalManager}, publish presets + the session list into shared
|
|
149
|
+
* state, and register the control RPC functions. Returns the manager so
|
|
150
|
+
* callers can spawn sessions or dispose it on shutdown.
|
|
151
|
+
*
|
|
152
|
+
* Works in any devframe runtime (CLI, Vite, build) — it only depends on the
|
|
153
|
+
* core `ctx.rpc` streaming + shared-state surface, not on the hub.
|
|
154
|
+
*/
|
|
155
|
+
declare function setupTerminals(ctx: DevframeNodeContext, options?: TerminalsOptions): Promise<TerminalManager>;
|
|
156
|
+
//#endregion
|
|
157
|
+
export { TerminalManager, diagnostics, getTerminalManager, isPtyAvailable, setTerminalManager, setupTerminals };
|