dsh-remote-vs 0.20.0 → 0.20.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/README.en.md +1 -1
- package/README.md +1 -1
- package/lib/client.js +123 -89
- package/lib/index.js +234 -36
- package/lib/p2-router-fs.js +1 -1
- package/lib/types/client/vsc/editor-keymap.d.ts +45 -0
- package/lib/types/client/vsc/file-icons.d.ts +8 -9
- package/lib/types/client/vsc/kit.d.ts +7 -6
- package/lib/types/preset-switch.d.ts +89 -0
- package/lib/{worlds-Be1YE2Ot.js → worlds-DSzyajOB.js} +1 -1
- package/package.json +1 -1
- package/src/client/CodeEditor.tsx +24 -62
- package/src/client/index.tsx +3 -3
- package/src/client/vsc/editor-keymap.ts +97 -0
- package/src/client/vsc/file-icons.tsx +8 -9
- package/src/client/vsc/kit.tsx +7 -6
- package/src/index.ts +115 -52
- package/src/preset-switch.ts +143 -0
package/README.en.md
CHANGED
|
@@ -462,7 +462,7 @@ tsc, to the bundler and to jsdom — this fixture is the only place they reprodu
|
|
|
462
462
|
> exactly why "57 call sites" and "55 checks run" differ by 2).
|
|
463
463
|
|
|
464
464
|
The live-host regression is still `npx tsc -p tsconfig.scratch.json && node .spike/build/.spike/p2-router.js`.
|
|
465
|
-
Before touching anything for a new DSH release, read the local-only `docs/MAINTENANCE.md` (§2 coupling points, §3 checklist) — it is gitignored, so a clone will not have it. After any change (host half or client half) the mandatory steps are: `pnpm run build` → `node scripts/verify-lib.mjs` (entries present, committed and loadable) → restart `dsh web`; and before committing, run every local gate under `scripts/` (`node scripts/check-*.mjs`,
|
|
465
|
+
Before touching anything for a new DSH release, read the local-only `docs/MAINTENANCE.md` (§2 coupling points, §3 checklist) — it is gitignored, so a clone will not have it. After any change (host half or client half) the mandatory steps are: `pnpm run build` → `node scripts/verify-lib.mjs` (entries present, committed and loadable) → restart `dsh web`; and before committing, run every local gate under `scripts/` (`node scripts/check-*.mjs`, 57 of them at the time of writing, plus `verify-lib.mjs` and the shared TS loader `_ts-hook.mjs`).
|
|
466
466
|
|
|
467
467
|
## License
|
|
468
468
|
|
package/README.md
CHANGED
|
@@ -413,7 +413,7 @@ node .spike/letter-check.mjs # 状态字母:未跟踪 ? 与冲突 U 不再
|
|
|
413
413
|
> 失败时才触发,所以「调用点 57」与「跑出来 55」本来就该差 2)。
|
|
414
414
|
|
|
415
415
|
真机回归仍是 `npx tsc -p tsconfig.scratch.json && node .spike/build/.spike/p2-router.js`。
|
|
416
|
-
DSH 发新版时先读本地维护文档 `docs/MAINTENANCE.md`(§2 逐项耦合点 + §3 升级清单)再动手;该文件被 .gitignore,克隆仓库的人看不到。改动后(无论 host 半还是 client 半)的必做动作是:`pnpm run build` → `node scripts/verify-lib.mjs`(核对 `lib/` 齐全、已入库、能加载)→ 重启 `dsh web`,提交前把 `scripts/` 下的本地门禁逐个跑一遍(`node scripts/check-*.mjs`,当前
|
|
416
|
+
DSH 发新版时先读本地维护文档 `docs/MAINTENANCE.md`(§2 逐项耦合点 + §3 升级清单)再动手;该文件被 .gitignore,克隆仓库的人看不到。改动后(无论 host 半还是 client 半)的必做动作是:`pnpm run build` → `node scripts/verify-lib.mjs`(核对 `lib/` 齐全、已入库、能加载)→ 重启 `dsh web`,提交前把 `scripts/` 下的本地门禁逐个跑一遍(`node scripts/check-*.mjs`,当前 57 个;另有 `verify-lib.mjs` 与共享 TS 加载器 `_ts-hook.mjs`)。
|
|
417
417
|
|
|
418
418
|
## 开源许可
|
|
419
419
|
|
package/lib/client.js
CHANGED
|
@@ -23269,6 +23269,17 @@ window.__ModuleLoader__.load({
|
|
|
23269
23269
|
run: toggleTabFocusMode
|
|
23270
23270
|
}
|
|
23271
23271
|
].concat(standardKeymap);
|
|
23272
|
+
/**
|
|
23273
|
+
A binding that binds Tab to [`indentMore`](https://codemirror.net/6/docs/ref/#commands.indentMore) and
|
|
23274
|
+
Shift-Tab to [`indentLess`](https://codemirror.net/6/docs/ref/#commands.indentLess).
|
|
23275
|
+
Please see the [Tab example](../../examples/tab/) before using
|
|
23276
|
+
this.
|
|
23277
|
+
*/
|
|
23278
|
+
const indentWithTab = {
|
|
23279
|
+
key: "Tab",
|
|
23280
|
+
run: indentMore,
|
|
23281
|
+
shift: indentLess
|
|
23282
|
+
};
|
|
23272
23283
|
//#endregion
|
|
23273
23284
|
//#region node_modules/.pnpm/@codemirror+autocomplete@6.20.3/node_modules/@codemirror/autocomplete/dist/index.js
|
|
23274
23285
|
/**
|
|
@@ -25691,14 +25702,15 @@ window.__ModuleLoader__.load({
|
|
|
25691
25702
|
* Icon sourcing has two tiers. `FileIcon` / `FolderIcon` paint the plain glyphs
|
|
25692
25703
|
* below (search hits, SCM rows, commit panes, download rows — list chrome where
|
|
25693
25704
|
* one neutral outline reads best). `ExplorerFileIcon` / `ExplorerFolderIcon`
|
|
25694
|
-
* paint the COLOURED type set ported from
|
|
25695
|
-
* the remote directory tree looks like the local
|
|
25696
|
-
* whose colour and mark carry the file type, and an
|
|
25705
|
+
* paint the COLOURED type set ported from the local sidebar plugin in
|
|
25706
|
+
* `./file-icons.tsx`, so the remote directory tree looks like the local
|
|
25707
|
+
* sidebar's tree: one sheet whose colour and mark carry the file type, and an
|
|
25708
|
+
* amber folder that opens.
|
|
25697
25709
|
*
|
|
25698
25710
|
* Every tier still prefers the host service when one is published (the
|
|
25699
|
-
* better-sidebar
|
|
25700
|
-
* registered icon theme).
|
|
25701
|
-
*
|
|
25711
|
+
* better-sidebar contract's `fileIcon` / `folderIcon`: host classifier plus any
|
|
25712
|
+
* registered icon theme). That plugin publishes none today, so with the local
|
|
25713
|
+
* sidebar installed the SVG sets above are what actually render.
|
|
25702
25714
|
*/
|
|
25703
25715
|
function svg(size, children, className) {
|
|
25704
25716
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
@@ -26957,6 +26969,83 @@ window.__ModuleLoader__.load({
|
|
|
26957
26969
|
});
|
|
26958
26970
|
}
|
|
26959
26971
|
//#endregion
|
|
26972
|
+
//#region src/client/vsc/editor-keymap.ts
|
|
26973
|
+
/**
|
|
26974
|
+
* Build the editor keymap.
|
|
26975
|
+
*
|
|
26976
|
+
* Order: the stock keymaps first, then the two additions that make this editor
|
|
26977
|
+
* behave like VS Code — `indentWithTab` (Tab / Shift-Tab indent or dedent) and
|
|
26978
|
+
* our own shortcuts. `indentWithTab` is deliberately NOT part of CodeMirror's
|
|
26979
|
+
* defaults, which is exactly what shipped the "Tab does nothing" bug; a red
|
|
26980
|
+
* proof in the gate removes it again.
|
|
26981
|
+
*/
|
|
26982
|
+
function editorKeymap(handlers) {
|
|
26983
|
+
return [
|
|
26984
|
+
...defaultKeymap,
|
|
26985
|
+
...historyKeymap,
|
|
26986
|
+
indentWithTab,
|
|
26987
|
+
{
|
|
26988
|
+
key: "Mod-s",
|
|
26989
|
+
run: () => {
|
|
26990
|
+
handlers.save();
|
|
26991
|
+
return true;
|
|
26992
|
+
},
|
|
26993
|
+
preventDefault: true
|
|
26994
|
+
},
|
|
26995
|
+
{
|
|
26996
|
+
key: "Mod-f",
|
|
26997
|
+
run: (view) => {
|
|
26998
|
+
handlers.openFindForSelection(view);
|
|
26999
|
+
return true;
|
|
27000
|
+
},
|
|
27001
|
+
preventDefault: true
|
|
27002
|
+
},
|
|
27003
|
+
{
|
|
27004
|
+
key: "F3",
|
|
27005
|
+
run: (view) => {
|
|
27006
|
+
handlers.stepFind(view, true);
|
|
27007
|
+
return true;
|
|
27008
|
+
},
|
|
27009
|
+
preventDefault: true
|
|
27010
|
+
},
|
|
27011
|
+
{
|
|
27012
|
+
key: "Shift-F3",
|
|
27013
|
+
run: (view) => {
|
|
27014
|
+
handlers.stepFind(view, false);
|
|
27015
|
+
return true;
|
|
27016
|
+
},
|
|
27017
|
+
preventDefault: true
|
|
27018
|
+
},
|
|
27019
|
+
(
|
|
27020
|
+
/**
|
|
27021
|
+
* Previous / next change hunk.
|
|
27022
|
+
*
|
|
27023
|
+
* `Mod-Shift-Alt-ArrowUp/Down` is the free combination: defaultKeymap already
|
|
27024
|
+
* uses `Mod-Alt-Arrow*` (multi-cursor), `Alt-Arrow*` (move line) and
|
|
27025
|
+
* `Shift-Alt-Arrow*` (copy line), and browsers leave this extra Shift alone.
|
|
27026
|
+
*
|
|
27027
|
+
* NO `preventDefault: true` here, deliberately: CodeMirror prevents the
|
|
27028
|
+
* default whenever a binding for that key sets the flag, even if every
|
|
27029
|
+
* command returns false (view keymap `runFor`). With the panel closed the
|
|
27030
|
+
* handler returns false, and the key must fall through instead of being
|
|
27031
|
+
* swallowed — the 2026-11-10 gate found this latent swallow while pinning
|
|
27032
|
+
* the Tab fix.
|
|
27033
|
+
*/
|
|
27034
|
+
{
|
|
27035
|
+
key: "Mod-Shift-Alt-ArrowDown",
|
|
27036
|
+
run: () => handlers.stepHunk(1)
|
|
27037
|
+
}),
|
|
27038
|
+
{
|
|
27039
|
+
key: "Mod-Shift-Alt-ArrowUp",
|
|
27040
|
+
run: () => handlers.stepHunk(-1)
|
|
27041
|
+
},
|
|
27042
|
+
{
|
|
27043
|
+
key: "Escape",
|
|
27044
|
+
run: () => handlers.closeFind()
|
|
27045
|
+
}
|
|
27046
|
+
];
|
|
27047
|
+
}
|
|
27048
|
+
//#endregion
|
|
26960
27049
|
//#region node_modules/.pnpm/@lezer+lr@1.4.11/node_modules/@lezer/lr/dist/index.js
|
|
26961
27050
|
/**
|
|
26962
27051
|
A parse stack. These are used internally by the parser to track
|
|
@@ -41214,91 +41303,36 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
|
|
|
41214
41303
|
if (host === null) return;
|
|
41215
41304
|
const extensions = [
|
|
41216
41305
|
history(),
|
|
41217
|
-
keymap.of(
|
|
41218
|
-
|
|
41219
|
-
|
|
41220
|
-
{
|
|
41221
|
-
key: "Mod-s",
|
|
41222
|
-
run: () => {
|
|
41223
|
-
propsRef.current.onSave();
|
|
41224
|
-
return true;
|
|
41225
|
-
},
|
|
41226
|
-
preventDefault: true
|
|
41227
|
-
},
|
|
41228
|
-
{
|
|
41229
|
-
key: "Mod-f",
|
|
41230
|
-
run: (view) => {
|
|
41231
|
-
const sel = view.state.selection.main;
|
|
41232
|
-
if (!sel.empty) {
|
|
41233
|
-
const text = view.state.sliceDoc(sel.from, sel.to);
|
|
41234
|
-
if (text !== "" && text.length <= 200) setFindSeed((prev) => ({
|
|
41235
|
-
text,
|
|
41236
|
-
id: prev.id + 1
|
|
41237
|
-
}));
|
|
41238
|
-
}
|
|
41239
|
-
setFindOpen(true);
|
|
41240
|
-
return true;
|
|
41241
|
-
},
|
|
41242
|
-
preventDefault: true
|
|
41306
|
+
keymap.of(editorKeymap({
|
|
41307
|
+
save: () => {
|
|
41308
|
+
propsRef.current.onSave();
|
|
41243
41309
|
},
|
|
41244
|
-
{
|
|
41245
|
-
|
|
41246
|
-
|
|
41247
|
-
|
|
41248
|
-
|
|
41249
|
-
|
|
41250
|
-
|
|
41310
|
+
openFindForSelection: (view) => {
|
|
41311
|
+
const sel = view.state.selection.main;
|
|
41312
|
+
if (!sel.empty) {
|
|
41313
|
+
const text = view.state.sliceDoc(sel.from, sel.to);
|
|
41314
|
+
if (text !== "" && text.length <= 200) setFindSeed((prev) => ({
|
|
41315
|
+
text,
|
|
41316
|
+
id: prev.id + 1
|
|
41317
|
+
}));
|
|
41318
|
+
}
|
|
41319
|
+
setFindOpen(true);
|
|
41251
41320
|
},
|
|
41252
|
-
{
|
|
41253
|
-
|
|
41254
|
-
run: (view) => {
|
|
41255
|
-
stepFind(view, false);
|
|
41256
|
-
return true;
|
|
41257
|
-
},
|
|
41258
|
-
preventDefault: true
|
|
41321
|
+
stepFind: (view, forward) => {
|
|
41322
|
+
stepFind(view, forward);
|
|
41259
41323
|
},
|
|
41260
|
-
(
|
|
41261
|
-
|
|
41262
|
-
|
|
41263
|
-
|
|
41264
|
-
|
|
41265
|
-
* defaultKeymap 里 `Mod-Alt-ArrowUp/Down`(多光标)、`Alt-ArrowUp/Down`
|
|
41266
|
-
* (移动行)、`Shift-Alt-ArrowUp/Down`(复制行)都被占了,三者之上再加
|
|
41267
|
-
* Shift 的这两个组合它没有用;浏览器侧 Ctrl+Shift+Alt+方向键也没有默认
|
|
41268
|
-
* 行为(选中/滚动都落在更低的组合上)。
|
|
41269
|
-
*
|
|
41270
|
-
* 没有 `onStepHunk`(面板没开)时返回 false,按键照旧落回 CodeMirror 的
|
|
41271
|
-
* 默认处理,不会平白吞掉一个组合键。
|
|
41272
|
-
*/
|
|
41273
|
-
{
|
|
41274
|
-
key: "Mod-Shift-Alt-ArrowDown",
|
|
41275
|
-
run: () => {
|
|
41276
|
-
const step = propsRef.current.onStepHunk;
|
|
41277
|
-
if (step === void 0) return false;
|
|
41278
|
-
step(1);
|
|
41279
|
-
return true;
|
|
41280
|
-
},
|
|
41281
|
-
preventDefault: true
|
|
41282
|
-
}),
|
|
41283
|
-
{
|
|
41284
|
-
key: "Mod-Shift-Alt-ArrowUp",
|
|
41285
|
-
run: () => {
|
|
41286
|
-
const step = propsRef.current.onStepHunk;
|
|
41287
|
-
if (step === void 0) return false;
|
|
41288
|
-
step(-1);
|
|
41289
|
-
return true;
|
|
41290
|
-
},
|
|
41291
|
-
preventDefault: true
|
|
41324
|
+
stepHunk: (delta) => {
|
|
41325
|
+
const step = propsRef.current.onStepHunk;
|
|
41326
|
+
if (step === void 0) return false;
|
|
41327
|
+
step(delta);
|
|
41328
|
+
return true;
|
|
41292
41329
|
},
|
|
41293
|
-
{
|
|
41294
|
-
|
|
41295
|
-
|
|
41296
|
-
|
|
41297
|
-
setFindOpen(false);
|
|
41298
|
-
return true;
|
|
41299
|
-
}
|
|
41330
|
+
closeFind: () => {
|
|
41331
|
+
if (!findOpenRef.current) return false;
|
|
41332
|
+
setFindOpen(false);
|
|
41333
|
+
return true;
|
|
41300
41334
|
}
|
|
41301
|
-
|
|
41335
|
+
})),
|
|
41302
41336
|
lineNumbers(),
|
|
41303
41337
|
highlightActiveLine(),
|
|
41304
41338
|
indentOnInput(),
|
|
@@ -41550,7 +41584,7 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
|
|
|
41550
41584
|
const primary = host.querySelectorAll("[class*=\"rvs-ck-\"]").length;
|
|
41551
41585
|
const fallback = host.querySelectorAll("span[class^=\"rvs-t-\"]").length;
|
|
41552
41586
|
const count = primary > 0 ? primary : fallback;
|
|
41553
|
-
console.info(`[dsh-remote-vs] build
|
|
41587
|
+
console.info(`[dsh-remote-vs] build 1110-1823 · ${source} · colored tokens: ${count} (${propsRef.current.path})`);
|
|
41554
41588
|
propsRef.current.onTokens?.(count);
|
|
41555
41589
|
};
|
|
41556
41590
|
const armFallback = () => {
|
|
@@ -48774,8 +48808,8 @@ Integer Float Double Long Int32 Int64 Uint8 uint32_t int32_t uint64_t int64_t si
|
|
|
48774
48808
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConnectionStatusChip, { compact: true }),
|
|
48775
48809
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
48776
48810
|
className: "rvs-build",
|
|
48777
|
-
title: `dsh-remote-vs build
|
|
48778
|
-
children: "
|
|
48811
|
+
title: `dsh-remote-vs build 1110-1823`,
|
|
48812
|
+
children: "1110-1823"
|
|
48779
48813
|
}),
|
|
48780
48814
|
tokenCount !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
48781
48815
|
className: "rvs-build",
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as keysDir, S as ensurePrivateDir, _ as clampExecTimeout, a as probe, b as aliasRoot, c as RemoteFiles, d as DEFAULT_GIT_TIMEOUT_MS, f as DEFAULT_READ_TIMEOUT_MS, g as MIN_TIMEOUT_MS, h as MAX_TIMEOUT_MS, i as helperAvailability, l as WriteConflictError, m as DeadlineError, n as TombstonedError, o as pushPipeline, p as DEFAULT_TIMEOUTS, s as seedHelperCache, t as RemoteWorlds, u as attachmentHeader, v as resolveTimeouts, w as storePath, x as dshHome, y as require_lib } from "./worlds-DSzyajOB.js";
|
|
2
2
|
import z from "@deepseek-ai/schemastery";
|
|
3
3
|
import { chmodSync, closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, statSync, writeSync } from "node:fs";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -4661,6 +4661,130 @@ function makeRoutes(deps) {
|
|
|
4661
4661
|
};
|
|
4662
4662
|
}
|
|
4663
4663
|
//#endregion
|
|
4664
|
+
//#region src/preset-switch.ts
|
|
4665
|
+
/**
|
|
4666
|
+
* Auto-switch decision for a new session born in a remote workspace.
|
|
4667
|
+
*
|
|
4668
|
+
* Why this module is pure
|
|
4669
|
+
* -----------------------
|
|
4670
|
+
* The 2026-11-10 bug was "sometimes no preset switch about 3 s after creating a
|
|
4671
|
+
* session". Two independent causes had to be found by reading the Host:
|
|
4672
|
+
*
|
|
4673
|
+
* 1. **The switch only listened to `source === 'startup'`.** The Web client does
|
|
4674
|
+
* not always mint a session: `session.create` accepts a named BLANK session
|
|
4675
|
+
* and reuses it (`createInWorkspace` passes the first listed blank id), which
|
|
4676
|
+
* the Host answers through `agents.resume` → `agent/created` with source
|
|
4677
|
+
* `'resume'`. Those sessions never even armed the timer.
|
|
4678
|
+
* 2. **A single 2.5 s shot lost every transient state.** At fire time the preset
|
|
4679
|
+
* may not be composed yet, the working directory may be unreadable, or the
|
|
4680
|
+
* workspace binding may not be listed; each guard returned silently, and the
|
|
4681
|
+
* one chance was spent.
|
|
4682
|
+
*
|
|
4683
|
+
* The fix keeps the "never block session creation" contract and turns the
|
|
4684
|
+
* decision into a pure function plus a bounded retry loop, so every branch is
|
|
4685
|
+
* covered by a gate instead of being inferred from a silent return.
|
|
4686
|
+
*
|
|
4687
|
+
* Blankness — no turn started — is the real precondition (`presets.select`
|
|
4688
|
+
* enforces exactly that), and it is also what excludes resumed sessions with
|
|
4689
|
+
* history. The event source only told us how the session came to be.
|
|
4690
|
+
*/
|
|
4691
|
+
/** Preset id this plugin switches remote sessions to (see `cordis.patch.yml`). */
|
|
4692
|
+
const REMOTE_PRESET_ID = "remote";
|
|
4693
|
+
/** Delay before each attempt, in order. The first attempt keeps the old 2.5 s. */
|
|
4694
|
+
const PRESET_SWITCH_DELAYS_MS = [
|
|
4695
|
+
2500,
|
|
4696
|
+
1e3,
|
|
4697
|
+
1500,
|
|
4698
|
+
2e3,
|
|
4699
|
+
3e3
|
|
4700
|
+
];
|
|
4701
|
+
/**
|
|
4702
|
+
* Decide one attempt.
|
|
4703
|
+
*
|
|
4704
|
+
* Order matters: the terminal reasons come first (config, history, user choice),
|
|
4705
|
+
* then the transient ones (composed preset, cwd, route), then the switch.
|
|
4706
|
+
*/
|
|
4707
|
+
function decidePresetSwitch(facts) {
|
|
4708
|
+
if (facts.mode !== "enforce") return {
|
|
4709
|
+
action: "stop",
|
|
4710
|
+
reason: "routing-off"
|
|
4711
|
+
};
|
|
4712
|
+
if (!facts.hasPresets) return {
|
|
4713
|
+
action: "stop",
|
|
4714
|
+
reason: "presets-absent"
|
|
4715
|
+
};
|
|
4716
|
+
if (!facts.blank) return {
|
|
4717
|
+
action: "stop",
|
|
4718
|
+
reason: "not-blank"
|
|
4719
|
+
};
|
|
4720
|
+
if (facts.currentPreset === "remote") return {
|
|
4721
|
+
action: "stop",
|
|
4722
|
+
reason: "already-remote"
|
|
4723
|
+
};
|
|
4724
|
+
if (facts.currentPreset === void 0) return {
|
|
4725
|
+
action: "retry",
|
|
4726
|
+
reason: "preset-unbound"
|
|
4727
|
+
};
|
|
4728
|
+
if (facts.currentPreset !== facts.defaultPreset) return {
|
|
4729
|
+
action: "stop",
|
|
4730
|
+
reason: "custom-preset"
|
|
4731
|
+
};
|
|
4732
|
+
if (facts.cwd.trim() === "") return {
|
|
4733
|
+
action: "retry",
|
|
4734
|
+
reason: "cwd-unavailable"
|
|
4735
|
+
};
|
|
4736
|
+
if (facts.tombstoned) return {
|
|
4737
|
+
action: "stop",
|
|
4738
|
+
reason: "tombstoned"
|
|
4739
|
+
};
|
|
4740
|
+
if (facts.remote === void 0) return {
|
|
4741
|
+
action: "retry",
|
|
4742
|
+
reason: "route-unknown"
|
|
4743
|
+
};
|
|
4744
|
+
if (!facts.remote) return {
|
|
4745
|
+
action: "stop",
|
|
4746
|
+
reason: "local-session"
|
|
4747
|
+
};
|
|
4748
|
+
return { action: "switch" };
|
|
4749
|
+
}
|
|
4750
|
+
/** Wait for `ms`, unref'd so a pending switch never keeps the Host alive. */
|
|
4751
|
+
function defaultSleep(ms) {
|
|
4752
|
+
return new Promise((resolve) => {
|
|
4753
|
+
setTimeout(resolve, ms).unref?.();
|
|
4754
|
+
});
|
|
4755
|
+
}
|
|
4756
|
+
/**
|
|
4757
|
+
* Run attempts with the given delays until one stops or switches.
|
|
4758
|
+
*
|
|
4759
|
+
* A retry is only worth spending for the transient reasons the planner names;
|
|
4760
|
+
* the loop itself does not re-classify, so a future terminal reason added to the
|
|
4761
|
+
* planner stays terminal automatically.
|
|
4762
|
+
*
|
|
4763
|
+
* @returns the last attempt and how many attempts were used (1-based).
|
|
4764
|
+
*/
|
|
4765
|
+
async function runPresetSwitchAttempts(attempt, sleep = defaultSleep, delays = PRESET_SWITCH_DELAYS_MS) {
|
|
4766
|
+
let last;
|
|
4767
|
+
let attempts = 0;
|
|
4768
|
+
for (const delay of delays) {
|
|
4769
|
+
attempts += 1;
|
|
4770
|
+
await sleep(delay);
|
|
4771
|
+
last = await attempt();
|
|
4772
|
+
if (last.step.action !== "retry") return {
|
|
4773
|
+
step: last.step,
|
|
4774
|
+
facts: last.facts,
|
|
4775
|
+
attempts
|
|
4776
|
+
};
|
|
4777
|
+
}
|
|
4778
|
+
return {
|
|
4779
|
+
step: last === void 0 ? {
|
|
4780
|
+
action: "stop",
|
|
4781
|
+
reason: "services-absent"
|
|
4782
|
+
} : last.step,
|
|
4783
|
+
facts: last?.facts,
|
|
4784
|
+
attempts
|
|
4785
|
+
};
|
|
4786
|
+
}
|
|
4787
|
+
//#endregion
|
|
4664
4788
|
//#region src/changes/status.ts
|
|
4665
4789
|
/** Exit statuses of the read commands (git's own statuses pass through as-is). */
|
|
4666
4790
|
const READ_EXIT = {
|
|
@@ -6817,43 +6941,117 @@ function apply(ctx, config) {
|
|
|
6817
6941
|
ctx.on("loader/volatile-update", () => {
|
|
6818
6942
|
sync();
|
|
6819
6943
|
});
|
|
6944
|
+
/**
|
|
6945
|
+
* Preset auto-switch for a new session born in a remote workspace (Phase 4b).
|
|
6946
|
+
*
|
|
6947
|
+
* 2026-11-10, bug "sometimes no Remote preset ~3 s after creating a session":
|
|
6948
|
+
*
|
|
6949
|
+
* - The Web client does not always MINT a session. `createInWorkspace` reuses
|
|
6950
|
+
* the first listed BLANK session of the workspace by passing its id, and the
|
|
6951
|
+
* Host answers that through `agents.resume` → `agent/created` with source
|
|
6952
|
+
* `'resume'`. The old `source !== 'startup'` guard silently skipped exactly
|
|
6953
|
+
* those sessions. Blankness (no turn started) is the precondition the preset
|
|
6954
|
+
* registry itself enforces, so it is what we check now — a resumed session
|
|
6955
|
+
* with history is excluded by it.
|
|
6956
|
+
* - One 2.5 s shot also lost every transient state: the preset may not be
|
|
6957
|
+
* composed yet, the working directory may be unreadable, or the workspace
|
|
6958
|
+
* binding may not be listed. `runPresetSwitchAttempts` retries those for a
|
|
6959
|
+
* bounded time and stops on terminal reasons (routing off, history, user's
|
|
6960
|
+
* own preset, local directory).
|
|
6961
|
+
*
|
|
6962
|
+
* The listener still DETACHES: it returns immediately, so session creation
|
|
6963
|
+
* never waits for a switch (the original 2026-10-13 race: selecting during
|
|
6964
|
+
* creation while both preset trees register tools could kill the session).
|
|
6965
|
+
* Failure modes are logged, never thrown; manual selection stays the fallback.
|
|
6966
|
+
*/
|
|
6967
|
+
const attemptPresetSwitch = async (agent) => {
|
|
6968
|
+
const presets = ctx.get("agentPresets");
|
|
6969
|
+
const agents = ctx.get("agents");
|
|
6970
|
+
const workingDirectory = ctx.get("workingDirectory");
|
|
6971
|
+
let boundary;
|
|
6972
|
+
try {
|
|
6973
|
+
boundary = agents?.turnBoundaryOf?.(agent.session);
|
|
6974
|
+
} catch {
|
|
6975
|
+
boundary = void 0;
|
|
6976
|
+
}
|
|
6977
|
+
let cwd = "";
|
|
6978
|
+
try {
|
|
6979
|
+
const current = workingDirectory?.get?.(agent.session);
|
|
6980
|
+
if (typeof current === "string") cwd = current;
|
|
6981
|
+
} catch {}
|
|
6982
|
+
let remote;
|
|
6983
|
+
let tombstoned = false;
|
|
6984
|
+
if (cwd !== "") try {
|
|
6985
|
+
remote = worlds.routeDir(cwd).kind === "remote";
|
|
6986
|
+
} catch (error) {
|
|
6987
|
+
if (error instanceof TombstonedError) tombstoned = true;
|
|
6988
|
+
}
|
|
6989
|
+
let currentPreset;
|
|
6990
|
+
let defaultPreset;
|
|
6991
|
+
try {
|
|
6992
|
+
currentPreset = presets?.composedPreset(agent.ctx);
|
|
6993
|
+
defaultPreset = presets?.defaultId;
|
|
6994
|
+
} catch {
|
|
6995
|
+
currentPreset = void 0;
|
|
6996
|
+
defaultPreset = void 0;
|
|
6997
|
+
}
|
|
6998
|
+
const facts = {
|
|
6999
|
+
mode: worlds.mode,
|
|
7000
|
+
hasPresets: presets !== void 0,
|
|
7001
|
+
blank: boundary !== void 0 && boundary.openTurnStartSeq === null && boundary.lastTurn === 0,
|
|
7002
|
+
cwd,
|
|
7003
|
+
remote,
|
|
7004
|
+
tombstoned,
|
|
7005
|
+
currentPreset,
|
|
7006
|
+
defaultPreset
|
|
7007
|
+
};
|
|
7008
|
+
const step = decidePresetSwitch(facts);
|
|
7009
|
+
if (step.action !== "switch") return {
|
|
7010
|
+
step,
|
|
7011
|
+
facts
|
|
7012
|
+
};
|
|
7013
|
+
if (presets === void 0) return {
|
|
7014
|
+
step: {
|
|
7015
|
+
action: "stop",
|
|
7016
|
+
reason: "presets-absent"
|
|
7017
|
+
},
|
|
7018
|
+
facts
|
|
7019
|
+
};
|
|
7020
|
+
try {
|
|
7021
|
+
await presets.select(agent, REMOTE_PRESET_ID);
|
|
7022
|
+
return {
|
|
7023
|
+
step: {
|
|
7024
|
+
action: "stop",
|
|
7025
|
+
reason: "switched"
|
|
7026
|
+
},
|
|
7027
|
+
facts
|
|
7028
|
+
};
|
|
7029
|
+
} catch (error) {
|
|
7030
|
+
const locked = error instanceof Error && /locked|already started/i.test(error.message);
|
|
7031
|
+
return {
|
|
7032
|
+
step: {
|
|
7033
|
+
action: locked ? "stop" : "retry",
|
|
7034
|
+
reason: locked ? "locked" : "select-failed"
|
|
7035
|
+
},
|
|
7036
|
+
facts
|
|
7037
|
+
};
|
|
7038
|
+
}
|
|
7039
|
+
};
|
|
6820
7040
|
ctx.on("agent/created", (payload) => {
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
7041
|
+
(async () => {
|
|
7042
|
+
try {
|
|
7043
|
+
const { step, facts, attempts } = await runPresetSwitchAttempts(() => attemptPresetSwitch(payload.agent));
|
|
6824
7044
|
try {
|
|
6825
|
-
|
|
6826
|
-
if (
|
|
6827
|
-
if (
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6834
|
-
|
|
6835
|
-
} catch {
|
|
6836
|
-
return;
|
|
6837
|
-
}
|
|
6838
|
-
let remote = false;
|
|
6839
|
-
try {
|
|
6840
|
-
remote = worlds.routeDir(cwd).kind === "remote";
|
|
6841
|
-
} catch {
|
|
6842
|
-
return;
|
|
6843
|
-
}
|
|
6844
|
-
if (!remote) return;
|
|
6845
|
-
await presets.select(payload.agent, "remote");
|
|
6846
|
-
try {
|
|
6847
|
-
ctx.logger.info(`[remote-vs] new remote session entered ${cwd}; preset switched to remote`);
|
|
6848
|
-
} catch {}
|
|
6849
|
-
} catch (error) {
|
|
6850
|
-
if (error instanceof Error && /locked|already started/i.test(error.message)) return;
|
|
6851
|
-
try {
|
|
6852
|
-
ctx.logger.warn(`[remote-vs] preset auto-switch skipped: ${error instanceof Error ? error.message : String(error)}`);
|
|
6853
|
-
} catch {}
|
|
6854
|
-
}
|
|
6855
|
-
})();
|
|
6856
|
-
}, 2500).unref?.();
|
|
7045
|
+
if (step.reason === "switched" && facts?.remote === true) ctx.logger.info(`[remote-vs] remote session ${facts.cwd}: preset switched to ${REMOTE_PRESET_ID} after ${attempts} attempt(s)`);
|
|
7046
|
+
else if (step.action === "retry") ctx.logger.warn(`[remote-vs] preset auto-switch gave up after ${attempts} attempt(s): ${step.reason}`);
|
|
7047
|
+
else if (facts?.remote === true) ctx.logger.info(`[remote-vs] preset auto-switch skipped for ${facts.cwd}: ${step.reason}`);
|
|
7048
|
+
} catch {}
|
|
7049
|
+
} catch (error) {
|
|
7050
|
+
try {
|
|
7051
|
+
ctx.logger.warn(`[remote-vs] preset auto-switch skipped: ${error instanceof Error ? error.message : String(error)}`);
|
|
7052
|
+
} catch {}
|
|
7053
|
+
}
|
|
7054
|
+
})();
|
|
6857
7055
|
});
|
|
6858
7056
|
sync();
|
|
6859
7057
|
}
|
package/lib/p2-router-fs.js
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The editor's key bindings, in one testable place.
|
|
3
|
+
*
|
|
4
|
+
* Why this module exists
|
|
5
|
+
* ----------------------
|
|
6
|
+
* Bug (2026-11-10, user report): "the remote editor cannot input Tab".
|
|
7
|
+
*
|
|
8
|
+
* CodeMirror 6's `defaultKeymap` deliberately does NOT bind Tab — the browser
|
|
9
|
+
* default (move focus) stays available for accessibility. Indentation is the
|
|
10
|
+
* opt-in `indentWithTab` binding, and this plugin never added it, so Tab fell
|
|
11
|
+
* through to the browser: the caret left the editor instead of indenting. The
|
|
12
|
+
* local sidebar editor binds it, which is why the same key worked there.
|
|
13
|
+
*
|
|
14
|
+
* The binding list used to live inline inside the CodeMirror mount effect, which
|
|
15
|
+
* meant the only way to test it was to render the whole component. It lives here
|
|
16
|
+
* so `scripts/check-editor-tab.mjs` can mount a real CodeMirror with the REAL
|
|
17
|
+
* binding list and dispatch real Tab/Shift-Tab presses.
|
|
18
|
+
*
|
|
19
|
+
* Handlers are injected (no React, no editor state): the component wires them to
|
|
20
|
+
* its refs/stores.
|
|
21
|
+
*/
|
|
22
|
+
import type { EditorView, KeyBinding } from '@codemirror/view';
|
|
23
|
+
/** The editor actions the key bindings dispatch into. */
|
|
24
|
+
export interface EditorKeyHandlers {
|
|
25
|
+
/** Ctrl/Cmd+S → the pane's save path. */
|
|
26
|
+
save(): void;
|
|
27
|
+
/** Ctrl/Cmd+F → seed our find widget from the selection and open it. */
|
|
28
|
+
openFindForSelection(view: EditorView): void;
|
|
29
|
+
/** F3 / Shift+F3 → step through matches. */
|
|
30
|
+
stepFind(view: EditorView, forward: boolean): void;
|
|
31
|
+
/** Jump to the previous/next change hunk; false when the panel is closed. */
|
|
32
|
+
stepHunk(delta: 1 | -1): boolean;
|
|
33
|
+
/** Escape → close the find widget; false when it was not open. */
|
|
34
|
+
closeFind(): boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Build the editor keymap.
|
|
38
|
+
*
|
|
39
|
+
* Order: the stock keymaps first, then the two additions that make this editor
|
|
40
|
+
* behave like VS Code — `indentWithTab` (Tab / Shift-Tab indent or dedent) and
|
|
41
|
+
* our own shortcuts. `indentWithTab` is deliberately NOT part of CodeMirror's
|
|
42
|
+
* defaults, which is exactly what shipped the "Tab does nothing" bug; a red
|
|
43
|
+
* proof in the gate removes it again.
|
|
44
|
+
*/
|
|
45
|
+
export declare function editorKeymap(handlers: EditorKeyHandlers): KeyBinding[];
|
|
@@ -8,19 +8,18 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Provenance
|
|
10
10
|
* ----------
|
|
11
|
-
* These are a straight port of the local sidebar plugin
|
|
12
|
-
* and its amber
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* `.gitignore` orange + a commit graph.
|
|
11
|
+
* These are a straight port of the icon set the local sidebar plugin draws
|
|
12
|
+
* (`FileTypeIcon` and its amber folder icon): one paper sheet whose colour and
|
|
13
|
+
* bottom-right mark carry the type — TS blue + `<>`, JS yellow + `<>`, Python
|
|
14
|
+
* blue with a yellow mark, Markdown blue + lines, images purple + a mountain,
|
|
15
|
+
* archives yellow + a zip, `.gitignore` orange + a commit graph.
|
|
17
16
|
*
|
|
18
17
|
* The copy exists on purpose: the client bundle may not import another plugin's
|
|
19
|
-
* values (tsdown's purity gate rejects cross-plugin imports), and
|
|
18
|
+
* values (tsdown's purity gate rejects cross-plugin imports), and that plugin
|
|
20
19
|
* publishes no `fileIcon` / `folderIcon` service that `kit.tsx` could call.
|
|
21
20
|
* `kit.tsx` still prefers such a service if a host ever provides one (the
|
|
22
|
-
* better-sidebar
|
|
23
|
-
*
|
|
21
|
+
* better-sidebar contract is where it would come from); this set is the
|
|
22
|
+
* fallback that paints a real, typed tree whenever that plugin is present.
|
|
24
23
|
*
|
|
25
24
|
* One deliberate difference from the source: the image mark used
|
|
26
25
|
* `fill="currentColor"`, which in a tree inherits the row's dim text colour —
|