@kowloonzh/dsh-tui 0.0.0-stage → 0.2.3-alpha.2.tui.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
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.
package/README.md CHANGED
@@ -1,3 +1,59 @@
1
- # Temporary Holding Version
1
+ # @kowloonzh/dsh-tui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A codex-style terminal frontend for [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness).
4
+
5
+ > Unofficial. Built and maintained by a community member, not by DeepSeek.
6
+
7
+ `dsh-tui` connects to the `web` profile Host over the public Client Remote contract. It
8
+ creates no profile of its own: sessions, models, tools, approvals, credentials, and plugins
9
+ are the web profile's, the same ones `dsh web` uses.
10
+
11
+ ## Install
12
+
13
+ Requires Node `^24.22.3 || >=26.13.1`.
14
+
15
+ ```sh
16
+ npm install -g @kowloonzh/dsh-tui
17
+ dsh-tui
18
+ ```
19
+
20
+ The package depends on an exact release of [`@deepseek-ai/dsh`](https://www.npmjs.com/package/@deepseek-ai/dsh),
21
+ installed with it, and starts that release's Host. Each `dsh-tui` version is built and tested
22
+ against the Host version it pins; `npm ls -g @deepseek-ai/dsh` shows which one.
23
+
24
+ On an older Node, `npm install -g @kowloonzh/dsh-tui` stops with
25
+ `No matching version found for @kowloonzh/dsh-tui@*`: every release is a semver prerelease
26
+ (it follows the Host version, such as `0.2.3-alpha.2.tui.1`), and npm passes over `latest`
27
+ when its engine range excludes the running Node. Upgrade Node; `npm install -g
28
+ @kowloonzh/dsh-tui@latest` installs anyway, but the Host then runs on an unsupported Node.
29
+
30
+ ## Usage
31
+
32
+ ```sh
33
+ dsh-tui # start a lean local Host and open a new Session
34
+ dsh-tui --resume # open the newest Session
35
+ dsh-tui --resume <session-id> # open a named Session
36
+ dsh-tui --prompt '<task text>' # submit one task, exit when its turn ends
37
+ DSH_URL='http://127.0.0.1:3080/?token=...' dsh-tui # use a running dsh web Host
38
+ ```
39
+
40
+ Configure models and credentials the way `dsh web` expects them; `dsh-tui` reads the same
41
+ configuration under `$DSH_HOME` (default `~/.dsh`).
42
+
43
+ Inside the TUI, `/help` lists the commands and keys. Highlights:
44
+
45
+ - streaming Markdown with highlighted code and tables, compact tool cards (Ctrl+O expands them);
46
+ - tool approvals and `ask_user_question`;
47
+ - Enter steers a running turn, Ctrl+Enter interrupts and sends, Esc interrupts, Alt+Up recalls;
48
+ - slash completion for local commands, Host commands, and skills, plus `@path` completion;
49
+ - `/model` with reasoning effort, `/status` tabs (Status, Stats, Context), `/export`;
50
+ - reconnection after a Host restart when `DSH_URL_FILE` names the file holding the Host's URL.
51
+
52
+ ## Source
53
+
54
+ The code lives in `apps/tui` on the
55
+ [`feat/dsh-tui-profile`](https://github.com/kowloonzh/deepseek-harness/tree/feat/dsh-tui-profile/apps/tui)
56
+ branch of a fork of `deepseek-ai/deepseek-harness`, rebased onto each upstream release.
57
+ Issues: <https://github.com/kowloonzh/deepseek-harness/issues>.
58
+
59
+ MIT licensed; the bundle includes DeepSeek Harness code under its MIT license.
package/bin/dsh-tui.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+ // `dsh-tui`: the standalone package's executable. The TUI itself is the bundled module.
3
+ import { runStandalone } from '../lib/index.js'
4
+
5
+ process.exitCode = await runStandalone({
6
+ args: process.argv.slice(2),
7
+ execArgv: process.execArgv,
8
+ env: process.env,
9
+ })
@@ -0,0 +1,183 @@
1
+ import { brandString } from "@deepseek-ai/dsh-brand";
2
+ import { BlockAssembler, createUserMessage } from "@deepseek-ai/dsh-llm";
3
+ import { extractTextContent } from "@deepseek-ai/dsh-llm/message";
4
+ //#region lib/types/suggest.js
5
+ /** The Host command that returns a suggestion; the TUI hides it from menus and the transcript. */
6
+ const NEXT_PROMPT_COMMAND = "tui-next-prompt";
7
+ //#endregion
8
+ //#region lib/types/host/next-prompt.js
9
+ /**
10
+ * Host plugin behind the TUI's composer suggestion: after a turn, guess the operator's next
11
+ * message from the conversation.
12
+ *
13
+ * It runs inside the Host, which owns the model routes, and is reached through one Host command
14
+ * so the TUI needs no new Remote surface. The TUI hides that command from its menus and its
15
+ * transcript. The TUI writes this plugin into the Web profile patch, whose live reload loads it
16
+ * into a Host that is already running; `config:` under that entry overrides the defaults below.
17
+ */
18
+ const name = NEXT_PROMPT_COMMAND;
19
+ const inject = ["commands", "llm"];
20
+ const MAX_SUGGESTION_CHARS = 200;
21
+ const SYSTEM = [
22
+ "You predict what the user of an AI coding assistant will type next.",
23
+ "You get the recent conversation. Reply with only the single next message the user is most likely to send:",
24
+ "one short line in the language the user writes in, phrased as the user would type it, with no quotes,",
25
+ "prefix, explanation or Markdown. Prefer the concrete next step the assistant offered or asked about,",
26
+ "such as approving a proposal. If nothing natural follows, reply with an empty line."
27
+ ].join("\n");
28
+ const DEFAULTS = {
29
+ maxTokens: 200,
30
+ timeoutMs: 3e4,
31
+ maxTranscriptChars: 12e3
32
+ };
33
+ /**
34
+ * Standard Schema validator for {@link Config}, which the loader runs on the entry's `config:`.
35
+ * Written by hand: the TUI carries no schema library, and the shape is small.
36
+ */
37
+ const Config = { "~standard": {
38
+ version: 1,
39
+ vendor: "dsh-tui",
40
+ validate(value) {
41
+ if (value === void 0 || value === null) return { value: DEFAULTS };
42
+ if (typeof value !== "object" || Array.isArray(value)) return { issues: [{ message: "expected an object" }] };
43
+ const input = value;
44
+ const issues = [];
45
+ const text = (key) => {
46
+ const item = input[key];
47
+ if (item === void 0 || typeof item === "string" && item !== "") return item;
48
+ issues.push({
49
+ message: "expected a non-empty string",
50
+ path: [key]
51
+ });
52
+ };
53
+ const count = (key) => {
54
+ const item = input[key];
55
+ if (item === void 0) return DEFAULTS[key];
56
+ if (typeof item === "number" && Number.isInteger(item) && item > 0) return item;
57
+ issues.push({
58
+ message: "expected a positive integer",
59
+ path: [key]
60
+ });
61
+ return DEFAULTS[key];
62
+ };
63
+ const config = {
64
+ provider: text("provider"),
65
+ model: text("model"),
66
+ maxTokens: count("maxTokens"),
67
+ timeoutMs: count("timeoutMs"),
68
+ maxTranscriptChars: count("maxTranscriptChars")
69
+ };
70
+ if (config.provider === void 0 !== (config.model === void 0)) issues.push({
71
+ message: "set provider and model together",
72
+ path: [config.provider === void 0 ? "provider" : "model"]
73
+ });
74
+ return issues.length > 0 ? { issues } : { value: config };
75
+ }
76
+ } };
77
+ /**
78
+ * The recent conversation as plain text, newest last, cut to a bound from the front.
79
+ * @param messages - the Session's model-visible messages.
80
+ * @param maxChars - the most characters kept.
81
+ * @returns role-labelled lines.
82
+ */
83
+ function transcriptText(messages, maxChars = DEFAULTS.maxTranscriptChars) {
84
+ const lines = [];
85
+ for (const message of messages) {
86
+ if (message.role !== "user" && message.role !== "assistant") continue;
87
+ const text = extractTextContent(message.content, {
88
+ separator: "\n",
89
+ trim: true
90
+ });
91
+ if (text !== "") lines.push(`${message.role === "user" ? "User" : "Assistant"}: ${text}`);
92
+ }
93
+ const joined = lines.join("\n\n");
94
+ return joined.length <= maxChars ? joined : joined.slice(joined.length - maxChars);
95
+ }
96
+ /**
97
+ * The suggestion from model output: its first non-empty line, unquoted and bounded.
98
+ * @param text - the model's text.
99
+ * @returns one line, or '' when the model offered nothing.
100
+ */
101
+ function suggestionFromOutput(text) {
102
+ const unquoted = (text.split(/\r?\n/u).map((item) => item.trim()).find((item) => item !== "") ?? "").replace(/^["'“‘`]+|["'”’`]+$/gu, "").trim();
103
+ return Array.from(unquoted).slice(0, MAX_SUGGESTION_CHARS).join("");
104
+ }
105
+ /**
106
+ * Guess the next message of the invoking Session.
107
+ * @param ctx - Host context holding the LLM service.
108
+ * @param config - plugin options.
109
+ * @param invocation - the command call, carrying the Session's Agent.
110
+ * @returns the guess as the command's text; '' when there is nothing to go on.
111
+ */
112
+ async function suggest(ctx, config, { agent, signal }) {
113
+ const route = config.provider !== void 0 && config.model !== void 0 ? {
114
+ provider: config.provider,
115
+ model: config.model
116
+ } : agent.model.current();
117
+ const transcript = transcriptText(agent.session.deriveMessages(), config.maxTranscriptChars);
118
+ if (route === void 0 || transcript === "") return {
119
+ kind: "success",
120
+ text: ""
121
+ };
122
+ const timeout = AbortSignal.any([signal, AbortSignal.timeout(config.timeoutMs)]);
123
+ const call = await ctx.llm.prepareCall({
124
+ provider: route.provider,
125
+ model: route.model,
126
+ maxTokens: config.maxTokens
127
+ }, timeout, (controls, model) => {
128
+ const effort = model.reasoning?.efforts[0]?.id;
129
+ return effort === void 0 ? controls : {
130
+ ...controls,
131
+ reasoningEffort: effort
132
+ };
133
+ });
134
+ const assembler = new BlockAssembler();
135
+ for await (const chunk of call.stream({
136
+ ...call.config,
137
+ system: SYSTEM,
138
+ messages: [createUserMessage({
139
+ content: [{
140
+ type: "text",
141
+ text: `Conversation so far:\n\n${transcript}\n\nThe user's next message:`
142
+ }],
143
+ source: { kind: "user" }
144
+ })],
145
+ purpose: "tui-next-prompt",
146
+ signal: timeout
147
+ })) assembler.push(chunk);
148
+ return {
149
+ kind: "success",
150
+ text: suggestionFromOutput(extractTextContent(assembler.blocks(), { separator: "\n" }))
151
+ };
152
+ }
153
+ /**
154
+ * Register the suggestion command for this plugin's lifetime.
155
+ * @param ctx - Host context with the command registry and the LLM service.
156
+ * @param config - plugin options.
157
+ */
158
+ function apply(ctx, config = DEFAULTS) {
159
+ const active = /* @__PURE__ */ new Set();
160
+ const handler = (invocation) => {
161
+ const operation = suggest(ctx, config, invocation);
162
+ active.add(operation);
163
+ const retire = () => {
164
+ active.delete(operation);
165
+ };
166
+ operation.then(retire, retire);
167
+ return operation;
168
+ };
169
+ ctx.effect(function* () {
170
+ yield async () => {
171
+ await Promise.allSettled(active);
172
+ };
173
+ yield ctx.commands.register({
174
+ definitionId: brandString("@deepseek-ai/dsh-tui-next-prompt"),
175
+ name: NEXT_PROMPT_COMMAND,
176
+ description: "Suggest the next prompt for the TUI composer (used by dsh tui)",
177
+ recordInput: false,
178
+ handler
179
+ });
180
+ }, `${NEXT_PROMPT_COMMAND} lifecycle`);
181
+ }
182
+ //#endregion
183
+ export { Config, apply, inject, name, suggestionFromOutput, transcriptText };