skyloom 1.12.0 → 1.13.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/.github/workflows/ci.yml +36 -36
- package/README.md +142 -46
- package/config/default.yaml +43 -47
- package/config/models.yaml +155 -155
- package/config/providers.yaml +39 -39
- package/config/skills/api_integrator/SKILL.md +15 -15
- package/config/skills/arch_designer/SKILL.md +13 -13
- package/config/skills/ci_cd_manager/SKILL.md +14 -14
- package/config/skills/code_analysis/SKILL.md +13 -13
- package/config/skills/code_generator/SKILL.md +12 -12
- package/config/skills/code_reviewer/SKILL.md +13 -13
- package/config/skills/content_writer/SKILL.md +14 -14
- package/config/skills/data_transformer/SKILL.md +15 -15
- package/config/skills/document_analysis/SKILL.md +13 -13
- package/config/skills/emotional_companion/SKILL.md +15 -15
- package/config/skills/performance_checker/SKILL.md +14 -14
- package/config/skills/security_auditor/SKILL.md +14 -14
- package/config/skills/self_evolve/SKILL.md +13 -13
- package/config/skills/sys_operator/SKILL.md +15 -15
- package/config/skills/task_planner/SKILL.md +14 -14
- package/config/skills/web_research/SKILL.md +14 -14
- package/config/skills/workflow_designer/SKILL.md +13 -13
- package/dist/agents/dew.js +52 -52
- package/dist/agents/fair.js +84 -84
- package/dist/agents/fog.js +30 -30
- package/dist/agents/frost.js +32 -32
- package/dist/agents/rain.js +32 -32
- package/dist/agents/snow.js +68 -68
- package/dist/cli/main.js +103 -51
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/tui.d.ts.map +1 -1
- package/dist/cli/tui.js +8 -1
- package/dist/cli/tui.js.map +1 -1
- package/dist/core/agent/task.d.ts +58 -0
- package/dist/core/agent/task.d.ts.map +1 -0
- package/dist/core/agent/task.js +83 -0
- package/dist/core/agent/task.js.map +1 -0
- package/dist/core/agent.d.ts +2 -45
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +61 -145
- package/dist/core/agent.js.map +1 -1
- package/dist/core/agent_helpers.d.ts +10 -0
- package/dist/core/agent_helpers.d.ts.map +1 -1
- package/dist/core/agent_helpers.js +39 -0
- package/dist/core/agent_helpers.js.map +1 -1
- package/dist/core/catalog.d.ts +71 -0
- package/dist/core/catalog.d.ts.map +1 -0
- package/dist/core/catalog.js +176 -0
- package/dist/core/catalog.js.map +1 -0
- package/dist/core/config.d.ts +8 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +12 -4
- package/dist/core/config.js.map +1 -1
- package/dist/core/factory.js +16 -16
- package/dist/core/llm.d.ts +7 -0
- package/dist/core/llm.d.ts.map +1 -1
- package/dist/core/llm.js +139 -7
- package/dist/core/llm.js.map +1 -1
- package/dist/core/longdoc.js +5 -5
- package/dist/core/memory.d.ts.map +1 -1
- package/dist/core/memory.js +69 -62
- package/dist/core/memory.js.map +1 -1
- package/dist/core/theme.d.ts +46 -0
- package/dist/core/theme.d.ts.map +1 -0
- package/dist/core/theme.js +42 -0
- package/dist/core/theme.js.map +1 -0
- package/dist/web/server.js +542 -519
- package/dist/web/server.js.map +1 -1
- package/docs/AESTHETIC_DESIGN.md +144 -0
- package/docs/OPTIMIZATION_PLAN.md +178 -0
- package/package.json +60 -60
- package/scripts/install.js +48 -48
- package/scripts/link.js +10 -10
- package/setup.bat +79 -79
- package/skill-test-ty2fOA/test.md +10 -10
- package/src/agents/dew.ts +70 -70
- package/src/agents/fair.ts +102 -102
- package/src/agents/fog.ts +48 -48
- package/src/agents/frost.ts +50 -50
- package/src/agents/rain.ts +50 -50
- package/src/agents/snow.ts +239 -239
- package/src/cli/main.ts +425 -372
- package/src/cli/mode.ts +58 -58
- package/src/cli/tui.ts +272 -269
- package/src/core/agent/task.ts +100 -0
- package/src/core/agent.ts +1446 -1549
- package/src/core/agent_helpers.ts +496 -461
- package/src/core/arbitrate.ts +162 -162
- package/src/core/catalog.ts +178 -0
- package/src/core/checkpoint.ts +94 -94
- package/src/core/config.ts +20 -4
- package/src/core/estimate.ts +104 -104
- package/src/core/evolve.ts +191 -191
- package/src/core/factory.ts +627 -627
- package/src/core/filter.ts +103 -103
- package/src/core/graph.ts +156 -156
- package/src/core/icons.ts +53 -53
- package/src/core/index.ts +37 -37
- package/src/core/learn.ts +146 -146
- package/src/core/llm.ts +108 -5
- package/src/core/longdoc.ts +155 -155
- package/src/core/mcp_server.ts +176 -176
- package/src/core/memory.ts +1178 -1171
- package/src/core/profile.ts +255 -255
- package/src/core/router.ts +124 -124
- package/src/core/sandbox.ts +142 -142
- package/src/core/security.ts +243 -243
- package/src/core/skill.ts +342 -342
- package/src/core/theme.ts +65 -0
- package/src/core/tool_router.ts +193 -193
- package/src/core/vector.ts +152 -152
- package/src/core/workspace.ts +150 -150
- package/src/plugins/loader.ts +66 -66
- package/src/skills/loader.ts +46 -46
- package/src/sql.js.d.ts +29 -29
- package/src/tools/builtin.ts +380 -380
- package/src/tools/computer.ts +269 -269
- package/src/tools/delegate.ts +49 -49
- package/src/web/server.ts +660 -634
- package/src/web/tts.ts +93 -93
- package/tests/agent_helpers.test.ts +48 -0
- package/tests/bus.test.ts +121 -121
- package/tests/catalog.test.ts +86 -0
- package/tests/config.test.ts +41 -0
- package/tests/icons.test.ts +45 -45
- package/tests/memory.test.ts +147 -0
- package/tests/router.test.ts +86 -86
- package/tests/schemas.test.ts +51 -51
- package/tests/semantic.test.ts +83 -83
- package/tests/setup.ts +10 -10
- package/tests/skill.test.ts +172 -172
- package/tests/task.test.ts +60 -0
- package/tests/tool.test.ts +108 -108
- package/tests/tool_router.test.ts +71 -71
- package/vitest.config.ts +17 -17
package/src/cli/tui.ts
CHANGED
|
@@ -1,269 +1,272 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 天空织机 TUI — Full-screen terminal interface
|
|
3
|
-
*
|
|
4
|
-
* Layout:
|
|
5
|
-
* ┌─────────────────────────────────────────┐
|
|
6
|
-
* │ ≋ 雾 Fog · deepseek-chat · $0.02 · ⏻ │ ← header bar
|
|
7
|
-
* ├──────────┬──────────────────────────────┤
|
|
8
|
-
* │ ☼ 晴 Fair│ ✦ 你好!有什么可以帮你的? │
|
|
9
|
-
* │ ✱ 霜 │ │ ← messages
|
|
10
|
-
* │ ≋ 雾 ▸ │ 用户消息右对齐 │
|
|
11
|
-
* │ ❉ 雪 │ │
|
|
12
|
-
* │ ∘ 露 │ │
|
|
13
|
-
* │ ⸽ 雨 │ │
|
|
14
|
-
* ├──────────┴──────────────────────────────┤
|
|
15
|
-
* │ ┌─ /fog /rain /frost /snow ───────┐│ ← command palette (popup)
|
|
16
|
-
* │ ▶ /fog Switch to Fog ││
|
|
17
|
-
* │ /rain Switch to Rain ││
|
|
18
|
-
* │ └──────────────────────────────────────┘│
|
|
19
|
-
* │ > hello world [send] │ ← input bar
|
|
20
|
-
* └─────────────────────────────────────────┘
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import * as readline from "readline";
|
|
24
|
-
import chalk from "chalk";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
["
|
|
41
|
-
["
|
|
42
|
-
["
|
|
43
|
-
]
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
["/
|
|
50
|
-
["/
|
|
51
|
-
["/
|
|
52
|
-
["/
|
|
53
|
-
["/
|
|
54
|
-
["/
|
|
55
|
-
["/
|
|
56
|
-
["/
|
|
57
|
-
["/
|
|
58
|
-
["/
|
|
59
|
-
["/
|
|
60
|
-
["/
|
|
61
|
-
["/
|
|
62
|
-
["/
|
|
63
|
-
["/
|
|
64
|
-
["/
|
|
65
|
-
]
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
let
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
if (code === "
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if (ch
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 天空织机 TUI — Full-screen terminal interface
|
|
3
|
+
*
|
|
4
|
+
* Layout:
|
|
5
|
+
* ┌─────────────────────────────────────────┐
|
|
6
|
+
* │ ≋ 雾 Fog · deepseek-chat · $0.02 · ⏻ │ ← header bar
|
|
7
|
+
* ├──────────┬──────────────────────────────┤
|
|
8
|
+
* │ ☼ 晴 Fair│ ✦ 你好!有什么可以帮你的? │
|
|
9
|
+
* │ ✱ 霜 │ │ ← messages
|
|
10
|
+
* │ ≋ 雾 ▸ │ 用户消息右对齐 │
|
|
11
|
+
* │ ❉ 雪 │ │
|
|
12
|
+
* │ ∘ 露 │ │
|
|
13
|
+
* │ ⸽ 雨 │ │
|
|
14
|
+
* ├──────────┴──────────────────────────────┤
|
|
15
|
+
* │ ┌─ /fog /rain /frost /snow ───────┐│ ← command palette (popup)
|
|
16
|
+
* │ ▶ /fog Switch to Fog ││
|
|
17
|
+
* │ /rain Switch to Rain ││
|
|
18
|
+
* │ └──────────────────────────────────────┘│
|
|
19
|
+
* │ > hello world [send] │ ← input bar
|
|
20
|
+
* └─────────────────────────────────────────┘
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import * as readline from "readline";
|
|
24
|
+
import chalk from "chalk";
|
|
25
|
+
|
|
26
|
+
/** Version read from package.json so the header never goes stale. */
|
|
27
|
+
const TUI_VERSION = (() => { try { return require("../../package.json").version; } catch { return ""; } })();
|
|
28
|
+
|
|
29
|
+
export interface TUIContext {
|
|
30
|
+
agent: any;
|
|
31
|
+
agents: Map<string, any>;
|
|
32
|
+
model: string;
|
|
33
|
+
cost: string;
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* ── Slash commands with icons ── */
|
|
39
|
+
const AGENT_CMDS: [string, string, string][] = [
|
|
40
|
+
["≋", "/fog", "雾 Fog · 松烟墨"],
|
|
41
|
+
["⸽", "/rain", "雨 Rain · 石青"],
|
|
42
|
+
["✱", "/frost", "霜 Frost · 石绿"],
|
|
43
|
+
["❉", "/snow", "雪 Snow · 铅白"],
|
|
44
|
+
["∘", "/dew", "露 Dew · 赭石"],
|
|
45
|
+
["☼", "/fair", "晴 Fair · 朱砂"],
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const ACTION_CMDS: [string, string][] = [
|
|
49
|
+
["/help", "所有命令"],
|
|
50
|
+
["/clear", "清屏"],
|
|
51
|
+
["/status", "状态总览"],
|
|
52
|
+
["/cost", "费用统计"],
|
|
53
|
+
["/cost reset", "费用归零"],
|
|
54
|
+
["/compact", "压缩上下文"],
|
|
55
|
+
["/retry", "重发上条"],
|
|
56
|
+
["/setup", "配置向导"],
|
|
57
|
+
["/apikey set <p> <k>", "保存API Key"],
|
|
58
|
+
["/apikey", "查看API Key"],
|
|
59
|
+
["/model", "模型管理"],
|
|
60
|
+
["/task <goal>", "多Agent编排"],
|
|
61
|
+
["/memory", "记忆状态"],
|
|
62
|
+
["/memory clear", "清除记忆"],
|
|
63
|
+
["/sessions", "会话列表"],
|
|
64
|
+
["/workspace", "工作空间"],
|
|
65
|
+
["/mcp", "MCP服务器"],
|
|
66
|
+
["/version", "版本信息"],
|
|
67
|
+
["/quit", "退出"],
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
/* ── Box drawing characters ── */
|
|
71
|
+
const B = { tl: "┌", tr: "┐", bl: "└", br: "┘", h: "─", v: "│", l: "├", r: "┤", cross: "┼", t: "┬", b: "┴", L: "░", o: "●" };
|
|
72
|
+
|
|
73
|
+
function bar(start: string, fill: string, end: string, width: number): string {
|
|
74
|
+
return start + fill.repeat(Math.max(0, width)) + end;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/* ── Render sidebar ── */
|
|
78
|
+
function renderSidebar(agent: any, agents: Map<string, any>, h: number): string[] {
|
|
79
|
+
const lines: string[] = [];
|
|
80
|
+
const W = 14; // sidebar width in chars
|
|
81
|
+
|
|
82
|
+
// Header
|
|
83
|
+
lines.push(chalk.cyan(bar(B.L + " 天空织机 ".padEnd(W - 2, B.L) + B.r, "", "", 0)));
|
|
84
|
+
lines.push(chalk.dim(B.v + " Skyloom " + B.v));
|
|
85
|
+
|
|
86
|
+
for (const n of ["fog", "rain", "frost", "snow", "dew", "fair"]) {
|
|
87
|
+
const isActive = agent.name === n;
|
|
88
|
+
const display: Record<string, string> = { fog: "≋ 雾 Fog", rain: "⸽ 雨 Rain", frost: "✱ 霜 Frost", snow: "❉ 雪 Snow", dew: "∘ 露 Dew", fair: "☼ 晴 Fair" };
|
|
89
|
+
const line = isActive
|
|
90
|
+
? chalk.cyan(B.v + " " + B.o + " " + display[n].padEnd(W - 5) + B.v)
|
|
91
|
+
: chalk.dim(B.v + " " + display[n].padEnd(W - 5) + B.v);
|
|
92
|
+
lines.push(line);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Fill remaining space
|
|
96
|
+
for (let i = lines.length; i < h; i++) {
|
|
97
|
+
lines.push(chalk.dim(B.v + " ".repeat(W - 2) + B.v));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Footer
|
|
101
|
+
try {
|
|
102
|
+
const cu = agent.contextUsage();
|
|
103
|
+
const pct = cu.pct || 0;
|
|
104
|
+
lines.push(chalk.dim(B.v + " ctx " + String(pct).padStart(3) + "%" + " ".repeat(W - 10) + B.v));
|
|
105
|
+
} catch { lines.push(chalk.dim(B.v + " ".repeat(W - 2) + B.v)); }
|
|
106
|
+
|
|
107
|
+
lines.push(chalk.dim(bar(B.bl, B.h, B.br, W - 2)));
|
|
108
|
+
return lines;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/* ── Render command palette ── */
|
|
112
|
+
function renderPalette(filter: string, selIdx: number, width: number): string[] {
|
|
113
|
+
const lines: string[] = [];
|
|
114
|
+
const W = Math.min(width - 4, 56);
|
|
115
|
+
|
|
116
|
+
// Agent section first
|
|
117
|
+
const agentMatches = AGENT_CMDS.filter(([, cmd]) => cmd.includes(filter) || filter === "/");
|
|
118
|
+
const actionMatches = ACTION_CMDS.filter(([cmd]) => cmd.includes(filter));
|
|
119
|
+
|
|
120
|
+
const allItems: string[] = [];
|
|
121
|
+
for (const [icon, cmd, desc] of agentMatches) allItems.push(`${icon} ${cmd.padEnd(16)} ${desc}`);
|
|
122
|
+
for (const [cmd, desc] of actionMatches) allItems.push(` ${cmd.padEnd(18)} ${desc}`);
|
|
123
|
+
|
|
124
|
+
if (allItems.length === 0 && filter.length > 1) {
|
|
125
|
+
// No matches — show message
|
|
126
|
+
lines.push(chalk.dim(bar(B.tl, B.h, B.tr, W)));
|
|
127
|
+
lines.push(chalk.dim(B.v + " 未找到匹配命令 (esc 关闭)".padEnd(W) + B.v));
|
|
128
|
+
lines.push(chalk.dim(bar(B.bl, B.h, B.br, W)));
|
|
129
|
+
return lines;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (allItems.length === 0) return lines;
|
|
133
|
+
|
|
134
|
+
const start = Math.max(0, Math.min(selIdx - 5, allItems.length - 10));
|
|
135
|
+
const end = Math.min(allItems.length, start + 10);
|
|
136
|
+
|
|
137
|
+
lines.push(chalk.dim(bar(B.tl, B.h, B.tr, W - 5)) + " ".padEnd(5));
|
|
138
|
+
|
|
139
|
+
for (let i = start; i < end; i++) {
|
|
140
|
+
const item = allItems[i];
|
|
141
|
+
const isSelected = i === selIdx;
|
|
142
|
+
const pad = W - item.replace(/\x1b\[[0-9;]*m/g, "").length + 2; // account for ANSI codes
|
|
143
|
+
lines.push(isSelected
|
|
144
|
+
? chalk.cyan(B.v + " ▶ " + item).padEnd(W + 10) + chalk.cyan(B.v)
|
|
145
|
+
: chalk.dim(B.v + " " + item).padEnd(W + 10) + chalk.dim(B.v));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
lines.push(chalk.dim(bar(B.bl, B.h, B.br, W - 5)) + " ".padEnd(5));
|
|
149
|
+
return lines;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/* ── Render message ── */
|
|
153
|
+
function renderMessage(role: string, text: string, width: number): string[] {
|
|
154
|
+
const lines: string[] = [];
|
|
155
|
+
const maxW = Math.min(width - 24, 60);
|
|
156
|
+
const prefix = role === "user" ? " " : " ";
|
|
157
|
+
const suffix = role === "user" ? "" : "";
|
|
158
|
+
|
|
159
|
+
for (const para of text.split("\n")) {
|
|
160
|
+
let remaining = para;
|
|
161
|
+
while (remaining.length > 0) {
|
|
162
|
+
const cut = remaining.length > maxW ? remaining.lastIndexOf(" ", maxW) : remaining.length;
|
|
163
|
+
const idx = cut > 0 ? cut : maxW;
|
|
164
|
+
const line = remaining.slice(0, idx).trimEnd();
|
|
165
|
+
if (role === "user") {
|
|
166
|
+
lines.push(chalk.dim(" ".repeat(Math.max(0, width - line.length - 4))) + chalk.cyan(line) + " ");
|
|
167
|
+
} else if (role === "assistant") {
|
|
168
|
+
lines.push(prefix + line + suffix);
|
|
169
|
+
} else {
|
|
170
|
+
lines.push(chalk.dim(" " + line));
|
|
171
|
+
}
|
|
172
|
+
remaining = remaining.slice(idx).trimStart();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return lines;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* ── Read input with command palette ── */
|
|
179
|
+
export function readInput(stdin: NodeJS.ReadStream, stdout: NodeJS.WriteStream, ctx: TUIContext): Promise<string> {
|
|
180
|
+
return new Promise(resolve => {
|
|
181
|
+
let buf = "";
|
|
182
|
+
let cursor = 0;
|
|
183
|
+
let palette = false;
|
|
184
|
+
let selIdx = 0;
|
|
185
|
+
|
|
186
|
+
function render() {
|
|
187
|
+
// Clear screen and render full TUI
|
|
188
|
+
readline.cursorTo(stdout, 0, 0);
|
|
189
|
+
readline.clearScreenDown(stdout);
|
|
190
|
+
|
|
191
|
+
const w = stdout.columns || 80;
|
|
192
|
+
const h = stdout.rows || 24;
|
|
193
|
+
const sidebarW = 16;
|
|
194
|
+
|
|
195
|
+
// Header
|
|
196
|
+
stdout.write(chalk.bgBlack.cyan(` 天空织机 Skyloom v${TUI_VERSION} `.padEnd(w - 20, " ")) + chalk.bgBlack.dim(" deepseek".padEnd(10)) + chalk.bgBlack("\n"));
|
|
197
|
+
stdout.write(chalk.dim(bar("", B.h, "", w)) + "\n");
|
|
198
|
+
|
|
199
|
+
// Sidebar
|
|
200
|
+
const sidebar = renderSidebar(ctx.agent, ctx.agents, h - 5);
|
|
201
|
+
for (let i = 0; i < sidebar.length && i < h - 5; i++) {
|
|
202
|
+
stdout.write(sidebar[i] + "\n");
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Command palette (overlaid)
|
|
206
|
+
if (palette) {
|
|
207
|
+
const paletteLines = renderPalette(buf, selIdx, w);
|
|
208
|
+
// Move cursor up to position palette below header
|
|
209
|
+
const paletteY = 2;
|
|
210
|
+
for (let i = 0; i < paletteLines.length; i++) {
|
|
211
|
+
stdout.write(`\x1b[${paletteY + i};${sidebarW}H`); // position cursor
|
|
212
|
+
stdout.write(paletteLines[i]);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Input bar at bottom
|
|
217
|
+
readline.cursorTo(stdout, sidebarW, h - 1);
|
|
218
|
+
stdout.write(chalk.dim(B.l + B.h.repeat(w - sidebarW - 2) + B.r));
|
|
219
|
+
readline.cursorTo(stdout, sidebarW, h);
|
|
220
|
+
stdout.write(chalk.cyan(" > ") + buf.slice(0, cursor) + chalk.inverse(buf[cursor] || " ") + buf.slice(cursor + 1));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (!stdin.isTTY) {
|
|
224
|
+
const rl = readline.createInterface({ input: stdin });
|
|
225
|
+
rl.on("line", (line) => { rl.close(); resolve(line.trim()); });
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
stdin.setRawMode(true);
|
|
230
|
+
stdin.resume();
|
|
231
|
+
render();
|
|
232
|
+
|
|
233
|
+
let escBuf = "";
|
|
234
|
+
stdin.on("data", (data: Buffer) => {
|
|
235
|
+
const str = data.toString();
|
|
236
|
+
escBuf += str;
|
|
237
|
+
|
|
238
|
+
if (escBuf.startsWith("\x1b[") && escBuf.length >= 3) {
|
|
239
|
+
const code = escBuf[2]; escBuf = "";
|
|
240
|
+
if (code === "A") { if (palette) selIdx = Math.max(0, selIdx - 1); render(); return; }
|
|
241
|
+
if (code === "B") { if (palette) { const all = [...AGENT_CMDS.map(c => c[1]), ...ACTION_CMDS.map(c => c[0])]; selIdx = Math.min(all.filter(a => a.includes(buf)).length - 1, selIdx + 1); } render(); return; }
|
|
242
|
+
if (code === "C") { if (cursor < buf.length) cursor++; render(); return; }
|
|
243
|
+
if (code === "D") { if (cursor > 0) cursor--; render(); return; }
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
for (const ch of escBuf) {
|
|
247
|
+
escBuf = "";
|
|
248
|
+
if (ch === "\x1b") { palette = false; render(); return; }
|
|
249
|
+
if (ch === "\r" || ch === "\n") {
|
|
250
|
+
if (palette) {
|
|
251
|
+
const all = [...AGENT_CMDS.map(c => c[1]), ...ACTION_CMDS.map(c => c[0])];
|
|
252
|
+
const filtered = all.filter(a => a.includes(buf));
|
|
253
|
+
if (filtered[selIdx]) buf = filtered[selIdx];
|
|
254
|
+
palette = false;
|
|
255
|
+
render();
|
|
256
|
+
stdin.setRawMode(false); stdin.pause(); resolve(buf.trim()); return;
|
|
257
|
+
}
|
|
258
|
+
stdin.setRawMode(false); stdin.pause(); resolve(buf.trim()); return;
|
|
259
|
+
}
|
|
260
|
+
if (ch === "\t") { /* ignore */ return; }
|
|
261
|
+
if (ch === "\x7f" || ch === "\b") { if (cursor > 0) { buf = buf.slice(0, cursor - 1) + buf.slice(cursor); cursor--; } if (!buf) palette = false; render(); return; }
|
|
262
|
+
if (ch === "\x03") { stdin.setRawMode(false); stdin.pause(); resolve("/quit"); return; }
|
|
263
|
+
if (ch >= " ") {
|
|
264
|
+
buf = buf.slice(0, cursor) + ch + buf.slice(cursor); cursor++;
|
|
265
|
+
if (ch === "/") { palette = true; selIdx = 0; }
|
|
266
|
+
else if (palette) selIdx = 0;
|
|
267
|
+
render(); return;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
}
|