openclacky 1.5.27 → 1.5.28
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.
- checksums.yaml +4 -4
- data/.clacky/skills/gem-release/SKILL.md +7 -1
- data/CHANGELOG.md +27 -0
- data/lib/clacky/billing/platform_billing.rb +7 -0
- data/lib/clacky/default_extensions/knowledge/README.md +3 -3
- data/lib/clacky/default_extensions/knowledge/README.zh.md +3 -3
- data/lib/clacky/default_extensions/knowledge/ext.yml +2 -2
- data/lib/clacky/default_extensions/knowledge/lib/index.rb +3 -1
- data/lib/clacky/default_extensions/knowledge/lib/knowledge.rb +1 -1
- data/lib/clacky/default_extensions/knowledge/lib/t2s.rb +44 -0
- data/lib/clacky/default_extensions/knowledge/lib/t2s.txt +3221 -0
- data/lib/clacky/default_extensions/knowledge/panels/kb/view.js +25 -7
- data/lib/clacky/default_extensions/side-chat/README.md +1 -1
- data/lib/clacky/default_extensions/side-chat/README.zh.md +1 -1
- data/lib/clacky/default_extensions/side-chat/api/runtime.rb +7 -2
- data/lib/clacky/default_extensions/side-chat/panels/side-chat/view.js +58 -16
- data/lib/clacky/default_extensions/terminal/README.md +2 -0
- data/lib/clacky/default_extensions/terminal/README.zh.md +2 -0
- data/lib/clacky/default_extensions/terminal/panels/terminal/view.js +80 -10
- data/lib/clacky/default_parsers/deepseek_ocr.rb +275 -0
- data/lib/clacky/default_parsers/pdf_parser.rb +39 -10
- data/lib/clacky/default_skills/media-gen/SKILL.md +5 -2
- data/lib/clacky/media/openai_compat.rb +17 -1
- data/lib/clacky/message_format/open_ai.rb +2 -2
- data/lib/clacky/message_format/open_ai_responses.rb +8 -2
- data/lib/clacky/providers.rb +34 -18
- data/lib/clacky/reasoning_levels.rb +2 -2
- data/lib/clacky/server/http_server.rb +104 -14
- data/lib/clacky/server/session_registry.rb +1 -1
- data/lib/clacky/utils/model_pricing.rb +9 -0
- data/lib/clacky/version.rb +1 -1
- data/lib/clacky/web/components/code-editor.js +45 -0
- data/lib/clacky/web/components/custom-select.js +15 -2
- data/lib/clacky/web/components/model-picker.js +11 -0
- data/lib/clacky/web/components/quote-select.js +7 -2
- data/lib/clacky/web/core/ext.js +34 -1
- data/lib/clacky/web/features/workspace/view.js +4 -2
- data/lib/clacky/web/i18n.js +28 -18
- data/lib/clacky/web/index.html +0 -2
- data/lib/clacky/web/sessions.js +74 -0
- metadata +4 -2
- data/lib/clacky/web/vendor/katex/auto-render.min.js +0 -1
|
@@ -471,6 +471,7 @@
|
|
|
471
471
|
data: null, folder: null, filter: "", busy: null, lastQuery: "", sort: loadSort(),
|
|
472
472
|
range: loadRange(), statsSession: "", statsTheme: "",
|
|
473
473
|
stats: null, statsKey: "", statsError: "", statsLoading: false,
|
|
474
|
+
statsFiltersSig: "", statsSeq: 0,
|
|
474
475
|
statsBox: null, statsClose: null, statsBody: null,
|
|
475
476
|
};
|
|
476
477
|
function loadRange() {
|
|
@@ -892,26 +893,40 @@
|
|
|
892
893
|
|
|
893
894
|
async function loadStats() {
|
|
894
895
|
const key = `${state.range}|${state.statsSession}|${state.statsTheme}`;
|
|
895
|
-
|
|
896
|
-
|
|
896
|
+
const seq = ++state.statsSeq;
|
|
897
|
+
if (state.statsKey === key && state.stats) {
|
|
898
|
+
// A newer request supersedes any answer still in flight.
|
|
899
|
+
state.statsLoading = false;
|
|
900
|
+
state.statsError = "";
|
|
901
|
+
drawStatsBody();
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
897
904
|
state.statsLoading = true;
|
|
898
905
|
state.statsError = "";
|
|
899
906
|
drawStatsBody();
|
|
900
907
|
try {
|
|
901
908
|
const data = await call("GET", `/stats?range=${encodeURIComponent(state.range)}`
|
|
902
909
|
+ `&session=${encodeURIComponent(state.statsSession)}&theme=${encodeURIComponent(state.statsTheme)}`);
|
|
910
|
+
if (seq !== state.statsSeq) return;
|
|
903
911
|
state.stats = data;
|
|
904
912
|
state.statsKey = key;
|
|
905
913
|
} catch (e) {
|
|
914
|
+
if (seq !== state.statsSeq) return;
|
|
906
915
|
state.stats = null;
|
|
907
916
|
state.statsError = t("loadFailed", { msg: e.message });
|
|
908
917
|
}
|
|
909
918
|
state.statsLoading = false;
|
|
910
|
-
//
|
|
911
|
-
//
|
|
912
|
-
//
|
|
913
|
-
|
|
914
|
-
|
|
919
|
+
// Both dependent dropdowns are built from the payload they filter, and that
|
|
920
|
+
// list depends on the range window (and on any conversation started since),
|
|
921
|
+
// not on the current selection. Comparing it against what is already on
|
|
922
|
+
// screen is what keeps the dropdowns in step with the range.
|
|
923
|
+
const sig = state.stats ? JSON.stringify(state.stats.filters) : "";
|
|
924
|
+
if (state.stats && sig !== state.statsFiltersSig) {
|
|
925
|
+
state.statsFiltersSig = sig;
|
|
926
|
+
drawStatsModal();
|
|
927
|
+
} else {
|
|
928
|
+
drawStatsBody();
|
|
929
|
+
}
|
|
915
930
|
}
|
|
916
931
|
|
|
917
932
|
function drawStatsBody() {
|
|
@@ -1677,6 +1692,9 @@
|
|
|
1677
1692
|
const overlay = el("div", { class: "modal-overlay kb-overlay" }, [box]);
|
|
1678
1693
|
const onKey = (e) => { if (e.key === "Escape") close(); };
|
|
1679
1694
|
function close() {
|
|
1695
|
+
// Portalled dropdowns are children of <body>, so removing the overlay
|
|
1696
|
+
// does not take them with it.
|
|
1697
|
+
if (window.CustomSelect && window.CustomSelect.closeAll) window.CustomSelect.closeAll();
|
|
1680
1698
|
overlay.remove();
|
|
1681
1699
|
document.removeEventListener("keydown", onKey);
|
|
1682
1700
|
if (onClose) onClose();
|
|
@@ -34,7 +34,7 @@ You can also attach a file with the paperclip or by dropping it on the panel, as
|
|
|
34
34
|
## Notes
|
|
35
35
|
|
|
36
36
|
- At most 6 branches at once across sessions. A branch nobody has been attached to for an hour is reaped the next time a panel opens — there is no timer, so an idle branch lingers until then.
|
|
37
|
-
- Branches live in the Clacky process: restarting Clacky ends them and the panel
|
|
37
|
+
- Branches live in the Clacky process: restarting Clacky ends them, and the panel then marks the end of the old conversation with "Earlier messages were reset." — nothing to re-send.
|
|
38
38
|
- Reloading the page does not replay the panel's history. Asking again reattaches to the same branch, so the context is still there even though the earlier answers are not shown.
|
|
39
39
|
- Model calls made here are billed to the session the panel belongs to, so the cost shows up in that session's usage.
|
|
40
40
|
- The panel is a narrow column by default; drag the divider to widen it. The width is remembered per session.
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
## 注意事项
|
|
35
35
|
|
|
36
36
|
- 跨会话最多同时 6 条分支;超过时会提示开不了新的。空闲超过 1 小时的分支会在下次打开侧聊时被回收(没有定时器,空闲期间它一直留着)。
|
|
37
|
-
- 分支活在 Clacky 进程里:重启 Clacky
|
|
37
|
+
- 分支活在 Clacky 进程里:重启 Clacky 后它们都没了,面板会在旧对话末尾标一行「之前的侧聊已重置」,不需要重发。
|
|
38
38
|
- 刷新页面不会回放面板里的历史;再发消息会接回同一条分支,上下文还在,只是之前那几轮问答不显示了。
|
|
39
39
|
- 这里产生的模型调用计入面板所属会话的用量,账单上看得到。
|
|
40
40
|
- 面板默认是窄栏,拖分隔条可以加宽;宽度按会话记住。
|
|
@@ -140,7 +140,13 @@ module Clacky
|
|
|
140
140
|
def ask(text:, files: [], references: [])
|
|
141
141
|
prompt = text.to_s.strip[0, MAX_TEXT_CHARS].to_s
|
|
142
142
|
files = [] unless files.is_a?(Array)
|
|
143
|
-
|
|
143
|
+
# A staged quote is content in its own right — the main conversation
|
|
144
|
+
# (#_sendMessage) accepts a send with nothing but quotes, and the
|
|
145
|
+
# composer's hasExtra gate lets one through, so refusing it here
|
|
146
|
+
# would drop the frame and answer nothing. Normalise first: junk
|
|
147
|
+
# references collapse to [], leaving a genuinely empty send :empty.
|
|
148
|
+
refs = normalize_references(references)
|
|
149
|
+
return :empty if prompt.empty? && files.empty? && refs.empty?
|
|
144
150
|
|
|
145
151
|
status = @mutex.synchronize do
|
|
146
152
|
if @closed
|
|
@@ -154,7 +160,6 @@ module Clacky
|
|
|
154
160
|
end
|
|
155
161
|
return status unless status == :ok
|
|
156
162
|
|
|
157
|
-
refs = normalize_references(references)
|
|
158
163
|
# The turn start is authoritative: the panel paints "running" from
|
|
159
164
|
# this frame instead of guessing at send time, because an `attached`
|
|
160
165
|
# snapshot answered before the send can land after it.
|
|
@@ -79,6 +79,11 @@
|
|
|
79
79
|
.sidechat-note { font-size: 0.75rem; line-height: 1.5; color: var(--color-text-tertiary);
|
|
80
80
|
padding: 0 0.25rem; }
|
|
81
81
|
.sidechat-note-error { color: var(--color-danger, #dc2626); }
|
|
82
|
+
/* The reset line divides two conversations, so it sits in the middle of
|
|
83
|
+
the column instead of hanging off the left edge like a status message.
|
|
84
|
+
It is short enough to stay on one line in the narrowest panel; a
|
|
85
|
+
centred sentence that wraps reads like a mistake. */
|
|
86
|
+
.sidechat-note-reset { text-align: center; }
|
|
82
87
|
.sidechat-foot { flex: none;
|
|
83
88
|
padding: 0.5rem 0.625rem 0.625rem; display: flex; flex-direction: column; }
|
|
84
89
|
.sidechat-composer { flex: none; }
|
|
@@ -139,6 +144,33 @@
|
|
|
139
144
|
return rt;
|
|
140
145
|
}
|
|
141
146
|
|
|
147
|
+
// A status line says where the panel stands, so saying it twice says nothing:
|
|
148
|
+
// a reconnect can deliver the same frame again, and two identical lines read
|
|
149
|
+
// as two separate failures. One line per distinct message.
|
|
150
|
+
function pushNote(rt, kind, text) {
|
|
151
|
+
const seen = rt.notes.some((note) => note.kind === kind && note.text === text);
|
|
152
|
+
if (!seen) rt.notes.push({ kind: kind, text: text });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// An ordinary entry, so the line renders where the branch ended rather than
|
|
156
|
+
// at the bottom of the panel, where the next messages would push it down.
|
|
157
|
+
function pushReset(rt) {
|
|
158
|
+
rt.entries.push({
|
|
159
|
+
kind: "note",
|
|
160
|
+
text: t("sidechat.reset", "Earlier messages were reset."),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Closes off the conversation on screen instead of discarding it: the branch
|
|
165
|
+
// behind it was reaped, so this transcript is the only copy. Only the last
|
|
166
|
+
// line survives — two of them with turns between would suggest the middle is
|
|
167
|
+
// still in play — and notes go with it, since they would render below it.
|
|
168
|
+
function markReset(rt) {
|
|
169
|
+
rt.notes = [];
|
|
170
|
+
rt.entries = rt.entries.filter((entry) => entry.kind !== "note");
|
|
171
|
+
if (rt.entries.length) pushReset(rt);
|
|
172
|
+
}
|
|
173
|
+
|
|
142
174
|
// ── Transport ────────────────────────────────────────────────────────────
|
|
143
175
|
|
|
144
176
|
function wsSend(frame) {
|
|
@@ -200,9 +232,16 @@
|
|
|
200
232
|
throw new Error(data.error || ("HTTP " + response.status));
|
|
201
233
|
}
|
|
202
234
|
if (fresh) {
|
|
235
|
+
// The branch that answers is forked from the main conversation, not
|
|
236
|
+
// from this panel, so whatever was said here leaves both the screen
|
|
237
|
+
// and the model's context. Clear it and open the new conversation
|
|
238
|
+
// with the line: an empty panel reads like a glitch, and the line
|
|
239
|
+
// belongs above the turns that follow it, not below them.
|
|
240
|
+
const hadTurns = rt.entries.length > 0;
|
|
203
241
|
rt.entries = [];
|
|
204
242
|
rt.streaming = null;
|
|
205
243
|
rt.notes = [];
|
|
244
|
+
if (hadTurns) pushReset(rt);
|
|
206
245
|
rt.pinBottom = true;
|
|
207
246
|
clearProgress(rt);
|
|
208
247
|
}
|
|
@@ -212,12 +251,9 @@
|
|
|
212
251
|
})
|
|
213
252
|
.catch((error) => {
|
|
214
253
|
rt.status = "idle";
|
|
215
|
-
rt.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
error: (error && error.message) || String(error),
|
|
219
|
-
}),
|
|
220
|
-
});
|
|
254
|
+
pushNote(rt, "error", t("sidechat.openFailed", "Could not open the side chat: {{error}}", {
|
|
255
|
+
error: (error && error.message) || String(error),
|
|
256
|
+
}));
|
|
221
257
|
})
|
|
222
258
|
.then(() => {
|
|
223
259
|
rt.opening = null;
|
|
@@ -306,7 +342,7 @@
|
|
|
306
342
|
rt.streaming = null;
|
|
307
343
|
rt.status = "idle";
|
|
308
344
|
clearProgress(rt);
|
|
309
|
-
rt
|
|
345
|
+
markReset(rt);
|
|
310
346
|
renderMessages(rt);
|
|
311
347
|
break;
|
|
312
348
|
|
|
@@ -366,7 +402,7 @@
|
|
|
366
402
|
}
|
|
367
403
|
|
|
368
404
|
case "tool_error":
|
|
369
|
-
rt
|
|
405
|
+
pushNote(rt, "note", "⚠ Tool error: " + String(event.error || event.message || ""));
|
|
370
406
|
scheduleRender(rt);
|
|
371
407
|
break;
|
|
372
408
|
|
|
@@ -390,12 +426,9 @@
|
|
|
390
426
|
case "error":
|
|
391
427
|
rt.streaming = null;
|
|
392
428
|
clearProgress(rt);
|
|
393
|
-
rt.
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
error: event.message || "",
|
|
397
|
-
}),
|
|
398
|
-
});
|
|
429
|
+
pushNote(rt, "error", t("sidechat.failed", "Side chat failed: {{error}}", {
|
|
430
|
+
error: event.message || "",
|
|
431
|
+
}));
|
|
399
432
|
scheduleRender(rt);
|
|
400
433
|
break;
|
|
401
434
|
|
|
@@ -538,6 +571,12 @@
|
|
|
538
571
|
}
|
|
539
572
|
|
|
540
573
|
function renderEntry(entry) {
|
|
574
|
+
// A note that belongs at a point in the conversation rather than at the
|
|
575
|
+
// bottom of the panel: the reset line sits where the old branch ended.
|
|
576
|
+
if (entry.kind === "note") {
|
|
577
|
+
return el("div", "sidechat-note sidechat-note-reset", entry.text);
|
|
578
|
+
}
|
|
579
|
+
|
|
541
580
|
if (entry.kind === "user") {
|
|
542
581
|
const wrap = el("div", "msg-user-wrap");
|
|
543
582
|
const bubble = el("div", "msg msg-user");
|
|
@@ -737,9 +776,12 @@
|
|
|
737
776
|
// survive either way.
|
|
738
777
|
rt.pendingFresh = true;
|
|
739
778
|
} else {
|
|
740
|
-
|
|
779
|
+
// No branch stands behind what is on screen (it was reaped, or the panel
|
|
780
|
+
// never attached). Keep it and close it off: the next send opens a branch
|
|
781
|
+
// and appends below the line. Wiping here would throw away the only copy
|
|
782
|
+
// of a transcript the server never writes to disk.
|
|
741
783
|
rt.streaming = null;
|
|
742
|
-
rt
|
|
784
|
+
markReset(rt);
|
|
743
785
|
rt.pinBottom = true;
|
|
744
786
|
renderMessages(rt);
|
|
745
787
|
}
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
- One shell per session, started in that session's working directory — the folder the AI works in. Falls back to your home directory when the session has none.
|
|
12
12
|
- Switching to another tab or another session leaves the shell running. Come back and everything it printed meanwhile is replayed.
|
|
13
|
+
- Reloading the page re-attaches to that same shell, scrollback included.
|
|
13
14
|
- Closing the tab with × does not kill the shell. Add **Terminal** again and you are back in the same one.
|
|
15
|
+
- Right-click the tab and pick **Restart terminal** to throw that shell away and start a clean one in the same folder — the way out when something is still running in it and `exit` cannot get through.
|
|
14
16
|
- Typing `exit` (or `Ctrl+D`) ends the shell, and the tab closes itself. Adding **Terminal** again gives you a fresh shell.
|
|
15
17
|
|
|
16
18
|
### Everyday commands
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
- 一个会话一个 shell,起始目录就是这个会话的工作目录(AI 干活的目录);没有会话目录时用用户主目录。
|
|
12
12
|
- 切到别的标签页或别的会话,shell 继续在后台跑;切回来时,期间打印的内容会补上。
|
|
13
|
+
- 刷新页面会接回同一个 shell,之前的输出还在。
|
|
13
14
|
- 用 × 关掉标签页不会杀掉进程;再添加「终端」就接回同一个 shell。
|
|
15
|
+
- 右键点标签页可以「重启终端」:把这个 shell 丢掉,在同一目录重新起一个干净的 —— 里面还有进程在跑、`exit` 敲不动时就靠这个。
|
|
14
16
|
- 输入 `exit`(或 `Ctrl+D`)退出后,这个标签页会自动关掉;再添加「终端」得到一个新 shell。
|
|
15
17
|
|
|
16
18
|
### 常用操作
|
|
@@ -20,6 +20,13 @@
|
|
|
20
20
|
const WS_PREFIX = "ext.terminal.";
|
|
21
21
|
const TAB_SLOT = "session.aside";
|
|
22
22
|
const TAB_ID = "terminal";
|
|
23
|
+
// The shell outlives the page, so its id is remembered per browser tab: a
|
|
24
|
+
// reload re-attaches to it instead of leaving it to the server's reaper.
|
|
25
|
+
const TERM_STORE_PREFIX = "clacky.terminal.term.";
|
|
26
|
+
|
|
27
|
+
// Same glyph, same scale as the directory picker's refresh button; growing it
|
|
28
|
+
// to fill the 24-unit box made it read heavier than the Lucide outlines beside it.
|
|
29
|
+
const REFRESH_ICON = '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><path transform="translate(3.5 3.5) scale(0.0166015625)" d="M914.17946 324.34283C854.308387 324.325508 750.895846 324.317788 750.895846 324.317788 732.045471 324.317788 716.764213 339.599801 716.764213 358.451121 716.764213 377.30244 732.045471 392.584453 750.895846 392.584453L955.787864 392.584453C993.448095 392.584453 1024 362.040424 1024 324.368908L1024 119.466667C1024 100.615347 1008.718742 85.333333 989.868367 85.333333 971.017993 85.333333 955.736735 100.615347 955.736735 119.466667L955.736735 256.497996C933.314348 217.628194 905.827487 181.795372 873.995034 149.961328 778.623011 54.584531 649.577119 0 511.974435 0 229.218763 0 0 229.230209 0 512 0 794.769791 229.218763 1024 511.974435 1024 794.730125 1024 1023.948888 794.769791 1023.948888 512 1023.948888 493.148681 1008.66763 477.866667 989.817256 477.866667 970.966881 477.866667 955.685623 493.148681 955.685623 512 955.685623 757.067153 757.029358 955.733333 511.974435 955.733333 266.91953 955.733333 68.263265 757.067153 68.263265 512 68.263265 266.932847 266.91953 68.266667 511.974435 68.266667 631.286484 68.266667 743.028524 115.531923 825.725634 198.233152 862.329644 234.839003 892.298522 277.528256 914.17946 324.34283L914.17946 324.34283Z" stroke="currentColor" stroke-width="35" stroke-linejoin="round"/></svg>';
|
|
23
30
|
|
|
24
31
|
const t = (key, fallback, params) => {
|
|
25
32
|
const value = (typeof I18n !== "undefined") ? I18n.t(key, params) : null;
|
|
@@ -59,6 +66,17 @@
|
|
|
59
66
|
return bytes;
|
|
60
67
|
}
|
|
61
68
|
|
|
69
|
+
function rememberTerm(rt) {
|
|
70
|
+
try {
|
|
71
|
+
if (rt.termId) window.sessionStorage.setItem(TERM_STORE_PREFIX + rt.sessionId, rt.termId);
|
|
72
|
+
else window.sessionStorage.removeItem(TERM_STORE_PREFIX + rt.sessionId);
|
|
73
|
+
} catch (_e) { /* storage unavailable: a reload starts a new shell */ }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function recallTerm(sessionId) {
|
|
77
|
+
try { return window.sessionStorage.getItem(TERM_STORE_PREFIX + sessionId); } catch (_e) { return null; }
|
|
78
|
+
}
|
|
79
|
+
|
|
62
80
|
function send(rt, frame) {
|
|
63
81
|
if (!rt || rt.disposed || !rt.termId) return;
|
|
64
82
|
if (!window.Clacky || !Clacky.WS) return;
|
|
@@ -70,9 +88,13 @@
|
|
|
70
88
|
const style = document.createElement("style");
|
|
71
89
|
style.id = "terminal-ext-css";
|
|
72
90
|
style.textContent = `
|
|
73
|
-
.term-host { flex: 1 1 auto; min-height: 0;
|
|
74
|
-
|
|
75
|
-
|
|
91
|
+
.term-host { flex: 1 1 auto; min-height: 0; background: transparent; }
|
|
92
|
+
/* FitAddon subtracts the padding of .xterm, not of its parent, so the
|
|
93
|
+
insets have to live here: on .term-host they were counted as usable
|
|
94
|
+
width and the terminal sized itself past the panel, which then grew a
|
|
95
|
+
scrollbar and fed a resize loop back through the ResizeObserver. */
|
|
96
|
+
.term-host .xterm { height: 100%; box-sizing: border-box; padding: 0.5rem 0.375rem 0.375rem 0.625rem; }
|
|
97
|
+
.term-host .xterm-viewport { background: transparent !important; overflow-x: hidden; }
|
|
76
98
|
.term-host .xterm-viewport::-webkit-scrollbar { width: 0.5rem; }
|
|
77
99
|
.term-host .xterm-viewport::-webkit-scrollbar-thumb { background: var(--color-border-strong, rgba(0,0,0,.18)); border-radius: 0.25rem; }
|
|
78
100
|
.term-note { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center;
|
|
@@ -176,13 +198,31 @@
|
|
|
176
198
|
if (rt.host) rt.host.style.display = "";
|
|
177
199
|
}
|
|
178
200
|
|
|
201
|
+
// Drops the shell behind the tab without closing the tab: the next shell is
|
|
202
|
+
// a fresh login shell in the same directory, with an empty scrollback.
|
|
203
|
+
function killShell(rt) {
|
|
204
|
+
if (!rt) return;
|
|
205
|
+
send(rt, { type: "ext.terminal.close" });
|
|
206
|
+
rt.termId = null;
|
|
207
|
+
rememberTerm(rt);
|
|
208
|
+
if (rt.term) rt.term.reset();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// A shell recalled after a reload may have exited or died with a server
|
|
212
|
+
// restart meanwhile; the tab was reopened for the user, so start a new one
|
|
213
|
+
// rather than closing it under them.
|
|
214
|
+
function replaceRecalled(rt) {
|
|
215
|
+
rt.recalled = false;
|
|
216
|
+
rt.termId = null;
|
|
217
|
+
rememberTerm(rt);
|
|
218
|
+
startShell(rt);
|
|
219
|
+
}
|
|
220
|
+
|
|
179
221
|
// The shell is the panel: once it exits (or the server no longer knows it,
|
|
180
222
|
// which happens if openclacky restarts) the tab has nothing to show, so it
|
|
181
223
|
// closes itself exactly like the × on the tab would.
|
|
182
224
|
function retire(rt) {
|
|
183
|
-
|
|
184
|
-
rt.termId = null;
|
|
185
|
-
if (rt.term) rt.term.reset();
|
|
225
|
+
killShell(rt);
|
|
186
226
|
const ext = window.Clacky && Clacky.ext;
|
|
187
227
|
// A background session's runtime must not close the tab the user is
|
|
188
228
|
// looking at; the tab id is shared, the panel state is per session.
|
|
@@ -215,6 +255,7 @@
|
|
|
215
255
|
return;
|
|
216
256
|
}
|
|
217
257
|
rt.termId = payload.term_id;
|
|
258
|
+
rememberTerm(rt);
|
|
218
259
|
send(rt, { type: "ext.terminal.attach" });
|
|
219
260
|
rt.term.focus();
|
|
220
261
|
} catch (error) {
|
|
@@ -224,6 +265,15 @@
|
|
|
224
265
|
}
|
|
225
266
|
}
|
|
226
267
|
|
|
268
|
+
// Throw away the current shell and start a new one in the same tab. Only the
|
|
269
|
+
// tab's context menu reaches this: × on the tab means "stop looking at it",
|
|
270
|
+
// this means "I want a clean shell".
|
|
271
|
+
function restartShell(rt) {
|
|
272
|
+
if (!rt || rt.disposed || rt.booting) return;
|
|
273
|
+
killShell(rt);
|
|
274
|
+
startShell(rt);
|
|
275
|
+
}
|
|
276
|
+
|
|
227
277
|
function onServerEvent(rt, event) {
|
|
228
278
|
if (!event || rt.disposed) return;
|
|
229
279
|
|
|
@@ -236,7 +286,12 @@
|
|
|
236
286
|
|
|
237
287
|
switch (event.type) {
|
|
238
288
|
case "ext.terminal.ready":
|
|
239
|
-
if (event.status && event.status !== "running") {
|
|
289
|
+
if (event.status && event.status !== "running") {
|
|
290
|
+
if (rt.recalled) replaceRecalled(rt);
|
|
291
|
+
else retire(rt);
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
rt.recalled = false;
|
|
240
295
|
if (event.replay) {
|
|
241
296
|
rt.term.reset();
|
|
242
297
|
rt.term.write(b64ToBytes(event.replay));
|
|
@@ -246,8 +301,11 @@
|
|
|
246
301
|
case "ext.terminal.output":
|
|
247
302
|
rt.term.write(b64ToBytes(event.data));
|
|
248
303
|
break;
|
|
249
|
-
case "ext.terminal.exit":
|
|
250
304
|
case "ext.terminal.gone":
|
|
305
|
+
if (rt.recalled) replaceRecalled(rt);
|
|
306
|
+
else retire(rt);
|
|
307
|
+
break;
|
|
308
|
+
case "ext.terminal.exit":
|
|
251
309
|
retire(rt);
|
|
252
310
|
break;
|
|
253
311
|
default:
|
|
@@ -257,9 +315,12 @@
|
|
|
257
315
|
|
|
258
316
|
function create(ctx) {
|
|
259
317
|
styles();
|
|
318
|
+
const sessionId = ctx && ctx.sessionId;
|
|
319
|
+
const recalled = recallTerm(sessionId);
|
|
260
320
|
const rt = {
|
|
261
|
-
sessionId
|
|
262
|
-
termId:
|
|
321
|
+
sessionId,
|
|
322
|
+
termId: recalled,
|
|
323
|
+
recalled: !!recalled,
|
|
263
324
|
term: null,
|
|
264
325
|
fit: null,
|
|
265
326
|
host: null,
|
|
@@ -289,6 +350,7 @@
|
|
|
289
350
|
Clacky.WS.send({ type: "ext.terminal.close", term_id: rt.termId });
|
|
290
351
|
}
|
|
291
352
|
rt.termId = null;
|
|
353
|
+
rememberTerm(rt);
|
|
292
354
|
}
|
|
293
355
|
if (rt.term) { rt.term.dispose(); rt.term = null; }
|
|
294
356
|
};
|
|
@@ -346,6 +408,14 @@
|
|
|
346
408
|
id: TAB_ID,
|
|
347
409
|
label: () => t("terminal.tab", "终端"),
|
|
348
410
|
icon: '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="5 8 10 12 5 16"/><line x1="12" y1="16.5" x2="19" y2="16.5"/></svg>',
|
|
411
|
+
// × detaches and the shell survives; a shell that must go away (a server
|
|
412
|
+
// running in it, a stuck `exit`) is discarded from here instead.
|
|
413
|
+
menu: (rt) => (rt && !rt.disposed ? [{
|
|
414
|
+
id: "restart",
|
|
415
|
+
label: t("terminal.restart", "重启终端"),
|
|
416
|
+
icon: REFRESH_ICON,
|
|
417
|
+
run: () => restartShell(rt),
|
|
418
|
+
}] : []),
|
|
349
419
|
},
|
|
350
420
|
});
|
|
351
421
|
})();
|