@eserstack/noskills-web 0.0.0-stage → 5.0.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 +13 -0
- package/README.md +247 -2
- package/dist/auth.d.ts +50 -0
- package/dist/auth.js +107 -0
- package/dist/mod.d.ts +13 -0
- package/dist/mod.js +11 -0
- package/dist/request-context.d.ts +35 -0
- package/dist/request-context.js +19 -0
- package/dist/routes/api.d.ts +45 -0
- package/dist/routes/api.js +167 -0
- package/dist/routes/pages.d.ts +20 -0
- package/dist/routes/pages.js +80 -0
- package/dist/routes/sse.d.ts +15 -0
- package/dist/routes/sse.js +61 -0
- package/dist/routes/static.d.ts +10 -0
- package/dist/routes/static.js +52 -0
- package/dist/server.d.ts +53 -0
- package/dist/server.js +228 -0
- package/dist/static/client.js +257 -0
- package/dist/static/icons/icon.svg +12 -0
- package/dist/static/manifest.json +17 -0
- package/dist/static/mux-remote.js +192 -0
- package/dist/static/mux-render.js +224 -0
- package/dist/static/style.css +391 -0
- package/dist/static/sw-register.js +31 -0
- package/dist/static/sw.js +109 -0
- package/dist/templates/components.d.ts +17 -0
- package/dist/templates/components.js +89 -0
- package/dist/templates/dashboard.d.ts +8 -0
- package/dist/templates/dashboard.js +28 -0
- package/dist/templates/escape.d.ts +8 -0
- package/dist/templates/escape.js +14 -0
- package/dist/templates/layout.d.ts +12 -0
- package/dist/templates/layout.js +83 -0
- package/dist/templates/spec-detail.d.ts +7 -0
- package/dist/templates/spec-detail.js +83 -0
- package/dist/terminal/mux-host.d.ts +65 -0
- package/dist/terminal/mux-host.js +166 -0
- package/dist/terminal/ws-bridge.d.ts +9 -0
- package/dist/terminal/ws-bridge.js +26 -0
- package/package.json +32 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content-Security-Policy for every HTML page. Scripts run only from this
|
|
3
|
+
* origin and the pinned CDN files above; there are no inline scripts. Inline
|
|
4
|
+
* styles stay allowed because components and xterm set them.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PAGE_CSP: string;
|
|
7
|
+
/** Response headers for an HTML page. */
|
|
8
|
+
export declare const htmlHeaders: () => Record<string, string>;
|
|
9
|
+
export declare const layout: (title: string, body: string, opts?: {
|
|
10
|
+
includeTerminal?: boolean;
|
|
11
|
+
token?: string;
|
|
12
|
+
}) => string;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Base HTML layout — wraps all pages.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import * as escape from "./escape.js";
|
|
8
|
+
// The dashboard page carries the mux token, which can spawn PTYs, so every
|
|
9
|
+
// third-party file it loads is pinned by content. The digests are SHA-384 of
|
|
10
|
+
// the exact npm release bytes (xterm@5.3.0, xterm-addon-web-links@0.9.0),
|
|
11
|
+
// which jsDelivr serves unchanged; a changed file fails to load instead of
|
|
12
|
+
// running. To upgrade, recompute with:
|
|
13
|
+
// openssl dgst -sha384 -binary <file> | openssl base64 -A
|
|
14
|
+
const XTERM_CDN = "https://cdn.jsdelivr.net/npm";
|
|
15
|
+
const XTERM_CSS = {
|
|
16
|
+
href: `${XTERM_CDN}/xterm@5.3.0/css/xterm.css`,
|
|
17
|
+
integrity: "sha384-LJcOxlx9IMbNXDqJ2axpfEQKkAYbFjJfhXexLfiRJhjDU81mzgkiQq8rkV0j6dVh",
|
|
18
|
+
};
|
|
19
|
+
const XTERM_SCRIPTS = [
|
|
20
|
+
{
|
|
21
|
+
src: `${XTERM_CDN}/xterm@5.3.0/lib/xterm.js`,
|
|
22
|
+
integrity: "sha384-/nfmYPUzWMS6v2atn8hbljz7NE0EI1iGx34lJaNzyVjWGDzMv+ciUZUeJpKA3Glc",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
src: `${XTERM_CDN}/xterm-addon-web-links@0.9.0/lib/xterm-addon-web-links.js`,
|
|
26
|
+
integrity: "sha384-U4fBROT3kCM582gaYiNaOSQiJbXPzd9SfR1598Y7yeGSYVBzikXrNg0XyuU+mOnl",
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
/**
|
|
30
|
+
* Content-Security-Policy for every HTML page. Scripts run only from this
|
|
31
|
+
* origin and the pinned CDN files above; there are no inline scripts. Inline
|
|
32
|
+
* styles stay allowed because components and xterm set them.
|
|
33
|
+
*/
|
|
34
|
+
export const PAGE_CSP = [
|
|
35
|
+
"default-src 'self'",
|
|
36
|
+
`script-src 'self' ${XTERM_CDN}/`,
|
|
37
|
+
`style-src 'self' 'unsafe-inline' ${XTERM_CDN}/`,
|
|
38
|
+
"img-src 'self' data:",
|
|
39
|
+
"connect-src 'self' ws: wss:",
|
|
40
|
+
"object-src 'none'",
|
|
41
|
+
"base-uri 'none'",
|
|
42
|
+
"frame-ancestors 'none'",
|
|
43
|
+
"form-action 'self'",
|
|
44
|
+
].join("; ");
|
|
45
|
+
/** Response headers for an HTML page. */
|
|
46
|
+
export const htmlHeaders = () => ({
|
|
47
|
+
"content-type": "text/html; charset=utf-8",
|
|
48
|
+
"content-security-policy": PAGE_CSP,
|
|
49
|
+
});
|
|
50
|
+
export const layout = (title, body, opts) => {
|
|
51
|
+
// The per-process token, handed to the browser the only way it can legally
|
|
52
|
+
// obtain one: by loading a page from an allowed origin. client.js reads it
|
|
53
|
+
// from here for the /mux upgrade and for every mutating fetch.
|
|
54
|
+
const tokenMeta = opts?.token === undefined
|
|
55
|
+
? ""
|
|
56
|
+
: `\n <meta name="noskills-token" content="${escape.escHtml(opts.token)}" />`;
|
|
57
|
+
const terminalScripts = opts?.includeTerminal === true
|
|
58
|
+
? `
|
|
59
|
+
<link rel="stylesheet" href="${XTERM_CSS.href}" integrity="${XTERM_CSS.integrity}" crossorigin="anonymous" />${XTERM_SCRIPTS.map((s) => `\n <script src="${s.src}" integrity="${s.integrity}" crossorigin="anonymous"></script>`).join("")}`
|
|
60
|
+
: "";
|
|
61
|
+
return `<!DOCTYPE html>
|
|
62
|
+
<html lang="en">
|
|
63
|
+
<head>
|
|
64
|
+
<meta charset="utf-8" />
|
|
65
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
66
|
+
<meta name="theme-color" content="#7c3aed" />${tokenMeta}
|
|
67
|
+
<title>${escape.escHtml(title)}</title>
|
|
68
|
+
<link rel="manifest" href="/manifest.json" />
|
|
69
|
+
<link rel="stylesheet" href="/static/style.css" />
|
|
70
|
+
${terminalScripts}
|
|
71
|
+
</head>
|
|
72
|
+
<body>
|
|
73
|
+
<header class="top-bar">
|
|
74
|
+
<a href="/" class="logo">noskills</a>
|
|
75
|
+
<span class="user-info" id="user-info"></span>
|
|
76
|
+
</header>
|
|
77
|
+
${body}
|
|
78
|
+
<script src="/static/mux-render.js"></script>
|
|
79
|
+
<script src="/static/client.js"></script>
|
|
80
|
+
<script src="/static/sw-register.js"></script>
|
|
81
|
+
</body>
|
|
82
|
+
</html>`;
|
|
83
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spec detail view — readable spec with inline CTAs.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type * as dashboard from "@eserstack/noskills/dashboard";
|
|
7
|
+
export declare const renderSpecDetail: (spec: dashboard.SpecSummary, specContent: string, _currentUser: dashboard.User | null, token?: string) => string;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
import * as layout from "./layout.js";
|
|
3
|
+
import * as components from "./components.js";
|
|
4
|
+
import * as escape from "./escape.js";
|
|
5
|
+
export const renderSpecDetail = (spec, specContent, _currentUser, token) => {
|
|
6
|
+
// Phase-specific CTAs. Each action must be one routes/api.ts handles.
|
|
7
|
+
// SPEC_APPROVED has none: the dashboard layer has no action that starts
|
|
8
|
+
// execution, so it starts from the agent (`noskills spec <name> next`).
|
|
9
|
+
const ctas = [];
|
|
10
|
+
if (spec.phase === "SPEC_PROPOSAL") {
|
|
11
|
+
ctas.push(components.ctaButton("Approve Spec", spec.slug, "approve"));
|
|
12
|
+
}
|
|
13
|
+
if (spec.phase === "EXECUTING") {
|
|
14
|
+
ctas.push(components.ctaButton("Mark Complete", spec.slug, "complete"));
|
|
15
|
+
}
|
|
16
|
+
// Always show note/question buttons for active specs
|
|
17
|
+
if (spec.phase !== "COMPLETED" &&
|
|
18
|
+
spec.phase !== "IDLE" &&
|
|
19
|
+
spec.phase !== "UNINITIALIZED") {
|
|
20
|
+
ctas.push(components.ctaButton("Add Note", spec.slug, "note"));
|
|
21
|
+
ctas.push(components.ctaButton("Ask Question", spec.slug, "question"));
|
|
22
|
+
}
|
|
23
|
+
// Pending questions
|
|
24
|
+
const questionsHtml = spec.pendingQuestions.length > 0
|
|
25
|
+
? `<div class="questions-section">
|
|
26
|
+
<h3>Open Questions</h3>
|
|
27
|
+
${spec.pendingQuestions
|
|
28
|
+
.map((q) => `<div class="question-item">
|
|
29
|
+
<strong>${escape.escHtml(q.user)}</strong>: ${escape.escHtml(q.text)}
|
|
30
|
+
${components.ctaButton("Reply", spec.slug, "reply", {
|
|
31
|
+
"question-id": q.id,
|
|
32
|
+
})}
|
|
33
|
+
</div>`)
|
|
34
|
+
.join("")}
|
|
35
|
+
</div>`
|
|
36
|
+
: "";
|
|
37
|
+
// Task list
|
|
38
|
+
const tasksHtml = spec.tasks.length > 0
|
|
39
|
+
? `<div class="tasks-section">
|
|
40
|
+
<h3>Tasks (${spec.tasks.filter((t) => t.done).length}/${spec.tasks.length})</h3>
|
|
41
|
+
<ul class="task-list">
|
|
42
|
+
${spec.tasks
|
|
43
|
+
.map((t) => `<li class="${t.done ? "done" : ""}">
|
|
44
|
+
<input type="checkbox" ${t.done ? "checked" : ""} disabled />
|
|
45
|
+
<span>${escape.escHtml(t.id)}: ${escape.escHtml(t.description)}</span>
|
|
46
|
+
${t.files !== undefined && t.files.length > 0
|
|
47
|
+
? `<span class="file-hints">${t.files
|
|
48
|
+
.map((f) => `<code>${escape.escHtml(f)}</code>`)
|
|
49
|
+
.join(", ")}</span>`
|
|
50
|
+
: ""}
|
|
51
|
+
</li>`)
|
|
52
|
+
.join("")}
|
|
53
|
+
</ul>
|
|
54
|
+
</div>`
|
|
55
|
+
: "";
|
|
56
|
+
// Spec markdown content
|
|
57
|
+
const specHtml = specContent.length > 0
|
|
58
|
+
? `<div class="spec-content"><pre>${escape.escHtml(specContent)}</pre></div>`
|
|
59
|
+
: "";
|
|
60
|
+
const ctaBar = ctas.length > 0 ? `<div class="cta-bar">${ctas.join("")}</div>` : "";
|
|
61
|
+
const body = `
|
|
62
|
+
<div class="spec-detail">
|
|
63
|
+
<div class="spec-header">
|
|
64
|
+
<a href="/" class="back-link">← All Specs</a>
|
|
65
|
+
<h1>${escape.escHtml(spec.name)} ${components.phaseBadge(spec.phase)}</h1>
|
|
66
|
+
<p class="spec-description">${escape.escHtml(spec.description)}</p>
|
|
67
|
+
<div class="roadmap">${escape.escHtml(spec.roadmap)}</div>
|
|
68
|
+
${ctaBar}
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
${tasksHtml}
|
|
72
|
+
${questionsHtml}
|
|
73
|
+
${specHtml}
|
|
74
|
+
|
|
75
|
+
${spec.contributors.length > 0
|
|
76
|
+
? `<div class="contributors">Contributors: ${spec.contributors
|
|
77
|
+
.map((n) => escape.escHtml(n))
|
|
78
|
+
.join(", ")}</div>`
|
|
79
|
+
: ""}
|
|
80
|
+
</div>`;
|
|
81
|
+
// The token lets the action buttons pass the guard on mutating requests.
|
|
82
|
+
return layout.layout(`${spec.name} — noskills`, body, { token });
|
|
83
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mux host for the web frontend.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the old single-PTY-per-tab `PtyManager` with a single mux server
|
|
5
|
+
* that owns every tab, pane, and PTY. The browser attaches one WebSocket
|
|
6
|
+
* carrying the neutral mux protocol (scene + per-pane output in, actions out)
|
|
7
|
+
* and renders the whole scene, so the web view is another mux frontend with
|
|
8
|
+
* the same feed as the ANSI TUI.
|
|
9
|
+
*
|
|
10
|
+
* noskills-specific glue stays here: session persistence, spec↔tab binding, and
|
|
11
|
+
* notifying the pane bound to a spec via the `writeToPane` action. Session
|
|
12
|
+
* creation and the agent spawn resolver are shared with the TUI manager via
|
|
13
|
+
* `@eserstack/noskills/session`.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import * as mux from "@eserstack/mux";
|
|
18
|
+
/** Per-tab noskills metadata, keyed by the mux tab id. */
|
|
19
|
+
export type WebTab = {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly specName: string | null;
|
|
22
|
+
readonly sessionId: string;
|
|
23
|
+
};
|
|
24
|
+
/** Options for {@link MuxHost}; the seams let tests avoid real PTYs and the
|
|
25
|
+
* native `where`/`which` agent discovery (both go through the ajan FFI). */
|
|
26
|
+
export type MuxHostOptions = {
|
|
27
|
+
readonly createHost?: (cb: mux.PtyHostCallbacks) => mux.PtyHost;
|
|
28
|
+
/** Override agent-binary discovery (defaults to the claude-code adapter). */
|
|
29
|
+
readonly resolveCommand?: () => Promise<string>;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Owns the web multiplexer: one mux server for every tab, pane and PTY, plus
|
|
33
|
+
* the noskills session and the optional spec bound to each tab.
|
|
34
|
+
*/
|
|
35
|
+
export declare class MuxHost {
|
|
36
|
+
#private;
|
|
37
|
+
/** Create the host for the project at `root`; no tab is open yet. */
|
|
38
|
+
constructor(root: string, opts?: MuxHostOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Connect a browser WebSocket to the multiplexer: the server streams the
|
|
41
|
+
* scene and the pane output to it, and acts on the frames it sends.
|
|
42
|
+
*
|
|
43
|
+
* Every inbound frame passes the remote sanitizer first, so a frame cannot
|
|
44
|
+
* pick the command, arguments or working directory of a new pane. One socket
|
|
45
|
+
* is connected at a time: a newer one replaces it and closes it. A closed
|
|
46
|
+
* socket stops delivery, and the panes keep running for the next one.
|
|
47
|
+
*
|
|
48
|
+
* The caller authenticates the socket before it attaches it.
|
|
49
|
+
*
|
|
50
|
+
* @param socket - The server end of an accepted WebSocket upgrade
|
|
51
|
+
*/
|
|
52
|
+
attachSocket(socket: WebSocket): void;
|
|
53
|
+
/** Create a tab running a coding agent, optionally bound to a spec. */
|
|
54
|
+
createTab(specName?: string): Promise<WebTab>;
|
|
55
|
+
/** Close a specific tab by mux id without moving the user's active tab. */
|
|
56
|
+
closeTab(tabId: string): void;
|
|
57
|
+
/** The tab bound to a spec, if any. */
|
|
58
|
+
findTabBySpec(specName: string): WebTab | undefined;
|
|
59
|
+
/** Write a notification into the pane currently focused in a spec's tab. */
|
|
60
|
+
notifySpec(specName: string, text: string): boolean;
|
|
61
|
+
/** All open tabs (for the server-rendered dashboard shell). */
|
|
62
|
+
listTabs(): readonly WebTab[];
|
|
63
|
+
/** Tear down every pane/PTY and persisted session. */
|
|
64
|
+
killAll(): Promise<void>;
|
|
65
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Mux host for the web frontend.
|
|
4
|
+
*
|
|
5
|
+
* Replaces the old single-PTY-per-tab `PtyManager` with a single mux server
|
|
6
|
+
* that owns every tab, pane, and PTY. The browser attaches one WebSocket
|
|
7
|
+
* carrying the neutral mux protocol (scene + per-pane output in, actions out)
|
|
8
|
+
* and renders the whole scene, so the web view is another mux frontend with
|
|
9
|
+
* the same feed as the ANSI TUI.
|
|
10
|
+
*
|
|
11
|
+
* noskills-specific glue stays here: session persistence, spec↔tab binding, and
|
|
12
|
+
* notifying the pane bound to a spec via the `writeToPane` action. Session
|
|
13
|
+
* creation and the agent spawn resolver are shared with the TUI manager via
|
|
14
|
+
* `@eserstack/noskills/session`.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
import * as mux from "@eserstack/mux";
|
|
19
|
+
import * as agents from "@eserstack/agents";
|
|
20
|
+
import * as persistence from "@eserstack/noskills/persistence";
|
|
21
|
+
import * as sessionBinding from "@eserstack/noskills/session";
|
|
22
|
+
/**
|
|
23
|
+
* Owns the web multiplexer: one mux server for every tab, pane and PTY, plus
|
|
24
|
+
* the noskills session and the optional spec bound to each tab.
|
|
25
|
+
*/
|
|
26
|
+
export class MuxHost {
|
|
27
|
+
#root;
|
|
28
|
+
/** The mux server behind every tab; {@link attachSocket} connects to it. */
|
|
29
|
+
#server;
|
|
30
|
+
#adapter = agents.getAgentAdapter("claude-code") ?? agents.defaultAgentAdapter();
|
|
31
|
+
/** mux tab id → noskills tab metadata. */
|
|
32
|
+
#tabs = new Map();
|
|
33
|
+
#resolveCommandOverride;
|
|
34
|
+
#command = null;
|
|
35
|
+
/** Create the host for the project at `root`; no tab is open yet. */
|
|
36
|
+
constructor(root, opts = {}) {
|
|
37
|
+
this.#root = root;
|
|
38
|
+
this.#resolveCommandOverride = opts.resolveCommand;
|
|
39
|
+
this.#server = mux.createServer({
|
|
40
|
+
// The browser draws its own tab bar and chrome in HTML, so the mux
|
|
41
|
+
// viewport reserves nothing — panes fill the grid the browser reports.
|
|
42
|
+
initialState: mux.engine.createInitialState({ cols: 120, rows: 40 }),
|
|
43
|
+
resolveSpawn: sessionBinding.buildAgentSpawnResolver(root),
|
|
44
|
+
chrome: { tabBarRows: 0, statusBarRows: 0 },
|
|
45
|
+
createHost: opts.createHost,
|
|
46
|
+
// The web mux server outlives any single tab; closing the last one leaves
|
|
47
|
+
// an empty multiplexer the browser can repopulate with "+".
|
|
48
|
+
exitOnEmpty: false,
|
|
49
|
+
// A pane exiting on its own (agent quit) closes its tab; reconcile so the
|
|
50
|
+
// persisted session is deleted promptly, not just on the next read.
|
|
51
|
+
onPaneExit: () => this.#reconcile(),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Connect a browser WebSocket to the multiplexer: the server streams the
|
|
56
|
+
* scene and the pane output to it, and acts on the frames it sends.
|
|
57
|
+
*
|
|
58
|
+
* Every inbound frame passes the remote sanitizer first, so a frame cannot
|
|
59
|
+
* pick the command, arguments or working directory of a new pane. One socket
|
|
60
|
+
* is connected at a time: a newer one replaces it and closes it. A closed
|
|
61
|
+
* socket stops delivery, and the panes keep running for the next one.
|
|
62
|
+
*
|
|
63
|
+
* The caller authenticates the socket before it attaches it.
|
|
64
|
+
*
|
|
65
|
+
* @param socket - The server end of an accepted WebSocket upgrade
|
|
66
|
+
*/
|
|
67
|
+
attachSocket(socket) {
|
|
68
|
+
const transport = mux.engine.sanitizeRemoteTransport(mux.wsTransport(socket, {
|
|
69
|
+
onClose: () => this.#server.disconnect(transport),
|
|
70
|
+
}));
|
|
71
|
+
this.#server.connect(transport);
|
|
72
|
+
}
|
|
73
|
+
/** Drop bindings whose mux tab has gone away (pane exited / tab closed). */
|
|
74
|
+
#reconcile() {
|
|
75
|
+
const live = new Set(this.#server.getState().tabs.map((t) => t.id));
|
|
76
|
+
for (const id of [...this.#tabs.keys()]) {
|
|
77
|
+
if (!live.has(id)) {
|
|
78
|
+
const tab = this.#tabs.get(id);
|
|
79
|
+
this.#tabs.delete(id);
|
|
80
|
+
persistence.deleteSession(this.#root, tab.sessionId).catch(() => { });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async #resolveCommand() {
|
|
85
|
+
if (this.#command === null) {
|
|
86
|
+
this.#command =
|
|
87
|
+
this.#resolveCommandOverride !== undefined
|
|
88
|
+
? await this.#resolveCommandOverride()
|
|
89
|
+
: ((await this.#adapter.resolveCommand()) ?? "claude");
|
|
90
|
+
}
|
|
91
|
+
return this.#command;
|
|
92
|
+
}
|
|
93
|
+
/** Create a tab running a coding agent, optionally bound to a spec. */
|
|
94
|
+
async createTab(specName) {
|
|
95
|
+
// Reuse the canonical session factories (spec-bound loads the live phase).
|
|
96
|
+
const binding = specName !== undefined
|
|
97
|
+
? await sessionBinding.createSpecSession(this.#root, specName, "web")
|
|
98
|
+
: await sessionBinding.createFreeSession(this.#root, "web");
|
|
99
|
+
const command = await this.#resolveCommand();
|
|
100
|
+
this.#server.dispatch({
|
|
101
|
+
type: "newTab",
|
|
102
|
+
command,
|
|
103
|
+
cwd: this.#root,
|
|
104
|
+
title: binding.spec ?? "free",
|
|
105
|
+
meta: { sessionId: binding.sessionId },
|
|
106
|
+
});
|
|
107
|
+
// The newest tab is now active.
|
|
108
|
+
const state = this.#server.getState();
|
|
109
|
+
const muxTab = state.tabs[state.activeTab];
|
|
110
|
+
const tab = {
|
|
111
|
+
id: muxTab.id,
|
|
112
|
+
specName: binding.spec,
|
|
113
|
+
sessionId: binding.sessionId,
|
|
114
|
+
};
|
|
115
|
+
this.#tabs.set(tab.id, tab);
|
|
116
|
+
return tab;
|
|
117
|
+
}
|
|
118
|
+
/** Close a specific tab by mux id without moving the user's active tab. */
|
|
119
|
+
closeTab(tabId) {
|
|
120
|
+
const idx = this.#server.getState().tabs.findIndex((t) => t.id === tabId);
|
|
121
|
+
if (idx < 0)
|
|
122
|
+
return;
|
|
123
|
+
this.#server.dispatch({ type: "closeTab", index: idx });
|
|
124
|
+
this.#reconcile();
|
|
125
|
+
}
|
|
126
|
+
/** The tab bound to a spec, if any. */
|
|
127
|
+
findTabBySpec(specName) {
|
|
128
|
+
this.#reconcile();
|
|
129
|
+
for (const tab of this.#tabs.values()) {
|
|
130
|
+
if (tab.specName === specName)
|
|
131
|
+
return tab;
|
|
132
|
+
}
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
/** Write a notification into the pane currently focused in a spec's tab. */
|
|
136
|
+
notifySpec(specName, text) {
|
|
137
|
+
const tab = this.findTabBySpec(specName);
|
|
138
|
+
if (tab === undefined)
|
|
139
|
+
return false;
|
|
140
|
+
// Resolve the live pane from the tab — the original pane may have been
|
|
141
|
+
// replaced by a split/promotion, so a cached pane id could be stale.
|
|
142
|
+
const muxTab = this.#server.getState().tabs.find((t) => t.id === tab.id);
|
|
143
|
+
if (muxTab === undefined)
|
|
144
|
+
return false;
|
|
145
|
+
this.#server.dispatch({
|
|
146
|
+
type: "writeToPane",
|
|
147
|
+
pane: muxTab.focusedPane,
|
|
148
|
+
data: text,
|
|
149
|
+
});
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
/** All open tabs (for the server-rendered dashboard shell). */
|
|
153
|
+
listTabs() {
|
|
154
|
+
this.#reconcile();
|
|
155
|
+
return [...this.#tabs.values()];
|
|
156
|
+
}
|
|
157
|
+
/** Tear down every pane/PTY and persisted session. */
|
|
158
|
+
async killAll() {
|
|
159
|
+
const sessions = [...this.#tabs.values()].map((t) => t.sessionId);
|
|
160
|
+
this.#tabs.clear();
|
|
161
|
+
await this.#server.dispose();
|
|
162
|
+
// Each session is its own file, so the removals are independent and run
|
|
163
|
+
// together. deleteSession reports a failed removal as false, not a throw.
|
|
164
|
+
await Promise.all(sessions.map((id) => persistence.deleteSession(this.#root, id)));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MuxHost } from "./mux-host.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Handle a WebSocket upgrade and attach it to the mux server.
|
|
4
|
+
*
|
|
5
|
+
* The caller is responsible for authenticating the upgrade (see `../auth.ts`);
|
|
6
|
+
* by the time this runs the request has already cleared the Origin and token
|
|
7
|
+
* checks.
|
|
8
|
+
*/
|
|
9
|
+
export declare const handleMuxWs: (request: Request, host: MuxHost) => Response;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* WebSocket ↔ mux bridge.
|
|
4
|
+
*
|
|
5
|
+
* Upgrades a browser WebSocket and attaches it to the {@link MuxHost}, which
|
|
6
|
+
* speaks the neutral mux protocol over it: scene diffs and per-pane output go to
|
|
7
|
+
* the browser, and attach/resize/action messages come back. One socket carries
|
|
8
|
+
* the whole multiplexer (every tab and pane), not a single PTY.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { runtime } from "@eserstack/standards/cross-runtime";
|
|
13
|
+
/**
|
|
14
|
+
* Handle a WebSocket upgrade and attach it to the mux server.
|
|
15
|
+
*
|
|
16
|
+
* The caller is responsible for authenticating the upgrade (see `../auth.ts`);
|
|
17
|
+
* by the time this runs the request has already cleared the Origin and token
|
|
18
|
+
* checks.
|
|
19
|
+
*/
|
|
20
|
+
export const handleMuxWs = (request, host) => {
|
|
21
|
+
const { socket, response } = runtime.http.upgradeWebSocket(request);
|
|
22
|
+
// attachSocket registers its listeners synchronously, before the handler
|
|
23
|
+
// returns `response`, so no frame can arrive ahead of them.
|
|
24
|
+
host.attachSocket(socket);
|
|
25
|
+
return response;
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eserstack/noskills-web",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/eser/stack",
|
|
8
|
+
"directory": "pkg/@eserstack/noskills-web"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/**/*.js",
|
|
12
|
+
"dist/**/*.d.ts",
|
|
13
|
+
"dist/**/*.json",
|
|
14
|
+
"dist/static/"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/mod.d.ts",
|
|
19
|
+
"import": "./dist/mod.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@eserstack/agents": "5.0.0",
|
|
24
|
+
"@eserstack/logging": "5.0.0",
|
|
25
|
+
"@eserstack/mux": "5.0.0",
|
|
26
|
+
"@eserstack/noskills": "5.0.0",
|
|
27
|
+
"@eserstack/standards": "5.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@eserstack/test-kit": "5.0.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "node ../../../etc/scripts/build-library.ts --copy static"
|
|
34
|
+
}
|
|
6
35
|
}
|