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
@@ -0,0 +1,111 @@
1
+ import type { RemoteConnectionStatus } from '../protocol.ts';
2
+ export type ConnectionState = 'ok' | 'error' | 'idle';
3
+ /** Automatic-retry cadence for an errored link (one dial per tick). */
4
+ export declare const AUTO_RETRY_MS = 30000;
5
+ /**
6
+ * Automatic attempts allowed per error episode.
7
+ *
8
+ * Not endless on purpose: each attempt is a real SSH dial, and repeated dials
9
+ * against a password-auth host can count towards a lockout. After the budget
10
+ * the chip stays a manual retry control.
11
+ */
12
+ export declare const AUTO_RETRY_MAX_ATTEMPTS = 3;
13
+ /**
14
+ * Decide one automatic-retry tick.
15
+ *
16
+ * Pure so the budget can be pinned without a browser: ok/idle reset the
17
+ * count, rror consumes one attempt until the budget is spent.
18
+ */
19
+ export declare function consumeAutoRetry(state: ConnectionState, attempts: number): {
20
+ run: boolean;
21
+ attempts: number;
22
+ };
23
+ /**
24
+ * The i18n key for a state's label.
25
+ *
26
+ * Kept here (not inside the chip) so the gate can assert the MAPPING without a
27
+ * browser: rendering the pool's normal lazy state as "not connected" was a real
28
+ * UX defect — idle means "nothing to report yet / connects on demand", not a
29
+ * broken link.
30
+ */
31
+ export declare function connectionLabelKey(state: ConnectionState): string;
32
+ /** What the UI renders for one alias. */
33
+ export interface ConnectionView {
34
+ alias: string;
35
+ state: ConnectionState;
36
+ /** Last transport error message (only while state === 'error'). */
37
+ error?: string;
38
+ /** When the Host last saw a transport error, epoch ms. */
39
+ errorAt?: number;
40
+ /** When the Host last completed a dial / transport-level operation. */
41
+ okAt?: number;
42
+ /** A pooled SSH connection is open right now (diagnostic detail only). */
43
+ open: boolean;
44
+ /**
45
+ * Client time of the last locally noted failure. A poll that still reports
46
+ * the older success must not clear an error the page just saw.
47
+ */
48
+ notedAt?: number;
49
+ }
50
+ /**
51
+ * Whether `error` (or its message) is a transport-level failure.
52
+ *
53
+ * The flags are honoured first: a repeat failure's message is REWRITTEN to a
54
+ * localized sentence before it is thrown (see `api.call`), and downstream guards
55
+ * (toast quieting, the offline banner) must still see a link error.
56
+ *
57
+ * `deadline` wins over the text: a budget that ran out is an operation result,
58
+ * not a link failure. Its message contains "timed out", so the text rule alone
59
+ * would classify it as transport — and that is exactly what used to turn one
60
+ * slow listing into a red chip and a read-only editor.
61
+ */
62
+ export declare function isConnectionFailure(error: unknown): boolean;
63
+ /** Point the view at the workspace the user is looking at. */
64
+ export declare function setActiveConnectionAlias(alias: string): void;
65
+ /** The alias the surface currently belongs to ('' when none). */
66
+ export declare function activeConnectionAlias(): string;
67
+ /**
68
+ * Apply the Host's status list. A host-reported success clears an error only
69
+ * when it is NEWER than the local failure note: otherwise a poll that raced the
70
+ * failing operation would flip the chip back to green while the toast still
71
+ * says the request failed.
72
+ */
73
+ export declare function applyConnectionStatuses(list: readonly RemoteConnectionStatus[]): void;
74
+ /** Record a transport failure the page just observed on `alias`. */
75
+ export declare function noteConnectionFailure(alias: string, error: unknown): void;
76
+ /** Drop every cached view — tests only (a live page keeps its map). */
77
+ export declare function resetConnectionViews(): void;
78
+ /** Record that an explicit retry just succeeded for `alias`. */
79
+ export declare function markConnectionProbeOk(alias: string): void;
80
+ /** Where the last observed state came from (see `isConnectionRecovery`). */
81
+ export interface ConnectionTrace {
82
+ alias: string;
83
+ state: string | undefined;
84
+ }
85
+ /**
86
+ * Whether this is the LINK recovering, as opposed to a workspace switch.
87
+ *
88
+ * Between two already-errored hosts the alias changes while the state does not;
89
+ * counting that as a recovery would refresh the wrong workspace. The caller
90
+ * keeps a trace keyed by alias, so by the time the new host recovers this sees
91
+ * `(b, error) → (b, ok)`.
92
+ */
93
+ export declare function isConnectionRecovery(previous: ConnectionTrace | undefined, alias: string, state: string | undefined): boolean;
94
+ /** Current view of the active alias (the hook is the UI path; this is for gates). */
95
+ export declare function currentConnection(): ConnectionView | undefined;
96
+ /**
97
+ * The cached health of ONE alias (`undefined` = never observed).
98
+ *
99
+ * `currentConnection()` answers for the alias the user is LOOKING at; an action
100
+ * that carries its own alias must ask by that alias instead. The undo path is
101
+ * the case in point: its coordinates come from `undoContext()` (the change
102
+ * panel), which can point at a different workspace than the visible one, and
103
+ * reading the visible alias' state there would block (or allow) the wrong host.
104
+ *
105
+ * A cached `error` is exactly what the save path already refuses on
106
+ * (`EditorPane` offline), and an unknown alias means "no evidence" — callers
107
+ * must treat `undefined` as "not proven down", never as healthy.
108
+ */
109
+ export declare function connectionStateOf(alias: string): ConnectionState | undefined;
110
+ /** Subscribe to the active alias's connection view (undefined when none). */
111
+ export declare function useConnectionStatus(): ConnectionView | undefined;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Remote environment doctor: ONE POSIX `sh` line that probes what the remote
3
+ * actually has, plus the pure parser that turns its output into three-state
4
+ * rows.
5
+ *
6
+ * Why this module exists
7
+ * ----------------------
8
+ * The client already depends on remote tools whose absence is invisible until
9
+ * something behaves worse than it should: without `rg` a content search falls
10
+ * back to a recursive `grep` that never finishes on a large tree; without
11
+ * `setsid --wait` a timeout can no longer end the remote command group and the
12
+ * only trace is a host-console warning; a full `$HOME` shows up as a failed
13
+ * push. Each of those was already documented as a known limit — this puts the
14
+ * same evidence on one screen instead of leaving it to guesswork.
15
+ *
16
+ * The three-state rule
17
+ * --------------------
18
+ * `missing` is a POSITIVE fact: the remote answered "no such command". Every
19
+ * other outcome — no marker line, an empty capture, an unparseable row, a
20
+ * link that dropped before the exit status, a budget that ran out — is
21
+ * IGNORANCE and must be reported as `unknown` with the reason. Encoding
22
+ * ignorance as a negative result is the incident-index defect this feature
23
+ * exists to avoid: a user who is told "rg is not installed" when the answer is
24
+ * actually "the probe did not run" will install the wrong thing and still be
25
+ * broken.
26
+ *
27
+ * Where the evidence comes from
28
+ * -----------------------------
29
+ * Every probe line carries a marker (`@@RVS-DOC <key> <state> <detail>`) so
30
+ * the parser never has to guess from human-readable output, and the shell
31
+ * folds each detail onto one line — output content can therefore never forge
32
+ * or split a marker. The script merges stderr into the capture (`2>&1`) and
33
+ * never uses `2>/dev/null`: dropping stderr is how the "permission denied"
34
+ * case used to look exactly like "not installed" (the incident index calls
35
+ * that out by name).
36
+ *
37
+ * What the tools' own failures look like
38
+ * --------------------------------------
39
+ * A shell reports exit 127 BOTH for "no such command" and for a binary that
40
+ * exists but cannot start (missing shared library, broken interpreter). The
41
+ * first is a positive answer, the second is ignorance — so the probe asks
42
+ * `command -v` which one happened instead of assuming. `sshd` is looked up at
43
+ * its absolute locations first: on Debian-family hosts a non-root login PATH
44
+ * does not contain `/usr/sbin`, and a bare lookup would report a running sshd
45
+ * as missing.
46
+ *
47
+ * Pure module: no React, no DOM, no i18n copy (labels are i18n KEYS; the panel
48
+ * translates them, so this file can be gate-evaluated in plain node).
49
+ */
50
+ export type DoctorState = 'ok' | 'missing' | 'unknown';
51
+ /** One row of the report. */
52
+ export interface DoctorItem {
53
+ /** Stable probe id (`os`, `rg`, …) — also what the copied report groups by. */
54
+ key: string;
55
+ /** i18n key for the row label. Translated by the panel, not here. */
56
+ label: string;
57
+ state: DoctorState;
58
+ /**
59
+ * Evidence: the remote's own words, or the reason this probe could not
60
+ * decide. Never empty for `unknown` — an unexplainable unknown is noise.
61
+ */
62
+ detail: string;
63
+ }
64
+ export interface DoctorProbe {
65
+ key: string;
66
+ label: string;
67
+ }
68
+ /**
69
+ * Probe order is report order: environment first, then the tools the client
70
+ * actually depends on, then the host-side facts (disk, helper installs).
71
+ */
72
+ export declare const DOCTOR_PROBES: readonly DoctorProbe[];
73
+ /** Prefix of every probe line. Keep in sync with the script below. */
74
+ export declare const DOCTOR_MARK = "@@RVS-DOC";
75
+ /**
76
+ * State words for the badge and the copied report. Kept beside the parser
77
+ * because both the panel and `formatDoctorReport` need the same mapping; the
78
+ * values are listed in `DYNAMIC_KEYS` since no literal `t()` call reaches them.
79
+ */
80
+ export declare const DOCTOR_STATE_KEY: Record<DoctorState, string>;
81
+ /**
82
+ * Budget for the whole probe line. It is a handful of local commands over one
83
+ * exec channel; 20 s leaves room for a slow sshd/`ldd` start without keeping
84
+ * the panel spinning behind a dead link.
85
+ */
86
+ export declare const DOCTOR_TIMEOUT_MS = 20000;
87
+ /**
88
+ * Remote install root, mirrored from `REMOTE_ROOT` in `src/deploy.ts`.
89
+ *
90
+ * The client bundle CANNOT import that module (`deploy.ts` pulls `node:crypto`,
91
+ * `node:fs` and the SFTP/SSH layer, which the client build's purity gate in
92
+ * `tsdown.config.ts` rejects), so the literal has to live here.
93
+ * `scripts/check-doctor.mjs` imports `REMOTE_ROOT` from `deploy.ts` and fails
94
+ * when the two drift. That cross-check matters: the first version of this probe
95
+ * looked for a file name the deploy pipeline never writes, so every real host
96
+ * reported "no helper installed" — a self-check that guesses the layout is
97
+ * worse than none.
98
+ */
99
+ export declare const HELPER_ROOT = "~/.dsh-helpers";
100
+ /** The single remote command the panel runs through `api.exec`. */
101
+ export declare function doctorScript(): string;
102
+ /**
103
+ * Parse the probe output into one row per known probe.
104
+ *
105
+ * @param exitCode - the remote exit status, or `null` when the channel died /
106
+ * the budget ran out. `null` invalidates the WHOLE run: partial stdout from a
107
+ * killed command is not evidence about the probes it never reached, so every
108
+ * row becomes `unknown` rather than some rows silently keeping stale states.
109
+ */
110
+ export declare function parseDoctor(stdout: string, stderr: string, exitCode: number | null): DoctorItem[];
111
+ /**
112
+ * The all-unknown report for a run that never produced a result at all (exec
113
+ * rejected: dead link, timeout at the client, host refused the route). Kept
114
+ * separate so the panel cannot accidentally drop a partial list on the floor.
115
+ */
116
+ export declare function doctorFailure(reason: string): DoctorItem[];
117
+ /**
118
+ * Plain-text report for "copy all" — what the user pastes into a support
119
+ * thread. One line per probe, states spelled out (no color codes to decode),
120
+ * and every detail verbatim so the reply can be checked instead of trusted.
121
+ */
122
+ export declare function formatDoctorReport(alias: string, items: DoctorItem[], t: (key: string) => string, at?: number): string;
@@ -14,12 +14,39 @@
14
14
  * unreadable path shows the Host's real error instead of an empty saved file.
15
15
  */
16
16
  /** What one download attempt ended as. */
17
- export type DownloadOutcome = 'saved' | 'downloaded';
17
+ export type DownloadOutcome =
18
+ /** Bytes went through the save picker into the user's chosen file. */
19
+ 'saved-picker'
20
+ /** Bytes were fully received and then handed to the browser to save. */
21
+ | 'saved-browser'
22
+ /**
23
+ * The URL was handed to the browser, which now owns the transfer: its bytes,
24
+ * its failures and its cancel. The panel must NOT report completion.
25
+ */
26
+ | 'handedOff';
18
27
  /** One progress sample: `total` is absent for a streamed archive (chunked). */
19
28
  export interface DownloadProgress {
20
29
  loaded: number;
21
30
  total?: number;
22
31
  }
32
+ /**
33
+ * Largest body the fallback path buffers before handing the URL to the browser.
34
+ *
35
+ * The save picker streams straight to disk, but a browser without the File
36
+ * System Access API can only be given a URL. Owning the transfer for small and
37
+ * medium files is what lets the panel see a Host error (a 502 JSON used to be
38
+ * saved as a file), report real progress and cancel; a 64 MiB ceiling keeps a
39
+ * multi-GB artifact from being assembled in the tab's memory.
40
+ */
41
+ export declare const FALLBACK_BUFFER_MAX_BYTES: number;
42
+ /**
43
+ * What the fallback should do with a body of `declaredTotal` bytes.
44
+ *
45
+ * `handoff` means the browser must own the transfer: too large to assemble in
46
+ * memory, and no failure/progress/cancel can be reported for it. Exported pure
47
+ * so the gate can pin the boundary without allocating 64 MiB.
48
+ */
49
+ export declare function fallbackPlan(declaredTotal: number | undefined): 'buffer' | 'handoff';
23
50
  /** Hooks the runner uses for the progress panel and its cancel button. */
24
51
  export interface SaveOptions {
25
52
  onProgress?: (progress: DownloadProgress) => void;
@@ -49,16 +76,19 @@ export declare function downloadManyUrl(alias: string, paths: readonly string[])
49
76
  * the document level.
50
77
  */
51
78
  export declare function triggerDownload(href: string, fileName: string): void;
79
+ /** Hand a fully received body to the browser's own "save file" path. */
80
+ export declare function saveBytesViaBrowser(bytes: readonly Uint8Array[], fileName: string): void;
52
81
  /**
53
82
  * Save one streamed URL to a destination the user picks.
54
83
  *
55
84
  * The picker runs while the click's transient activation is still valid, so it
56
85
  * must come before the network work. A picker that refuses the call (expired
57
- * activation, policy) falls back to the browser download flow instead of
58
- * failing the download outright.
86
+ * activation, policy) falls back to {@link saveViaFallback} instead of failing
87
+ * the download outright.
59
88
  *
60
- * @returns `'saved'` for the picked destination, `'downloaded'` for the
61
- * browser-default fallback.
89
+ * @returns `'saved-picker'` for the picked destination, `'saved-browser'` when
90
+ * the fallback received every byte and handed them to the browser, and
91
+ * `'handedOff'` when the browser owns an unverified transfer.
62
92
  */
63
93
  export declare function saveRemoteUrl(href: string, fileName: string, options?: SaveOptions): Promise<DownloadOutcome>;
64
94
  /** Save one remote file (fresh name from its POSIX basename). */
@@ -8,7 +8,7 @@
8
8
  * a download already streaming must keep running to completion.
9
9
  */
10
10
  /** One download's lifecycle state. */
11
- export type DownloadStatus = 'running' | 'done' | 'failed' | 'cancelled';
11
+ export type DownloadStatus = 'running' | 'done' | 'failed' | 'cancelled' | 'handedOff';
12
12
  /** One task as the dock renders it. */
13
13
  export interface DownloadTask {
14
14
  id: string;
@@ -31,6 +31,23 @@ export interface DownloadTask {
31
31
  }
32
32
  /** Human byte size for the progress line. */
33
33
  export declare function formatByteCount(bytes: number): string;
34
+ /**
35
+ * One line of detail under a task's bar (pure: the dock only renders it).
36
+ *
37
+ * KNOWN size includes 0 — a zero-byte file has a size and it is 0. Treating
38
+ * `total === 0` as "unknown" printed `0 B · size unknown` for every empty file.
39
+ * An `undefined` total keeps both honest cases: a directory/selection archive
40
+ * is chunked by design (indeterminate), while a plain file with no total means
41
+ * a shell or proxy stripped `content-length` (DSH Desktop does that).
42
+ */
43
+ export declare function downloadDetailText(task: DownloadTask, t: (key: string) => string): string;
44
+ /**
45
+ * Percent for the bar, or `undefined` while the size is unknown (archives).
46
+ *
47
+ * `total === 0` is COMPLETE, not unknown: every one of an empty file's zero
48
+ * bytes has arrived, so the bar is full instead of a permanent flowing stripe.
49
+ */
50
+ export declare function downloadPercent(task: DownloadTask): number | undefined;
34
51
  /** Store surface: `useSyncExternalStore(subscribe, getSnapshot, getSnapshot)`. */
35
52
  export declare const downloadsStore: {
36
53
  subscribe(listener: () => void): () => void;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Which remote spelling a clicked file reference actually exists at.
3
+ *
4
+ * Why this module exists
5
+ * ----------------------
6
+ * A click on a file reference resolves to an ordered candidate list (workspace
7
+ * root first, then the session's current directory — see
8
+ * `remote-file-open-target.ts`), and the caller used to accept only two
9
+ * answers from the existence probe: "it exists" or "it does not". A TIMEOUT or
10
+ * a TRANSPORT failure therefore read as "this spelling is wrong, try the next
11
+ * one": one dead click became N remote stat calls, each paying its own 4s
12
+ * deadline, followed by a 7s `find` fallback — with no UI feedback at all. On a
13
+ * known-broken link every candidate fails the same way, so the extra probes
14
+ * could never find anything either.
15
+ *
16
+ * The project already learned this lesson once, in `scm/actions.ts`:
17
+ * `resolveRepoRoot` folded "not a repository" and "the probe did not answer"
18
+ * into `undefined`, and the cache treated the empty answer as fact (MAINTENANCE
19
+ * §2.25: "仓库探测必须三态"). This is the same rule for the click path:
20
+ * `exists` / `missing` / `unknown`, and `unknown` STOPS the chain.
21
+ *
22
+ * Everything effectful is injected, so the decision table is drivable in node
23
+ * without a store, a React tree or a fake SSH host
24
+ * (`scripts/check-file-open-click.mjs`).
25
+ */
26
+ /** What one candidate answer means for the chain. */
27
+ export type CandidateVerdict = {
28
+ kind: 'exists';
29
+ path: string;
30
+ }
31
+ /** Every candidate answered "no such file": the caller may try a suffix search. */
32
+ | {
33
+ kind: 'missing';
34
+ }
35
+ /** Cannot tell (timed out, link down): stop probing, open the primary spelling. */
36
+ | {
37
+ kind: 'unknown';
38
+ };
39
+ /** Everything the probe needs from the outside world. */
40
+ export interface CandidateProbeDeps {
41
+ /** One remote stat; rejects with the host's error. */
42
+ stat: (alias: string, path: string) => Promise<unknown>;
43
+ /**
44
+ * Bound one probe. Resolves `undefined` when the budget ran out — the shape
45
+ * `withDeadline` already has (a timeout is not an error there).
46
+ */
47
+ deadline: <T>(promise: Promise<T>, ms: number) => Promise<T | undefined>;
48
+ /** The link's last known state; only `'error'` is evidence of a dead link. */
49
+ connection: (alias: string) => 'ok' | 'error' | 'idle' | undefined;
50
+ /** Whether an error means "the link", as opposed to "this path is missing". */
51
+ isLinkFailure: (error: unknown) => boolean;
52
+ }
53
+ /**
54
+ * Probe the candidates in order, stopping at the first EXISTS **or the first
55
+ * UNKNOWN**.
56
+ *
57
+ * @param alias - host alias the paths live on.
58
+ * @param candidates - candidate spellings, most likely first.
59
+ * @param deps - injected effects (stat / deadline / connection / classifier).
60
+ * @param timeoutMs - budget for ONE probe.
61
+ * @returns the verdict; `unknown` is not a failure — it tells the caller to
62
+ * stop guessing and show the real remote error instead.
63
+ */
64
+ export declare function probeCandidates(alias: string, candidates: readonly string[], deps: CandidateProbeDeps, timeoutMs: number): Promise<CandidateVerdict>;
@@ -11,7 +11,7 @@
11
11
  * them here keeps the check meaningful in both directions: every entry must
12
12
  * exist in both dictionaries, and nothing else may be unreferenced.
13
13
  */
14
- export declare const DYNAMIC_KEYS: readonly ["common.loading", "editor.saving", "editor.unsaved", "editor.saved", "scm.hunkStaged", "scm.hunkUnstaged", "scm.hunkReverted", "history.details", "history.content", "history.diff", "downloads.running", "downloads.indeterminate", "downloads.sizeUnknown"];
14
+ export declare const DYNAMIC_KEYS: readonly ["common.loading", "editor.saving", "editor.unsaved", "editor.saved", "scm.hunkStaged", "scm.hunkUnstaged", "scm.hunkReverted", "history.details", "history.content", "history.diff", "downloads.running", "downloads.indeterminate", "downloads.sizeUnknown", "downloads.handedOff", "term.disconnected", "term.closed", "connection.ok", "connection.error", "connection.idle", "connection.actionFailed", "doctor.state.ok", "doctor.state.missing", "doctor.state.unknown", "doctor.item.os", "doctor.item.libc", "doctor.item.git", "doctor.item.rg", "doctor.item.tar", "doctor.item.setsid", "doctor.item.disk", "doctor.item.nproc", "doctor.item.memory", "doctor.item.helpers", "doctor.item.sshd"];
15
15
  export type Lang = 'zh' | 'en';
16
16
  export declare function detectLang(): Lang;
17
17
  export declare function makeT(lang: Lang): (key: string) => string;