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
@@ -28,6 +28,32 @@ export interface EditorTab {
28
28
  * guard silent) — the exact silent-loss path the handoff exists to avoid.
29
29
  */
30
30
  baseline?: string;
31
+ /**
32
+ * The remote VERSION this buffer was loaded from / last saved to.
33
+ *
34
+ * Sent back on save as an optimistic lock: the Host refuses the write when the
35
+ * remote file has a different mtime (or size), because that means a person or
36
+ * an agent wrote it after this buffer was read and saving would destroy their
37
+ * work with a cheerful "saved". Kept here rather than in the editor because it
38
+ * must survive a surface handoff and a tab switch.
39
+ *
40
+ * `undefined` means NO baseline (a file created by this session, or a write
41
+ * whose post-save stat failed): the save then goes through unguarded, exactly
42
+ * as before this feature — the guard protects a known history, it must never
43
+ * invent one.
44
+ */
45
+ remoteMtime?: number;
46
+ /** Size that belonged to `remoteMtime` (the second half of the same baseline). */
47
+ remoteSize?: number;
48
+ /**
49
+ * Set when a save was REFUSED because the remote file moved on, carrying what
50
+ * is there now. The pane turns this into an offer — overwrite / reload / see
51
+ * the difference — instead of a red toast the user cannot act on.
52
+ */
53
+ conflict?: {
54
+ mtime: number | null;
55
+ size: number | null;
56
+ };
31
57
  dirty: boolean;
32
58
  saving: boolean;
33
59
  binary: boolean;
@@ -43,6 +69,15 @@ export interface EditorTab {
43
69
  untracked: boolean;
44
70
  /** Set for a commit drill-down: the diff compares `ref^` with `ref`. */
45
71
  ref?: string;
72
+ /**
73
+ * 重命名差异的旧路径(commit diff 专用)。
74
+ *
75
+ * `openCommitFile` 的首次加载把它一起交给 `loadCommitFileDiff`(两个路径一起
76
+ * `git show -M` 才能把 rename 配对),但 `reloadTab` 是另一个调用点:不存进 tab,
77
+ * 重载(工具栏 ⟳ / 断线恢复的批量 reload)就只会拿新路径去问 git,rename 立刻
78
+ * 退化成「整篇新增」。
79
+ */
80
+ origPath?: string;
46
81
  /** 1-based line to reveal after load (a content-search hit). */
47
82
  line?: number;
48
83
  /**
@@ -260,7 +295,16 @@ export interface ExplorerValue {
260
295
  * @returns true only when the write really succeeded — the caller uses it to
261
296
  * advance the editor's dirty baseline (see `CodeEditorHandle.markSaved`).
262
297
  */
263
- saveTab: (id: string, content: string) => Promise<boolean>;
298
+ saveTab: (id: string, content: string, options?: {
299
+ force?: boolean;
300
+ }) => Promise<boolean>;
301
+ /**
302
+ * Forget the pending save-conflict banner for one tab (the user dismissed it).
303
+ *
304
+ * The buffer and the dirty flag are untouched: dismissing only hides the
305
+ * offer, it never decides anything on the user's behalf.
306
+ */
307
+ dismissConflict: (id: string) => void;
264
308
  reloadTab: (id: string) => Promise<void>;
265
309
  info: (text: string) => void;
266
310
  fail: (text: string) => void;
@@ -273,6 +317,23 @@ export declare function repoRelative(repoRoot: string | undefined, fullPath: str
273
317
  export declare function bootstrap(ctx: Context): void;
274
318
  /** Reload hosts + workspace bindings and the routing status. */
275
319
  export declare function refreshAll(): void;
320
+ /**
321
+ * Reopen the file tabs this browser had for the current workspace.
322
+ *
323
+ * Runs once per page load, for the CURRENT workspace only: switching workspaces
324
+ * keeps its existing contract (the strip is cleared and the user is told so
325
+ * first), and re-running this on every `refreshAll` would fight that clear
326
+ * rather than complement it.
327
+ *
328
+ * A tab that no longer loads (deleted, renamed, no permission) is dropped and
329
+ * COUNTED — silently restoring "6 of 9" would leave the user looking for three
330
+ * tabs they think they had.
331
+ *
332
+ * Only PATHS are restored. Caret and scroll position are not persisted: the
333
+ * README's privacy stance is "paths only, never content", and a caret stored
334
+ * weeks ago would point into a file that has since changed.
335
+ */
336
+ export declare function restoreStoredTabs(): void;
276
337
  /** Switch the sidebar panel (persisted across reloads). */
277
338
  export declare function setView(view: RailView): void;
278
339
  /** One-shot request from the explorer: "search this folder". */
@@ -396,6 +457,21 @@ export declare function workspaceMatchesSession(): boolean;
396
457
  export declare function sessionRepoSubdir(sessionId?: string | undefined): string;
397
458
  /** The binding id the views are on (the dropdown/tree's answer), plain read. */
398
459
  export declare function selectedWorkspaceId(): string;
460
+ /**
461
+ * Snapshot of the editor tabs, for non-React callers (the local gates).
462
+ *
463
+ * Same shape as `selectedWorkspaceId` / `gitState`: a plain read so a script can
464
+ * assert what the store actually holds without rendering a component.
465
+ */
466
+ export declare function editorTabs(): readonly EditorTab[];
467
+ /**
468
+ * The active tab's id.
469
+ *
470
+ * A plain getter rather than a hook, for the same reason `editorTabs` is one:
471
+ * the restore path lives outside React, and the gates that verify it need to see
472
+ * what the strip would consider current without mounting a component.
473
+ */
474
+ export declare function activeEditorTabId(): string | undefined;
399
475
  /**
400
476
  * Point git at a directory inside the workspace. Repositories often live in a
401
477
  * sub-directory of the binding (`/srv/app` holding `/srv/app/web/.git`), and
@@ -426,6 +502,15 @@ export declare function discoverRepos(): Promise<string[]>;
426
502
  export declare function refreshGit(mode?: 'join' | 'fresh'): Promise<void>;
427
503
  /** Refresh everything a working-tree change can invalidate. */
428
504
  export declare function afterWrite(): Promise<void>;
505
+ /**
506
+ * The connection came back: re-read everything a disconnect froze.
507
+ *
508
+ * `revision` is what makes the explorer re-list the root and every expanded
509
+ * directory (the cached rows may predate the drop), and the git refresh updates
510
+ * the status marks they are drawn with. Clean editor tabs are reloaded by the
511
+ * caller (it owns the tab list); dirty ones must be left to the user.
512
+ */
513
+ export declare function refreshAfterReconnect(): void;
429
514
  /** The repository the SCM panel is pointed at, or undefined when none. */
430
515
  export declare function scmTarget(): {
431
516
  alias: string;
@@ -529,8 +614,10 @@ export declare function remoteOpenBindings(): {
529
614
  * interceptor already resolved it), switching the explorer's selected
530
615
  * workspace when the on-screen one differs.
531
616
  *
532
- * @returns true when the file was handed to the editor; false when the binding
533
- * is unknown (the caller then keeps the native preview).
617
+ * @returns true when the click was HANDLED — either the file went to the editor,
618
+ * or it was deliberately refused with a message (see below); false only when
619
+ * the binding is unknown, which is the caller's cue to keep the native
620
+ * preview.
534
621
  */
535
622
  export declare function openRemoteFileInBinding(bindingId: string, remotePath: string, options?: {
536
623
  line?: number;
@@ -558,8 +645,30 @@ export declare function openCommitFile(hash: string, rel: string, origPath?: str
558
645
  export declare function activateTab(id: string): void;
559
646
  export declare function closeTab(id: string): void;
560
647
  export declare function updateTab(id: string, next: Partial<EditorTab>): void;
561
- /** Write one tab back to the remote host. @returns true when the write landed. */
562
- export declare function saveTab(id: string, content: string): Promise<boolean>;
648
+ /**
649
+ * Write one tab back to the remote host. @returns true when the burst's LAST
650
+ * write landed.
651
+ *
652
+ * Requests for the SAME tab are serialized (see `SaveSlot`); a request that
653
+ * arrives while one is in flight becomes the single pending write, replacing any
654
+ * earlier pending content. Every caller of that burst — the one that started it
655
+ * and the coalesced-away ones — resolves with the outcome of the write that
656
+ * finally lands: the bytes they asked for are part of the newer buffer the
657
+ * editor held, so "your edit is on disk" stays true (and a burst whose last
658
+ * write failed reports false to all of them).
659
+ */
660
+ export declare function saveTab(id: string, content: string, options?: {
661
+ force?: boolean;
662
+ }): Promise<boolean>;
663
+ /**
664
+ * Drop the pending save-conflict banner for one tab.
665
+ *
666
+ * Hiding the offer is NOT a decision: the buffer stays dirty and the baseline
667
+ * stays untouched, so the next save is guarded exactly as this one was. Only a
668
+ * forced save or a reload can settle a conflict for real — anything else would
669
+ * be deciding for the user which version of their file to keep.
670
+ */
671
+ export declare function dismissConflict(id: string): void;
563
672
  /**
564
673
  * Re-read one tab (file content or diff payload).
565
674
  *
@@ -76,6 +76,13 @@ export declare function FindWidget(props: {
76
76
  top: number;
77
77
  right: number;
78
78
  } | undefined;
79
+ /**
80
+ * Bumped by the editor whenever its selection changes while this widget is
81
+ * open. The `n/N` readout is derived from the caret, and moves made OUTSIDE the
82
+ * widget (F3 / Shift-F3, a click, an arrow key) never told it — the numbers
83
+ * stayed on the previous match while the caret had moved on.
84
+ */
85
+ tick?: number;
79
86
  onClose: () => void;
80
87
  }): ReactNode;
81
88
  export {};
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The window-level Ctrl/Cmd+S shortcut.
3
+ *
4
+ * `CodeEditor` owns that keystroke only while its CodeMirror view has focus (the
5
+ * editor's keymap), so after clicking the tab strip, the info row, the find box
6
+ * or any sidebar panel the very same keystroke did nothing at all — silently,
7
+ * while the UI advertises Ctrl+S as the save key (the save button's title and
8
+ * the empty-pane hint). A missed save is invisible until the tab is closed.
9
+ *
10
+ * Two rules make a global listener safe here:
11
+ *
12
+ * - BUBBLE phase plus `defaultPrevented`: CodeMirror handles its own keydown
13
+ * first and calls `preventDefault()` when a keymap binding matches (its event
14
+ * dispatch does exactly that), so this listener must step aside then — one
15
+ * press may never save twice.
16
+ * - the CALLER decides what "save" means: `resolve()` returns undefined when the
17
+ * surface on screen has nothing of ours to save (a diff tab is `DiffView`'s own
18
+ * contract, a themed dialog owns its input, a terminal owns its keys).
19
+ *
20
+ * Dependency-free on purpose (no React, no CodeMirror): the gate drives it with
21
+ * real `KeyboardEvent`s in jsdom, so the rule is testable without mounting the
22
+ * whole editor.
23
+ */
24
+ /** The fields `isSaveShortcut` reads — a structural type keeps it testable. */
25
+ export interface SaveShortcutEvent {
26
+ key: string;
27
+ ctrlKey: boolean;
28
+ metaKey: boolean;
29
+ altKey: boolean;
30
+ shiftKey: boolean;
31
+ isComposing?: boolean | undefined;
32
+ defaultPrevented: boolean;
33
+ target: EventTarget | null;
34
+ }
35
+ /**
36
+ * Is this the save shortcut this module should act on?
37
+ *
38
+ * Pure: the caller passes the event's fields, so the gate can pin every rule
39
+ * without a DOM.
40
+ */
41
+ export declare function isSaveShortcut(event: SaveShortcutEvent): boolean;
42
+ /** A registered save target: `undefined` = this surface has nothing to save. */
43
+ export type SaveShortcutResolver = () => (() => void) | undefined;
44
+ /**
45
+ * Install the window-level save shortcut for one surface.
46
+ *
47
+ * Re-entrant by design: the FIRST call installs the one window listener, later
48
+ * calls only register their resolver (no second listener), and the last disposer
49
+ * removes it.
50
+ *
51
+ * @param resolve - What to save RIGHT NOW; return the save action, or undefined
52
+ * when this surface is not ours to save. Called once per candidate keypress, so
53
+ * it always sees the current state.
54
+ * @returns the disposer (unregisters this resolver; removes the listener when the
55
+ * last surface is gone).
56
+ */
57
+ export declare function installSaveShortcut(resolve: SaveShortcutResolver): () => void;
@@ -49,10 +49,30 @@ export interface HelperCacheEntry {
49
49
  protocol: number;
50
50
  nodeVersion: string;
51
51
  }
52
+ /** Wire protocol this plugin's `dsh-ssh` generation speaks (see MAINTENANCE §2.7). */
53
+ export declare const EXPECTED_HELPER_PROTOCOL = 2;
54
+ /** Absolute path of one cached helper tarball; throws when it is not inside the cache. */
55
+ export declare function helperTarballPath(helper: HelperCacheEntry, dir?: string): string;
52
56
  /** Scan the local helper cache; invalid/incomplete entries are skipped. */
53
57
  export declare function listCachedHelpers(dir?: string): HelperCacheEntry[];
54
- /** Pick a cached build for a platform (exact version pin or newest). */
55
- export declare function pickCached(platform: string, version?: string): HelperCacheEntry | undefined;
58
+ /**
59
+ * SemVer-ish comparison for cached helper versions.
60
+ *
61
+ * A plain string compare picked `0.9.0` over `0.10.0` (multi-digit segments sort
62
+ * wrong: `9` > `10`) and the pipeline then pushed an OLD helper as "ok". Numeric
63
+ * segments compare as numbers, everything else lexicographically; a shorter
64
+ * version loses to its own extension (`0.2` < `0.2.1`) and a numeric segment wins
65
+ * over a pre-release one (`0.2.1` > `0.2.1-alpha.2`).
66
+ */
67
+ export declare function compareHelperVersions(left: string, right: string): number;
68
+ /**
69
+ * Pick a cached build for a platform (exact version pin or newest).
70
+ *
71
+ * `expectedProtocol` (default: this plugin's wire protocol) is part of the
72
+ * choice: a cached build whose protocol does not match would install fine and
73
+ * then fail the runtime handshake, so it is not a candidate at all.
74
+ */
75
+ export declare function pickCached(platform: string, version?: string, expectedProtocol?: number): HelperCacheEntry | undefined;
56
76
  /** Honest availability of the helper channels. */
57
77
  export declare function helperAvailability(): HelperAvailability[];
58
78
  export declare function isHelperAvailable(kind: HelperKind): boolean;
@@ -92,3 +112,25 @@ export interface PushOptions {
92
112
  * fallback) -> compare -> skip or push -> write back.
93
113
  */
94
114
  export declare function pushPipeline(pool: RemotePool, store: RemoteStore, alias: string, opts?: PushOptions): Promise<PushReport>;
115
+ /** Paths of one helper install attempt (absolute, probe-derived + whitelisted version). */
116
+ export interface HelperInstallPaths {
117
+ root: string;
118
+ verDir: string;
119
+ tmpFile: string;
120
+ }
121
+ /**
122
+ * Remote shell steps installing one cached helper.
123
+ *
124
+ * Invariant: the currently installed version is never deleted before the new one
125
+ * is fully extracted — the old dir is renamed to `.old` and removed only after
126
+ * the swap, and a crash between "old moved away" and "new moved in" is repaired
127
+ * by the recovery step (restore `.old` when the live dir is missing). Every path
128
+ * goes through `shRoot`; the tarball name embedded in the sha256 line is quoted
129
+ * too (the caller's version already passed `HELPER_VERSION_RE`, so it cannot
130
+ * break out of the shell any more).
131
+ *
132
+ * Pure string work (no fs/pool) so a gate can pin the ORDER without a remote.
133
+ */
134
+ export declare function helperInstallSteps(helper: HelperCacheEntry, paths: HelperInstallPaths): string[];
135
+ /** One POSIX shell line: steps joined so any failure stops the sequence. */
136
+ export declare function helperInstallScript(helper: HelperCacheEntry, paths: HelperInstallPaths): string;
@@ -24,6 +24,21 @@ export declare function messageCommand(workdir: string, ref: string): string;
24
24
  export declare function statCommand(workdir: string, ref: string): string;
25
25
  /** True when stderr reports a non-repository / missing git. */
26
26
  export declare function gitFailed(stderr: string): string | undefined;
27
+ /**
28
+ * Reverse git's C-style quoting of one porcelain path.
29
+ *
30
+ * `git status --porcelain` (without `-z`) quotes any path containing whitespace,
31
+ * a quote, a backslash or a control character, and escapes the specials inside:
32
+ * `"a\"b.txt"`, `"plain space.txt"`, `"ctl\001name.txt"`. Passing that field on
33
+ * as if it were the path made every such file unusable in the SCM panel
34
+ * (open/diff/stage asked for a literal filename with quotes in it) — and a space
35
+ * in a name is common, not an exotic edge (2026-10 audit, A18-b).
36
+ *
37
+ * Unquoted input is returned unchanged. Octal escapes are decoded as BYTES and
38
+ * only then interpreted as UTF-8: a multi-byte character can arrive as several
39
+ * `\NNN` escapes and failing to group them would corrupt it.
40
+ */
41
+ export declare function unquoteGitPath(path: string): string;
27
42
  /** Parse `status --porcelain=v1 -b` into branch + file rows. */
28
43
  export declare function parseStatus(stdout: string): GitStatus;
29
44
  /** Parse the \x1f/\x1e log format into commits. */
@@ -2,9 +2,43 @@
2
2
  * Small JSON body/response helpers for the /api/dsh-remote route family.
3
3
  */
4
4
  import type { IncomingMessage, OutgoingHttpHeaders, ServerResponse } from 'node:http';
5
+ /**
6
+ * Outcome of one bounded body read.
7
+ *
8
+ * The discriminant exists because `null` collapsed three very different cases
9
+ * (empty, malformed, too large) into one, and the caller could only answer them
10
+ * all the same way. `too-large` is what a 413 should be built from.
11
+ */
12
+ export type JsonBodyResult = {
13
+ kind: 'ok';
14
+ value: unknown;
15
+ } | {
16
+ kind: 'empty';
17
+ } | {
18
+ kind: 'invalid';
19
+ } | {
20
+ kind: 'too-large';
21
+ maxBytes: number;
22
+ };
23
+ /**
24
+ * Bounded body reader with a truthful outcome.
25
+ *
26
+ * Oversize no longer destroys the request immediately: returning early from the
27
+ * `for await` loop would tear the socket down, and the caller's 400/413 then
28
+ * reaches the client as a connection reset (the reported A11 symptom). The body
29
+ * is drained instead, up to `DRAIN_LIMIT_BYTES`, so the route can answer with a
30
+ * readable JSON error; an absurd stream is still cut off with `destroy()`.
31
+ */
32
+ export declare function readJsonBodyResult(req: IncomingMessage, opts?: {
33
+ maxBytes?: number;
34
+ objectOnly?: boolean;
35
+ }): Promise<JsonBodyResult>;
5
36
  /**
6
37
  * Lenient bounded body reader: parse a request body as JSON, or null on an
7
38
  * empty body, invalid JSON, or a body past maxBytes (default 64 KiB).
39
+ *
40
+ * Facade over {@link readJsonBodyResult} for the existing route call sites; new
41
+ * code should use the result form so `too-large` can be answered with a 413.
8
42
  */
9
43
  export declare function readJsonBody(req: IncomingMessage, opts?: {
10
44
  maxBytes?: number;
@@ -12,3 +46,13 @@ export declare function readJsonBody(req: IncomingMessage, opts?: {
12
46
  }): Promise<unknown | null>;
13
47
  /** Write one JSON response. */
14
48
  export declare function writeJson(res: ServerResponse, status: number, body: unknown, headers?: OutgoingHttpHeaders): void;
49
+ /**
50
+ * Write one failed-operation response, tagging a budget that merely ran out.
51
+ *
52
+ * `code: 'deadline'` is what lets the browser tell "this one request was too
53
+ * slow" from "the link is down": the client keeps the status chip green and the
54
+ * editor editable, while the operation still fails with a readable reason. Only
55
+ * the error object carries that distinction — the message is prose, and matching
56
+ * on prose stops working the moment the sentence changes.
57
+ */
58
+ export declare function writeRouteError(res: ServerResponse, error: unknown): void;
@@ -23,6 +23,8 @@ export declare const REMOTE_FILE_SEARCH_MAX_RESULTS = 20;
23
23
  export declare const REMOTE_FILE_SEARCH_MAX_ENTRIES = 50000;
24
24
  /** Mirrored stock exclusion list (order kept for diffability). */
25
25
  export declare const REMOTE_FILE_SEARCH_EXCLUDED_DIRECTORIES: readonly string[];
26
+ /** Why the cached index is a bounded prefix instead of the whole tree. */
27
+ export type RemoteIndexCap = 'entries' | 'bytes' | 'timeout';
26
28
  export interface RemoteFileSearchDeps {
27
29
  /** Remote fs view (worlds.fsFor) for scoped live listings. */
28
30
  fs: FileSystem;
@@ -32,10 +34,17 @@ export interface RemoteFileSearchDeps {
32
34
  remoteRoot: string;
33
35
  /** Optional warn sink (router wires ctx.logger). */
34
36
  warn?: (message: string) => void;
37
+ /** Override the post-cap close wait (tests only; production keeps the default). */
38
+ doneTimeoutMs?: number;
35
39
  }
36
40
  export declare class RemoteFileSearch {
37
- private readonly deps;
38
41
  private readonly excluded;
42
+ /**
43
+ * Explicit field assignment instead of a constructor parameter property: the
44
+ * local gates load this module through Node's type-stripping runner (same as
45
+ * `changes/recorder.ts`), which rejects parameter properties.
46
+ */
47
+ private readonly deps;
39
48
  private settled;
40
49
  private pending;
41
50
  private pendingAbort;
@@ -44,7 +53,17 @@ export declare class RemoteFileSearch {
44
53
  private disposed;
45
54
  /** Monotonic invalidation counter; a scan started below it is stale. */
46
55
  private invalidations;
56
+ /** Why the cached index is bounded, or undefined when it is complete. */
57
+ private cappedIndex;
47
58
  constructor(deps: RemoteFileSearchDeps);
59
+ /**
60
+ * Why the current index is a bounded prefix, or `undefined` for a complete one.
61
+ *
62
+ * The `@` surface itself returns candidates only (its contract is the stock
63
+ * local list), so this is the honest place to expose "you are looking at a
64
+ * prefix": host logs get the warning, and a future consumer can surface it.
65
+ */
66
+ get indexCap(): RemoteIndexCap | undefined;
48
67
  /**
49
68
  * Drop the cached index (tool activity); the next bare query rebuilds.
50
69
  *
@@ -67,7 +86,25 @@ export declare class RemoteFileSearch {
67
86
  private listDirectory;
68
87
  /** Cached full listing; concurrent callers share one in-flight build. */
69
88
  private indexFor;
70
- /** One remote `rg --files` run, head-capped, sorted for determinism. */
89
+ /**
90
+ * One remote `rg --files` run, head-capped, sorted for determinism.
91
+ *
92
+ * A cap is a BOUNDED ANSWER, not a failure: whatever was read before the cap is
93
+ * still the prefix of the listing, and it used to be thrown away because the
94
+ * process's own SIGTERM (we killed it) looked like a non-zero exit. On a
95
+ * monorepo past 50k files that made the bare `@` query answer "nothing to
96
+ * reference" for a repo full of files. Now the prefix is served and
97
+ * {@link RemoteFileSearch.indexCap} / the warn sink say it is a prefix.
98
+ */
71
99
  private buildIndex;
100
+ /**
101
+ * Wait for the ended scan to close, but never forever.
102
+ *
103
+ * `handle.done` settles from the transport's close event; a half-dead channel
104
+ * can withhold it for the life of the process. Every outcome is reported as a
105
+ * fact — a rejection stays a rejection so the caller can still treat it as a
106
+ * failure when nothing else explains the scan.
107
+ */
108
+ private waitForDone;
72
109
  private warn;
73
110
  }
@@ -17,6 +17,18 @@ export interface RpcHello {
17
17
  platform: string;
18
18
  nodeVersion: string;
19
19
  }
20
+ /**
21
+ * Close each resource, ignoring failures — and keeping going.
22
+ *
23
+ * Teardown runs while an error is already unwinding: one resource that throws on
24
+ * close must not stop the NEXT one from being released (that skipped socket is
25
+ * exactly the leak this exists to prevent). Exported so the gate can drive the
26
+ * real behaviour with fake resources; there is no transport to stub locally.
27
+ */
28
+ export declare function closeQuietly(resources: ReadonlyArray<{
29
+ close?: () => void;
30
+ end?: () => void;
31
+ }>): void;
20
32
  export declare class RpcConnection {
21
33
  private readonly opts;
22
34
  private conn;
@@ -58,6 +70,20 @@ export declare class RpcConnection {
58
70
  private reconnect;
59
71
  dispose(): Promise<void>;
60
72
  private peerReady;
73
+ /**
74
+ * Release the current transport, whatever state it is in.
75
+ *
76
+ * Shared by `reconnect()`, a failed `open()` and `dispose()` because all three
77
+ * carry the same obligation: afterwards no ssh session, channel or heartbeat may
78
+ * survive. A half-open transport is a real leak — the socket lives until the
79
+ * remote's keepalive gives up, and the next attempt opens a SECOND session.
80
+ * `stderrTail` is cleared too: it describes the connection being torn down, and
81
+ * keeping it would attribute the NEXT failure to the previous transport's error
82
+ * output.
83
+ */
84
+ private teardownTransport;
61
85
  private open;
86
+ /** The part of {@link open} that runs once the socket object exists. */
87
+ private dialAndHello;
62
88
  private invalidate;
63
89
  }
@@ -1,11 +1,30 @@
1
+ import type { Context } from '@deepseek-ai/cordis';
1
2
  import { SpillStore } from '@deepseek-ai/dsh-spill';
2
3
  import type { SaveTextSpill, SpillRef } from '@deepseek-ai/dsh-spill';
3
4
  export default class TransparentSpillStore extends SpillStore {
4
5
  static inject: string[];
6
+ /** Hosts already TTL-swept by THIS process (one `find` per host, not per spill). */
7
+ private readonly sweptAliases;
8
+ /** session id -> directories written for it, for the best-effort dispose prune. */
9
+ private readonly sessionDirs;
10
+ constructor(ctx: Context);
5
11
  private get local();
6
12
  private get remote();
7
13
  private effective;
8
14
  saveText(input: SaveTextSpill): Promise<SpillRef>;
9
15
  /** Explicit remote policy: mirrored mode, spill dir as the fence root. */
10
16
  private policyFor;
17
+ /**
18
+ * Sweep one host's spill root once per process.
19
+ *
20
+ * The marker is set BEFORE awaiting so two concurrent first spills on the same
21
+ * host cannot both issue the sweep; a failed sweep still leaves the host marked
22
+ * (retention is a nicety, retrying it on every spill would be a tax).
23
+ */
24
+ private sweepOnce;
25
+ /** Remember one written directory for the dispose prune (bounded, oldest first). */
26
+ private remember;
27
+ /** Best-effort TTL check for the directories one session wrote. Never throws. */
28
+ private pruneSession;
29
+ private warn;
11
30
  }
@@ -6,6 +6,8 @@
6
6
  */
7
7
  import { SubprocessRuntime } from '@deepseek-ai/dsh-subprocess';
8
8
  import type { SubprocessHandle, SubprocessSpawnSpec, SubprocessTerminalEnvironment, SubprocessTerminalHandle, SubprocessTerminalSpawnSpec } from '@deepseek-ai/dsh-subprocess';
9
+ /** True when argv selects a Windows shell (unsupported in remote worlds). */
10
+ export declare function isWindowsShellArgv(argv: readonly string[]): boolean;
9
11
  export default class TransparentSubprocessRuntime extends SubprocessRuntime {
10
12
  static inject: string[];
11
13
  private get local();
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Remote spill retention: the policy constant and the pure command builders.
3
+ *
4
+ * Why this module exists: the spill backend writes model-facing artifacts into
5
+ * the remote `$HOME` under a per-session directory (`router-spill.ts`), and the
6
+ * spill service definition owns NO retention policy ({@link SpillStore} only
7
+ * declares `saveText`). Nothing removed those files, so a long-lived host grew
8
+ * one artifact per oversized tool result forever — including the content of
9
+ * command output, which is exactly the material that should not live on a build
10
+ * machine indefinitely.
11
+ *
12
+ * The policy is deliberately lazy: a TTL sweep per host (one `find` on the first
13
+ * spill), plus a per-session directory check when a session is disposed. Two
14
+ * rules shape the commands below:
15
+ *
16
+ * 1. **Deletion must never block a write.** Everything is best-effort (see
17
+ * {@link runBestEffort}); a failed cleanup is logged and forgotten.
18
+ * 2. **Deletion must be impossible to aim at anything else.** Every path is an
19
+ * absolute POSIX path under `<home>/.dsh-helpers/spills`, every shell word is
20
+ * single-quoted, the sweep is capped at depth 1 and to `session-*`, and the
21
+ * session-directory check only matches the directory itself (`-maxdepth 0`).
22
+ *
23
+ * Kept free of cordis/pool on purpose, so `scripts/check-spill-retention.mjs`
24
+ * drives the real builders without a host.
25
+ */
26
+ /** Subdirectory of the remote `$HOME` that holds every spilled artifact. */
27
+ export declare const SPILLS_SUBDIR = ".dsh-helpers/spills";
28
+ /** Default lifetime of a remote spill directory, in whole days. */
29
+ export declare const SPILL_TTL_DAYS_DEFAULT = 14;
30
+ /** The TTL in days: `DSH_REMOTE_VS_SPILL_TTL_DAYS` when sane, else the default. */
31
+ export declare function spillTtlDays(): number;
32
+ /** A TTL clamped to the supported range (also used by direct callers/tests). */
33
+ export declare function clampTtlDays(value: number): number;
34
+ /** POSIX single-quote one shell word. Throws on NUL, which no shell can carry. */
35
+ export declare function shq(word: string): string;
36
+ /** The spills root inside one remote home. */
37
+ export declare function spillRoot(home: string): string;
38
+ /**
39
+ * The per-session spill directory.
40
+ *
41
+ * Mirrors `router-spill.ts`'s previous inline spelling so existing sessions keep
42
+ * finding their files, and rejects anything that could escape the root: a session
43
+ * id comes from the Host, but a directory name derived from it still has to be
44
+ * one safe path segment.
45
+ */
46
+ export declare function sessionSpillDir(home: string, sessionId: string | number): string;
47
+ /**
48
+ * One sweep command for a whole host: every `session-*` directory under the
49
+ * spills root older than `ttlDays`.
50
+ *
51
+ * `-mindepth 1 -maxdepth 1` keeps the walk inside the root's own children (no
52
+ * recursion, so a stray directory elsewhere can never match), `-name 'session-*'`
53
+ * pins the namespace, and `|| true` makes "the root does not exist yet" (the
54
+ * normal first-run case) a success: retention is not allowed to look like
55
+ * failure to its caller.
56
+ */
57
+ export declare function spillSweepCommand(home: string, ttlDays: number): string;
58
+ /**
59
+ * One command for a single session's spill directory: remove it only when the
60
+ * directory itself is older than the TTL.
61
+ *
62
+ * The mtime gate is what makes this safe for forked sessions: `dsh-spill` states
63
+ * that a fork inherits the parent's locators without copying them, so a young
64
+ * directory may still be referenced by a live child. `-maxdepth 0` matches the
65
+ * directory alone — never its contents.
66
+ */
67
+ export declare function spillDirSweepCommand(dir: string, ttlDays: number): string;
68
+ /**
69
+ * Run one retention step without ever failing the caller.
70
+ *
71
+ * A write path that waits on a cleanup is a write path that can be broken by a
72
+ * cleanup; the caller only gets a warning sink. Returns whether the step ran.
73
+ */
74
+ export declare function runBestEffort(what: string, run: () => Promise<void>, warn?: (message: string) => void): Promise<boolean>;
@@ -151,6 +151,17 @@ export declare class RemoteWorlds {
151
151
  homeFor(alias: string): Promise<string>;
152
152
  /** Best-effort remote mkdir -p (for paths the fs seam cannot create). */
153
153
  mkdirRemote(alias: string, dir: string): Promise<void>;
154
+ /**
155
+ * TTL-sweep one host's spill root (retention, best effort).
156
+ *
157
+ * Deliberately narrow: the command is built by `spill-retention.ts` (absolute
158
+ * path under that host's `$HOME`, `session-*` children only, depth 1), so this
159
+ * method cannot be talked into deleting an arbitrary directory. Callers treat a
160
+ * rejection as a warning, never as an operation failure.
161
+ */
162
+ sweepSpillRoot(alias: string, home: string, ttlDays: number): Promise<void>;
163
+ /** Remove one session's spill directory when it is older than the TTL (best effort). */
164
+ sweepSpillDir(alias: string, dir: string, ttlDays: number): Promise<void>;
154
165
  /** Drop one host's RPC + fs view + proc runtime (call after host update/delete). */
155
166
  dropHost(alias: string): Promise<void>;
156
167
  dispose(): Promise<void>;