dsh-remote-vs 0.13.0 → 0.15.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.
Files changed (128) hide show
  1. package/README.en.md +455 -443
  2. package/README.md +408 -396
  3. package/lib/client.js +8062 -2651
  4. package/lib/index.js +1058 -288
  5. package/lib/p2-router-fs.js +1 -1
  6. package/lib/p2-router-refs.js +89 -10
  7. package/lib/p2-router-spill.js +73 -1
  8. package/lib/p2-router-subprocess.js +18 -6
  9. package/lib/spill-retention-BwKEWrl5.js +115 -0
  10. package/lib/{ssh-proc-arI5lm4W.js → ssh-proc-VKWn_LZC.js} +17 -0
  11. package/lib/types/archive.d.ts +1 -1
  12. package/lib/types/changes/recorder.d.ts +34 -2
  13. package/lib/types/client/CodeEditor.d.ts +12 -0
  14. package/lib/types/client/ConnectionStatus.d.ts +17 -0
  15. package/lib/types/client/DirectoryFlow.d.ts +2 -0
  16. package/lib/types/client/DoctorPanel.d.ts +25 -0
  17. package/lib/types/client/QuickOpen.d.ts +17 -0
  18. package/lib/types/client/RemoteExplorer.d.ts +192 -1
  19. package/lib/types/client/RemoteRoot.d.ts +17 -0
  20. package/lib/types/client/SearchView.d.ts +55 -0
  21. package/lib/types/client/TerminalView.d.ts +38 -0
  22. package/lib/types/client/WorkspaceWizard.d.ts +17 -0
  23. package/lib/types/client/api.d.ts +54 -4
  24. package/lib/types/client/changes/undo-affordance.d.ts +16 -0
  25. package/lib/types/client/changes/undo-context.d.ts +14 -18
  26. package/lib/types/client/changes/undo-target.d.ts +78 -0
  27. package/lib/types/client/connection.d.ts +111 -0
  28. package/lib/types/client/doctor.d.ts +122 -0
  29. package/lib/types/client/download.d.ts +35 -5
  30. package/lib/types/client/downloads.d.ts +18 -1
  31. package/lib/types/client/file-open-probe.d.ts +64 -0
  32. package/lib/types/client/i18n.d.ts +1 -1
  33. package/lib/types/client/quickopen-model.d.ts +332 -0
  34. package/lib/types/client/scm/DiffView.d.ts +34 -0
  35. package/lib/types/client/scm/actions.d.ts +18 -0
  36. package/lib/types/client/scm/diff-model.d.ts +17 -1
  37. package/lib/types/client/scm/git-cache.d.ts +10 -2
  38. package/lib/types/client/scm/read-queue.d.ts +2 -1
  39. package/lib/types/client/scm/stage-queue.d.ts +13 -0
  40. package/lib/types/client/scm/status-map.d.ts +3 -1
  41. package/lib/types/client/store.d.ts +114 -5
  42. package/lib/types/client/vsc/FindWidget.d.ts +7 -0
  43. package/lib/types/client/vsc/save-shortcut.d.ts +57 -0
  44. package/lib/types/deploy.d.ts +44 -2
  45. package/lib/types/git-format.d.ts +15 -0
  46. package/lib/types/http.d.ts +44 -0
  47. package/lib/types/p2/file-refs.d.ts +39 -2
  48. package/lib/types/p2/helper-rpc.d.ts +26 -0
  49. package/lib/types/p2/router-spill.d.ts +19 -0
  50. package/lib/types/p2/router-subprocess.d.ts +2 -0
  51. package/lib/types/p2/spill-retention.d.ts +74 -0
  52. package/lib/types/p2/worlds.d.ts +11 -0
  53. package/lib/types/pool.d.ts +73 -11
  54. package/lib/types/protocol.d.ts +63 -0
  55. package/lib/types/routes.d.ts +18 -0
  56. package/lib/types/sftp.d.ts +114 -8
  57. package/lib/types/store.d.ts +34 -0
  58. package/lib/types/timeouts.d.ts +14 -0
  59. package/lib/{worlds-C6Xha1mQ.js → worlds-Be1YE2Ot.js} +727 -78
  60. package/package.json +1 -1
  61. package/src/archive.ts +41 -9
  62. package/src/changes/recorder.ts +227 -31
  63. package/src/changes/status.ts +37 -1
  64. package/src/client/CodeEditor.tsx +84 -2
  65. package/src/client/ConnectionStatus.tsx +130 -0
  66. package/src/client/DirectoryFlow.tsx +40 -5
  67. package/src/client/DoctorPanel.tsx +202 -0
  68. package/src/client/DownloadDock.tsx +13 -25
  69. package/src/client/EditorPane.tsx +291 -7
  70. package/src/client/HostsView.tsx +17 -8
  71. package/src/client/QuickOpen.tsx +371 -0
  72. package/src/client/RemoteDirectoryPicker.tsx +54 -3
  73. package/src/client/RemoteExplorer.tsx +879 -160
  74. package/src/client/RemoteRoot.tsx +178 -1
  75. package/src/client/SearchView.tsx +180 -6
  76. package/src/client/SettingsHosts.tsx +1 -1
  77. package/src/client/TerminalView.tsx +174 -9
  78. package/src/client/WorkspaceWizard.tsx +110 -16
  79. package/src/client/WorkspacesView.tsx +22 -6
  80. package/src/client/api.ts +197 -11
  81. package/src/client/changes/ChangesDock.tsx +35 -8
  82. package/src/client/changes/undo-affordance.ts +33 -0
  83. package/src/client/changes/undo-context.ts +14 -18
  84. package/src/client/changes/undo-target.ts +139 -0
  85. package/src/client/connection.ts +264 -0
  86. package/src/client/doctor.ts +441 -0
  87. package/src/client/download.ts +148 -12
  88. package/src/client/downloads.ts +43 -2
  89. package/src/client/file-open-probe.ts +83 -0
  90. package/src/client/i18n.ts +244 -0
  91. package/src/client/index.tsx +5 -2
  92. package/src/client/quickopen-model.ts +778 -0
  93. package/src/client/remote-file-open.ts +21 -33
  94. package/src/client/scm/DiffView.tsx +116 -6
  95. package/src/client/scm/ScmPanel.tsx +19 -0
  96. package/src/client/scm/actions.ts +34 -2
  97. package/src/client/scm/diff-model.ts +33 -37
  98. package/src/client/scm/git-cache.ts +61 -4
  99. package/src/client/scm/read-queue.ts +33 -2
  100. package/src/client/scm/stage-queue.ts +72 -1
  101. package/src/client/scm/status-map.ts +22 -1
  102. package/src/client/store.tsx +704 -21
  103. package/src/client/vsc/FindWidget.tsx +20 -0
  104. package/src/client/vsc/kit.tsx +115 -6
  105. package/src/client/vsc/reveal-line.ts +33 -14
  106. package/src/client/vsc/save-shortcut.ts +131 -0
  107. package/src/client/vsc/vsc.css +419 -0
  108. package/src/deploy.ts +185 -33
  109. package/src/git-format.ts +136 -22
  110. package/src/git-ops.ts +14 -6
  111. package/src/http.ts +80 -12
  112. package/src/importers.ts +80 -21
  113. package/src/index.ts +21 -1
  114. package/src/p2/file-refs.ts +112 -10
  115. package/src/p2/helper-rpc.ts +73 -36
  116. package/src/p2/router-spill.ts +96 -1
  117. package/src/p2/router-subprocess.ts +18 -5
  118. package/src/p2/spill-retention.ts +134 -0
  119. package/src/p2/ssh-proc.ts +22 -0
  120. package/src/p2/worlds.ts +24 -0
  121. package/src/pool.ts +329 -47
  122. package/src/protocol.ts +66 -0
  123. package/src/routes.ts +251 -43
  124. package/src/sftp.ts +486 -26
  125. package/src/store.ts +207 -85
  126. package/src/terminal.ts +38 -2
  127. package/src/timeouts.ts +14 -0
  128. package/src/tools.ts +14 -5
@@ -1,4 +1,4 @@
1
- import { n as isWindowsAbsolute, u as aliasRoot } from "./worlds-C6Xha1mQ.js";
1
+ import { n as isWindowsAbsolute, y as aliasRoot } from "./worlds-Be1YE2Ot.js";
2
2
  import { FileSystem, FsError } from "@deepseek-ai/dsh-fs";
3
3
  //#region src/p2/router-fs.ts
4
4
  /**
@@ -19,9 +19,25 @@ const REMOTE_FILE_SEARCH_EXCLUDED_DIRECTORIES = [
19
19
  ];
20
20
  /** Byte ceiling for one rg listing transfer (50k lines worst case). */
21
21
  const RG_OUTPUT_MAX_BYTES = 16 * 1024 * 1024;
22
+ /**
23
+ * How long the ended scan may take to actually close before we stop waiting.
24
+ *
25
+ * The cap above terminates `rg` ourselves, and a cap is a RESULT, not a failure —
26
+ * but the process may be slow to die (or its ssh channel may never report close
27
+ * at all). Waiting forever there would leave the shared `pending` promise
28
+ * unsettled for the life of the Host, so every later bare query would join it and
29
+ * never answer. Two minutes is far beyond a healthy 5-entry/16MiB listing and only
30
+ * ever bites a half-dead transport.
31
+ */
32
+ const DONE_TIMEOUT_MS = 12e4;
22
33
  var RemoteFileSearch = class {
23
- deps;
24
34
  excluded;
35
+ /**
36
+ * Explicit field assignment instead of a constructor parameter property: the
37
+ * local gates load this module through Node's type-stripping runner (same as
38
+ * `changes/recorder.ts`), which rejects parameter properties.
39
+ */
40
+ deps;
25
41
  settled;
26
42
  pending;
27
43
  pendingAbort;
@@ -30,11 +46,23 @@ var RemoteFileSearch = class {
30
46
  disposed = false;
31
47
  /** Monotonic invalidation counter; a scan started below it is stale. */
32
48
  invalidations = 0;
49
+ /** Why the cached index is bounded, or undefined when it is complete. */
50
+ cappedIndex;
33
51
  constructor(deps) {
34
52
  this.deps = deps;
35
53
  this.excluded = new Set(REMOTE_FILE_SEARCH_EXCLUDED_DIRECTORIES);
36
54
  }
37
55
  /**
56
+ * Why the current index is a bounded prefix, or `undefined` for a complete one.
57
+ *
58
+ * The `@` surface itself returns candidates only (its contract is the stock
59
+ * local list), so this is the honest place to expose "you are looking at a
60
+ * prefix": host logs get the warning, and a future consumer can surface it.
61
+ */
62
+ get indexCap() {
63
+ return this.cappedIndex;
64
+ }
65
+ /**
38
66
  * Drop the cached index (tool activity); the next bare query rebuilds.
39
67
  *
40
68
  * Dropping — rather than keeping the entries and revalidating behind the
@@ -51,6 +79,7 @@ var RemoteFileSearch = class {
51
79
  invalidate() {
52
80
  this.invalidations += 1;
53
81
  this.settled = void 0;
82
+ this.cappedIndex = void 0;
54
83
  if (this.pendingAbort !== void 0) {
55
84
  try {
56
85
  this.pendingAbort.abort(/* @__PURE__ */ new Error("file search index invalidated"));
@@ -143,7 +172,16 @@ var RemoteFileSearch = class {
143
172
  });
144
173
  });
145
174
  }
146
- /** One remote `rg --files` run, head-capped, sorted for determinism. */
175
+ /**
176
+ * One remote `rg --files` run, head-capped, sorted for determinism.
177
+ *
178
+ * A cap is a BOUNDED ANSWER, not a failure: whatever was read before the cap is
179
+ * still the prefix of the listing, and it used to be thrown away because the
180
+ * process's own SIGTERM (we killed it) looked like a non-zero exit. On a
181
+ * monorepo past 50k files that made the bare `@` query answer "nothing to
182
+ * reference" for a repo full of files. Now the prefix is served and
183
+ * {@link RemoteFileSearch.indexCap} / the warn sink say it is a prefix.
184
+ */
147
185
  async buildIndex(signal) {
148
186
  const globs = [];
149
187
  for (const name of this.excluded) globs.push(`--glob=!**/${name}`, `--glob=!**/${name}/**`);
@@ -157,6 +195,7 @@ var RemoteFileSearch = class {
157
195
  "--",
158
196
  "."
159
197
  ];
198
+ this.cappedIndex = void 0;
160
199
  let handle;
161
200
  try {
162
201
  handle = this.deps.spawn({
@@ -176,7 +215,7 @@ var RemoteFileSearch = class {
176
215
  }
177
216
  const lines = [];
178
217
  let bytes = 0;
179
- let truncated = false;
218
+ let cappedBy;
180
219
  try {
181
220
  const stdout = handle.stdout;
182
221
  if (stdout === void 0) handle.terminate();
@@ -196,15 +235,19 @@ var RemoteFileSearch = class {
196
235
  const clean = line.endsWith("\r") ? line.slice(0, -1) : line;
197
236
  if (clean === "") continue;
198
237
  bytes += Buffer.byteLength(clean, "utf8") + 1;
199
- if (lines.length >= 5e4 || bytes > RG_OUTPUT_MAX_BYTES) {
200
- truncated = true;
238
+ if (lines.length >= 5e4) {
239
+ cappedBy = "entries";
240
+ break;
241
+ }
242
+ if (bytes > RG_OUTPUT_MAX_BYTES) {
243
+ cappedBy = "bytes";
201
244
  break;
202
245
  }
203
246
  lines.push(clean);
204
247
  }
205
- if (truncated) break;
248
+ if (cappedBy !== void 0) break;
206
249
  }
207
- if (!truncated && carry !== "") {
250
+ if (cappedBy === void 0 && carry !== "") {
208
251
  if (lines.length < 5e4 && bytes <= RG_OUTPUT_MAX_BYTES) lines.push(carry.endsWith("\r") ? carry.slice(0, -1) : carry);
209
252
  }
210
253
  } finally {
@@ -213,9 +256,15 @@ var RemoteFileSearch = class {
213
256
  signal.throwIfAborted();
214
257
  handle.terminate();
215
258
  }
216
- const outcome = await handle.done.catch(() => void 0);
217
- if (outcome !== void 0 && outcome.exitCode !== 0 && outcome.exitCode !== 1) {
218
- this.warn(`remote file index rg exited ${outcome.exitCode ?? outcome.signal}`);
259
+ const waited = await this.waitForDone(handle);
260
+ if (waited.kind === "timeout") cappedBy ??= "timeout";
261
+ else if (waited.kind === "failed") {
262
+ if (cappedBy === void 0) {
263
+ this.warn(`remote file index failed: ${messageOf(waited.error)}`);
264
+ return [];
265
+ }
266
+ } else if (cappedBy === void 0 && waited.outcome !== void 0 && waited.outcome.exitCode !== 0 && waited.outcome.exitCode !== 1) {
267
+ this.warn(`remote file index rg exited ${waited.outcome.exitCode ?? waited.outcome.signal}`);
219
268
  return [];
220
269
  }
221
270
  } catch (error) {
@@ -226,6 +275,10 @@ var RemoteFileSearch = class {
226
275
  this.warn(`remote file index failed: ${messageOf(error)}`);
227
276
  return [];
228
277
  }
278
+ if (cappedBy !== void 0) {
279
+ this.cappedIndex = cappedBy;
280
+ this.warn(`remote file index capped by ${cappedBy}; serving the prefix read so far`);
281
+ }
229
282
  const files = /* @__PURE__ */ new Set();
230
283
  for (let line of lines) {
231
284
  if (line.startsWith("./")) line = line.slice(2);
@@ -252,6 +305,32 @@ var RemoteFileSearch = class {
252
305
  indexed.sort((a, b) => compareText(a.path, b.path));
253
306
  return indexed;
254
307
  }
308
+ /**
309
+ * Wait for the ended scan to close, but never forever.
310
+ *
311
+ * `handle.done` settles from the transport's close event; a half-dead channel
312
+ * can withhold it for the life of the process. Every outcome is reported as a
313
+ * fact — a rejection stays a rejection so the caller can still treat it as a
314
+ * failure when nothing else explains the scan.
315
+ */
316
+ async waitForDone(handle) {
317
+ const ms = this.deps.doneTimeoutMs ?? DONE_TIMEOUT_MS;
318
+ let timer;
319
+ const settled = handle.done.then((outcome) => ({
320
+ kind: "outcome",
321
+ outcome
322
+ }), (error) => ({
323
+ kind: "failed",
324
+ error
325
+ }));
326
+ try {
327
+ return await Promise.race([settled, new Promise((resolve) => {
328
+ timer = setTimeout(() => resolve({ kind: "timeout" }), ms);
329
+ })]);
330
+ } finally {
331
+ if (timer !== void 0) clearTimeout(timer);
332
+ }
333
+ }
255
334
  warn(message) {
256
335
  try {
257
336
  this.deps.warn?.(`[remote-refs] ${message}`);
@@ -1,3 +1,4 @@
1
+ import { a as spillTtlDays, n as sessionSpillDir, t as runBestEffort } from "./spill-retention-BwKEWrl5.js";
1
2
  import { randomUUID } from "node:crypto";
2
3
  import { SpillLocator, SpillStore } from "@deepseek-ai/dsh-spill";
3
4
  //#region src/p2/router-spill.ts
@@ -6,7 +7,15 @@ import { SpillLocator, SpillStore } from "@deepseek-ai/dsh-spill";
6
7
  * spill backend (private realm) and per-host remote spill dirs. Unknown
7
8
  * sessions stay local (system callers); tombstoned sessions fail closed and
8
9
  * the caller keeps its inline result.
10
+ *
11
+ * Retention: the remote artifacts used to live forever (one file per oversized
12
+ * tool result, under `$HOME/.dsh-helpers/spills/session-<id>/`). They now get a
13
+ * TTL sweep once per host per process, plus a per-session check when the session
14
+ * is disposed — both best-effort, both outside the write's critical path (see
15
+ * `spill-retention.ts` for the commands and why they are safe to aim).
9
16
  */
17
+ /** Ceiling on tracked sessions, so a long-lived Host cannot grow this map forever. */
18
+ const TRACKED_SESSIONS_CAP = 200;
10
19
  /** Sanitize a suggested name to one safe segment (backend owns the rest). */
11
20
  function safeName(suggested) {
12
21
  const base = suggested.replace(/[^A-Za-z0-9._-]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 64);
@@ -14,6 +23,23 @@ function safeName(suggested) {
14
23
  }
15
24
  var TransparentSpillStore = class extends SpillStore {
16
25
  static inject = ["localSpillStore", "remoteWorlds"];
26
+ /** Hosts already TTL-swept by THIS process (one `find` per host, not per spill). */
27
+ sweptAliases = /* @__PURE__ */ new Set();
28
+ /** session id -> directories written for it, for the best-effort dispose prune. */
29
+ sessionDirs = /* @__PURE__ */ new Map();
30
+ constructor(ctx) {
31
+ super(ctx);
32
+ /**
33
+ * Session end is the one moment a spill directory is provably dead for the
34
+ * session that wrote it. The check still requires the DIRECTORY to be older
35
+ * than the TTL (`spillDirSweepCommand`), because `dsh-spill` states that a
36
+ * forked session inherits its parent's locators without copying them — a
37
+ * young directory may still be read by a live child.
38
+ */
39
+ ctx.on("session/disposed", (session) => {
40
+ this.pruneSession(String(session.id));
41
+ });
42
+ }
17
43
  get local() {
18
44
  return this.ctx.localSpillStore;
19
45
  }
@@ -33,11 +59,14 @@ var TransparentSpillStore = class extends SpillStore {
33
59
  const route = this.effective(this.remote.sessionWorld(input.owner.sessionId), `spill ${input.suggestedName ?? ""}`);
34
60
  if (route.kind === "local") return this.local.saveText(input);
35
61
  const fs = await this.remote.fsFor(route.alias);
36
- const dir = `${await this.remote.homeFor(route.alias)}/.dsh-helpers/spills/session-${input.owner.sessionId}`;
62
+ const home = await this.remote.homeFor(route.alias);
63
+ this.sweepOnce(route.alias, home);
64
+ const dir = sessionSpillDir(home, input.owner.sessionId);
37
65
  await this.remote.mkdirRemote(route.alias, dir);
38
66
  const fullPath = `${dir}/${safeName(input.suggestedName ?? "spill.txt")}`;
39
67
  const target = await fs.resolve(fullPath, {});
40
68
  await fs.writeText(target, input.content, { kind: "createIfAbsent" }, void 0, this.policyFor(dir));
69
+ this.remember(String(input.owner.sessionId), route.alias, dir);
41
70
  const bytes = Buffer.byteLength(input.content, "utf8");
42
71
  return {
43
72
  locator: SpillLocator(`remote:${route.alias}:${fullPath}`),
@@ -57,6 +86,49 @@ var TransparentSpillStore = class extends SpillStore {
57
86
  workspaceRoot: dir
58
87
  };
59
88
  }
89
+ /**
90
+ * Sweep one host's spill root once per process.
91
+ *
92
+ * The marker is set BEFORE awaiting so two concurrent first spills on the same
93
+ * host cannot both issue the sweep; a failed sweep still leaves the host marked
94
+ * (retention is a nicety, retrying it on every spill would be a tax).
95
+ */
96
+ async sweepOnce(alias, home) {
97
+ if (this.sweptAliases.has(alias)) return;
98
+ this.sweptAliases.add(alias);
99
+ await runBestEffort(`ttl sweep on ${alias}`, () => this.remote.sweepSpillRoot(alias, home, spillTtlDays()), (message) => this.warn(message));
100
+ }
101
+ /** Remember one written directory for the dispose prune (bounded, oldest first). */
102
+ remember(sessionId, alias, dir) {
103
+ const existing = this.sessionDirs.get(sessionId);
104
+ if (existing === void 0) {
105
+ if (this.sessionDirs.size >= TRACKED_SESSIONS_CAP) {
106
+ const oldest = this.sessionDirs.keys().next().value;
107
+ if (oldest !== void 0) this.sessionDirs.delete(oldest);
108
+ }
109
+ this.sessionDirs.set(sessionId, [{
110
+ alias,
111
+ dir
112
+ }]);
113
+ return;
114
+ }
115
+ if (!existing.some((record) => record.alias === alias && record.dir === dir)) existing.push({
116
+ alias,
117
+ dir
118
+ });
119
+ }
120
+ /** Best-effort TTL check for the directories one session wrote. Never throws. */
121
+ pruneSession(sessionId) {
122
+ const records = this.sessionDirs.get(sessionId);
123
+ if (records === void 0) return;
124
+ this.sessionDirs.delete(sessionId);
125
+ for (const record of records) runBestEffort(`session prune of ${record.dir}`, () => this.remote.sweepSpillDir(record.alias, record.dir, spillTtlDays()), (message) => this.warn(message));
126
+ }
127
+ warn(message) {
128
+ try {
129
+ this.ctx.logger.warn(`[remote-vs] ${message}`);
130
+ } catch {}
131
+ }
60
132
  };
61
133
  //#endregion
62
134
  export { TransparentSpillStore as default };
@@ -1,4 +1,4 @@
1
- import { n as remoteCommand } from "./ssh-proc-arI5lm4W.js";
1
+ import { n as remoteCommand } from "./ssh-proc-VKWn_LZC.js";
2
2
  import { SubprocessExecutableNotFoundError, SubprocessRuntime } from "@deepseek-ai/dsh-subprocess";
3
3
  //#region src/p2/router-subprocess.ts
4
4
  /**
@@ -7,11 +7,23 @@ import { SubprocessExecutableNotFoundError, SubprocessRuntime } from "@deepseek-
7
7
  * the chosen backend, so no handle mapping is needed; pwsh argv in a remote
8
8
  * world fails closed with guidance instead of exit-127 confusion.
9
9
  */
10
- /** True when argv selects PowerShell (remote worlds are POSIX-only). */
11
- function isPwshArgv(argv) {
10
+ /**
11
+ * Windows shells: remote worlds are POSIX-only, so ALL of these fail closed.
12
+ *
13
+ * Recognising only `pwsh` was fail-open: `powershell.exe` / `cmd.exe` / `.ps1`
14
+ * fell through to the bare-name rewrite and were then looked up on the remote
15
+ * PATH. Usually that produced a misleading "not found"; with a same-named binary
16
+ * on the host it would have run something else entirely. Exported so the guard
17
+ * can be asserted directly, without a host.
18
+ */
19
+ const WINDOWS_SHELL = /^(?:pwsh|pwsh-preview|powershell|powershell_ise|cmd)(?:\.exe)?$/i;
20
+ /** Windows script extensions: argv[0] naming one cannot run without a shell. */
21
+ const WINDOWS_SCRIPT = /\.(?:ps1|bat|cmd)$/i;
22
+ /** True when argv selects a Windows shell (unsupported in remote worlds). */
23
+ function isWindowsShellArgv(argv) {
12
24
  if (argv.length === 0) return false;
13
25
  const base = argv[0].replace(/\\/g, "/").split("/").pop() ?? "";
14
- return /^pwsh(\.exe)?$/i.test(base);
26
+ return WINDOWS_SHELL.test(base) || WINDOWS_SCRIPT.test(base);
15
27
  }
16
28
  var TransparentSubprocessRuntime = class extends SubprocessRuntime {
17
29
  static inject = ["localSubprocess", "remoteWorlds"];
@@ -44,7 +56,7 @@ var TransparentSubprocessRuntime = class extends SubprocessRuntime {
44
56
  spawn(spec) {
45
57
  const route = this.effective(this.remote.routeDir(spec.cwd), `spawn ${spec.argv[0] ?? ""} @ ${spec.cwd}`);
46
58
  if (route.kind === "local") return this.local.spawn(spec);
47
- if (isPwshArgv(spec.argv)) throw new SubprocessExecutableNotFoundError(`remote worlds are POSIX-only: '${spec.argv[0]}' cannot run on ${route.alias}; use the bash tool (Remote preset) instead`);
59
+ if (isWindowsShellArgv(spec.argv)) throw new SubprocessExecutableNotFoundError(`remote worlds are POSIX-only: '${spec.argv[0]}' is a Windows shell and cannot run on ${route.alias}; use the bash tool (Remote preset) instead`);
48
60
  const runtime = this.remote.procFor(route.alias);
49
61
  const argv0 = spec.argv[0];
50
62
  const remoteArgv0 = argv0.startsWith("/") ? argv0 : /^[A-Za-z]:[\\/]/.test(argv0) || argv0.includes("\\") ? remoteCommand(argv0) : argv0;
@@ -61,4 +73,4 @@ var TransparentSubprocessRuntime = class extends SubprocessRuntime {
61
73
  }
62
74
  };
63
75
  //#endregion
64
- export { TransparentSubprocessRuntime as default };
76
+ export { TransparentSubprocessRuntime as default, isWindowsShellArgv };
@@ -0,0 +1,115 @@
1
+ //#region src/p2/spill-retention.ts
2
+ /**
3
+ * Remote spill retention: the policy constant and the pure command builders.
4
+ *
5
+ * Why this module exists: the spill backend writes model-facing artifacts into
6
+ * the remote `$HOME` under a per-session directory (`router-spill.ts`), and the
7
+ * spill service definition owns NO retention policy ({@link SpillStore} only
8
+ * declares `saveText`). Nothing removed those files, so a long-lived host grew
9
+ * one artifact per oversized tool result forever — including the content of
10
+ * command output, which is exactly the material that should not live on a build
11
+ * machine indefinitely.
12
+ *
13
+ * The policy is deliberately lazy: a TTL sweep per host (one `find` on the first
14
+ * spill), plus a per-session directory check when a session is disposed. Two
15
+ * rules shape the commands below:
16
+ *
17
+ * 1. **Deletion must never block a write.** Everything is best-effort (see
18
+ * {@link runBestEffort}); a failed cleanup is logged and forgotten.
19
+ * 2. **Deletion must be impossible to aim at anything else.** Every path is an
20
+ * absolute POSIX path under `<home>/.dsh-helpers/spills`, every shell word is
21
+ * single-quoted, the sweep is capped at depth 1 and to `session-*`, and the
22
+ * session-directory check only matches the directory itself (`-maxdepth 0`).
23
+ *
24
+ * Kept free of cordis/pool on purpose, so `scripts/check-spill-retention.mjs`
25
+ * drives the real builders without a host.
26
+ */
27
+ /** Subdirectory of the remote `$HOME` that holds every spilled artifact. */
28
+ const SPILLS_SUBDIR = ".dsh-helpers/spills";
29
+ /** TTL bounds: below a day a sweep would race live sessions; above a quarter a "temporary" artifact is not. */
30
+ const TTL_MIN_DAYS = 1;
31
+ const TTL_MAX_DAYS = 90;
32
+ /** The TTL in days: `DSH_REMOTE_VS_SPILL_TTL_DAYS` when sane, else the default. */
33
+ function spillTtlDays() {
34
+ const raw = Number(process.env.DSH_REMOTE_VS_SPILL_TTL_DAYS);
35
+ if (!Number.isFinite(raw) || raw < TTL_MIN_DAYS) return 14;
36
+ return Math.min(Math.floor(raw), TTL_MAX_DAYS);
37
+ }
38
+ /** A TTL clamped to the supported range (also used by direct callers/tests). */
39
+ function clampTtlDays(value) {
40
+ if (!Number.isFinite(value)) return 14;
41
+ return Math.min(Math.max(Math.floor(value), TTL_MIN_DAYS), TTL_MAX_DAYS);
42
+ }
43
+ /** POSIX single-quote one shell word. Throws on NUL, which no shell can carry. */
44
+ function shq(word) {
45
+ if (word.includes("\0")) throw new Error("NUL byte in shell word");
46
+ return `'${word.replace(/'/g, `'\\''`)}'`;
47
+ }
48
+ /** Refuse a path that is not remote-absolute: retention must never guess a directory. */
49
+ function remoteAbsolute(path) {
50
+ if (!path.startsWith("/")) throw new Error(`refusing non-absolute remote path: ${path}`);
51
+ return path.length > 1 ? path.replace(/\/+$/, "") : path;
52
+ }
53
+ /** The spills root inside one remote home. */
54
+ function spillRoot(home) {
55
+ return `${remoteAbsolute(home)}/${SPILLS_SUBDIR}`;
56
+ }
57
+ /**
58
+ * The per-session spill directory.
59
+ *
60
+ * Mirrors `router-spill.ts`'s previous inline spelling so existing sessions keep
61
+ * finding their files, and rejects anything that could escape the root: a session
62
+ * id comes from the Host, but a directory name derived from it still has to be
63
+ * one safe path segment.
64
+ */
65
+ function sessionSpillDir(home, sessionId) {
66
+ const id = String(sessionId);
67
+ if (id === "" || !/^[A-Za-z0-9._-]+$/.test(id) || id === "." || id === "..") throw new Error(`unsafe spill session id: ${id}`);
68
+ return `${spillRoot(home)}/session-${id}`;
69
+ }
70
+ /**
71
+ * One sweep command for a whole host: every `session-*` directory under the
72
+ * spills root older than `ttlDays`.
73
+ *
74
+ * `-mindepth 1 -maxdepth 1` keeps the walk inside the root's own children (no
75
+ * recursion, so a stray directory elsewhere can never match), `-name 'session-*'`
76
+ * pins the namespace, and `|| true` makes "the root does not exist yet" (the
77
+ * normal first-run case) a success: retention is not allowed to look like
78
+ * failure to its caller.
79
+ */
80
+ function spillSweepCommand(home, ttlDays) {
81
+ const ttl = clampTtlDays(ttlDays);
82
+ return `find ${shq(spillRoot(home))} -mindepth 1 -maxdepth 1 -type d -name 'session-*' -mtime +${ttl} -exec rm -rf -- {} + 2>/dev/null || true`;
83
+ }
84
+ /**
85
+ * One command for a single session's spill directory: remove it only when the
86
+ * directory itself is older than the TTL.
87
+ *
88
+ * The mtime gate is what makes this safe for forked sessions: `dsh-spill` states
89
+ * that a fork inherits the parent's locators without copying them, so a young
90
+ * directory may still be referenced by a live child. `-maxdepth 0` matches the
91
+ * directory alone — never its contents.
92
+ */
93
+ function spillDirSweepCommand(dir, ttlDays) {
94
+ const ttl = clampTtlDays(ttlDays);
95
+ return `find ${shq(remoteAbsolute(dir))} -maxdepth 0 -type d -mtime +${ttl} -exec rm -rf -- {} + 2>/dev/null || true`;
96
+ }
97
+ /**
98
+ * Run one retention step without ever failing the caller.
99
+ *
100
+ * A write path that waits on a cleanup is a write path that can be broken by a
101
+ * cleanup; the caller only gets a warning sink. Returns whether the step ran.
102
+ */
103
+ async function runBestEffort(what, run, warn) {
104
+ try {
105
+ await run();
106
+ return true;
107
+ } catch (error) {
108
+ try {
109
+ warn?.(`spill retention (${what}) failed: ${error instanceof Error ? error.message : String(error)}`);
110
+ } catch {}
111
+ return false;
112
+ }
113
+ }
114
+ //#endregion
115
+ export { spillTtlDays as a, spillSweepCommand as i, sessionSpillDir as n, spillDirSweepCommand as r, runBestEffort as t };
@@ -72,6 +72,22 @@ function sweepSpills(now) {
72
72
  }
73
73
  }
74
74
  /**
75
+ * Whether this process has already swept the Host spill dir.
76
+ *
77
+ * The sweep used to hang off `spillCreate` alone, so a Host that stopped
78
+ * producing over-cap output kept its old files forever. Arming it from the first
79
+ * remote spawn makes it independent of whether THIS run ever spills.
80
+ */
81
+ let hostSweepArmed = false;
82
+ /** Arm the one-per-process Host spill sweep (cheap readdir; best effort). */
83
+ function armHostSpillSweep(now) {
84
+ if (hostSweepArmed) return;
85
+ hostSweepArmed = true;
86
+ try {
87
+ sweepSpills(now);
88
+ } catch {}
89
+ }
90
+ /**
75
91
  * One collected stream: tail window + offset readers + optional full-stream
76
92
  * spill file (Host disk). Mirrors the stock local runtime's contract
77
93
  * (dsh-subprocess SubprocessCollect): with `spill` configured, overflow
@@ -264,6 +280,7 @@ var SshProcRuntime = class {
264
280
  if (!Number.isFinite(spec.graceMs) || spec.graceMs < 0) throw new Error(`remote spawn needs a non-negative graceMs, got: ${spec.graceMs}`);
265
281
  if (spec.stdio.control === "pipe") throw new Error("remote control channels are not implemented in P2-v1");
266
282
  if (spec.signal?.aborted === true) throw new Error("spawn aborted before start");
283
+ armHostSpillSweep(Date.now());
267
284
  const useSetsid = this.setsid ?? true;
268
285
  return new SshProcHandle(this.pool, this.alias, spec, useSetsid, () => {
269
286
  this.setsid = false;
@@ -6,7 +6,7 @@
6
6
  * writes it to its own disk. Pure string builders (no fs, no exec) so the
7
7
  * download gate can pin the exact command shape.
8
8
  */
9
- /** Download file name for one archived directory. */
9
+ /** Download file name for one archived directory (normalized like the command). */
10
10
  export declare function directoryArchiveName(dir: string): string;
11
11
  /**
12
12
  * One POSIX shell command that writes the directory's gzip tar to stdout.
@@ -127,7 +127,39 @@ export declare class SessionChanges {
127
127
  * ledger outside the workspace it was created for.
128
128
  */
129
129
  useRepoSubdir(sessionId: string, subdir: string | undefined): void;
130
- /** Resolve the routing target once per session, caching the ledger. */
130
+ /**
131
+ * Forget everything observed against the ledger's previous root.
132
+ *
133
+ * The root is the subject of every fact this ledger holds: the baseline
134
+ * describes that tree, both scans name paths relative to it, and the flags
135
+ * that gate them (`absorbed`, `untrackedGivenUp`) are verdicts about that
136
+ * repository. Moving the root therefore makes the whole observation set
137
+ * meaningless at once — resetting only the ones a caller happened to remember
138
+ * is how the first cut of `useRepoSubdir` forgot `untracked` and `absorbed`,
139
+ * which announced the newly selected repository's PRE-EXISTING untracked
140
+ * files as this session's work (full-file additions, revertible — and a
141
+ * revert of an untracked file destroys a copy git never had).
142
+ *
143
+ * One entry point on purpose: a field added later belongs here by default,
144
+ * instead of needing every root-move path to be found again.
145
+ */
146
+ private resetObservation;
147
+ /**
148
+ * Resolve (or rebind) the ledger for one session from its CURRENT cwd.
149
+ *
150
+ * The cwd is re-resolved on every turn boundary instead of once per session: a
151
+ * session can change its working directory mid-conversation (a workspace
152
+ * switch, `working-directory.set`), and a ledger pinned to the first binding
153
+ * then keeps answering "what did this session change" about a tree the session
154
+ * is no longer working in — and points file-open and undo at it.
155
+ *
156
+ * Rebinding happens IN PLACE rather than forget+create: the panel keeps its
157
+ * identity and `turn` counter (no null-summary flicker) and one
158
+ * `resetObservation()` drops every fact that belonged to the previous root, so
159
+ * the field list stays in that one method. C1's root-snapshot guards in
160
+ * `refresh`/`publish`/`kickUntracked`/`absorbPreExisting` are exactly what makes
161
+ * this safe while a scan of the old root is still in flight.
162
+ */
131
163
  private ensure;
132
164
  /** Queue a refresh, coalescing bursts (a turn can end while one is running). */
133
165
  private schedule;
@@ -154,7 +186,7 @@ export declare class SessionChanges {
154
186
  * ledger looks one level down once and adopts the repository it finds, which
155
187
  * is the same idea the SCM panel's `repoSubdir` expresses by hand.
156
188
  *
157
- * @returns entries relative to the ledger's root, or undefined when no
189
+ * @returns the entries and the root they are relative to, or undefined when no
158
190
  * repository could be found (the ledger then reports why).
159
191
  */
160
192
  private scanTracked;
@@ -148,4 +148,16 @@ export declare const CodeEditor: import("react").ForwardRefExoticComponent<{
148
148
  savedText?: string;
149
149
  onSave: () => void;
150
150
  onDirty: (dirty: boolean) => void;
151
+ /**
152
+ * Last chance to hand the LIVE document to the store, called from this
153
+ * component's own unmount cleanup while the EditorView still exists.
154
+ *
155
+ * The parent cannot do this itself: React clears a child's ref before the
156
+ * parent's cleanup runs, so `editorRef.current` is already null there. An
157
+ * unmount that is not one of the plugin's own switches (the host swapping the
158
+ * remote-editor view away) would otherwise drop every unsaved edit while the
159
+ * tab kept its dirty dot, and the next Ctrl+S would write the stale bytes
160
+ * back. Only called when the buffer is dirty, so clean unmounts stay free.
161
+ */
162
+ onBuffer?: (tabId: string, text: string) => void;
151
163
  } & import("react").RefAttributes<CodeEditorHandle>>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Connection status for the workspace on screen.
3
+ *
4
+ * Two renderings, one source of truth: a chip in the remote surface's top bar
5
+ * (dot + label) and a compact dot in the editor's info bar. The chip is a
6
+ * read-out in the healthy states and a RETRY control in the errored one.
7
+ *
8
+ * An errored link self-heals: a bounded auto-retry (one dial per tick, at most
9
+ * AUTO_RETRY_MAX_ATTEMPTS in a row) runs while the page is visible, so a network
10
+ * that comes back does not need a user action. It stops after the budget and
11
+ * leaves the manual click — repeated dials against a password-auth host can
12
+ * count towards a lockout, so this is deliberately not an endless loop.
13
+ */
14
+ import { type ReactNode } from 'react';
15
+ export declare function ConnectionStatusChip(props: {
16
+ compact?: boolean;
17
+ }): ReactNode;
@@ -27,4 +27,6 @@ export interface DirectoryFlowInjected {
27
27
  createDirectory: (path: string, name: string) => Promise<string>;
28
28
  pickDirectory: () => Promise<string | null>;
29
29
  }
30
+ /** True when the failure is "this backend serves no browse primitives". */
31
+ export declare function isUnavailable(e: unknown): boolean;
30
32
  export declare function RemoteDirectoryFlow(props: DirectoryFlowOwnerProps & DirectoryFlowInjected): ReactNode;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Remote environment doctor panel: one screen of evidence about the host the
3
+ * workspace lives on, plus "copy all" as plain text.
4
+ *
5
+ * Rendered as a fixed overlay (like the input dialog) instead of joining the
6
+ * host list: the list lives in the DSH Settings dialog, and pushing it around
7
+ * while the first paint of a probe is still in flight would be worse than a
8
+ * layer on top of it.
9
+ *
10
+ * The run lives here, not in `HostsView`: the panel is mounted for exactly the
11
+ * lifetime of one report (the host row supplies `key={alias}`), so an unmount
12
+ * closes the door on a late answer instead of writing into the list. A second
13
+ * mount for the same alias joins the in-flight probe rather than spending
14
+ * another channel slot.
15
+ *
16
+ * Three states, one of which is `unknown` — see `doctor.ts`: an unanswered
17
+ * probe is never rendered as "not installed"; the hint line under the table
18
+ * says what "unknown" means so nobody reads a blank as a pass.
19
+ */
20
+ import { type ReactNode } from 'react';
21
+ export declare function DoctorPanel(props: {
22
+ t: (key: string) => string;
23
+ alias: string;
24
+ onClose: () => void;
25
+ }): ReactNode;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Ctrl+P quick open: the portal modal, its list and its keyboard handling.
3
+ *
4
+ * Mounted by `RemoteRoot` only while it is open, so unmounting IS closing (no
5
+ * "is it visible" state to keep in sync), and it reads the same store the tree
6
+ * does: opening a hit is one `store.openFile()`, which makes a quick-open file
7
+ * indistinguishable from one opened in the tree — including cross-workspace
8
+ * binding resolution and the "already open → activate" rule.
9
+ *
10
+ * The index, scoring and the remote command live in `quickopen-model.ts` (pure, and
11
+ * covered by `scripts/check-quickopen.mjs`); this file owns pixels, focus and
12
+ * keys only.
13
+ */
14
+ import { type ReactNode } from 'react';
15
+ export declare function QuickOpen(props: {
16
+ onClose: () => void;
17
+ }): ReactNode;