dsh-remote-vs 0.8.6 → 0.8.8

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.
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The title one remote binding gets in DSH's own workspace sidebar.
3
+ *
4
+ * The sidebar (and the session grouping under it) is rendered by the shell from
5
+ * the workspace REGISTRY, so this string is the only label the user ever sees
6
+ * there. It used to be built from the remote PATH's last segment, which threw
7
+ * away the one name the user had chosen: a workspace created as
8
+ * "P710_userdebug" showed up as `… > P710`, and two bindings that differ only
9
+ * deeper down (`…/userdebug/P710` and `…/userdebug/P710_fac`) became
10
+ * indistinguishable.
11
+ *
12
+ * The alias stays in front: it is what tells two hosts apart, and the part after
13
+ * it is what takes the workspace name.
14
+ *
15
+ * DISPLAY ONLY. The registry resolves a workspace by its canonical PATH
16
+ * (`resolveByPath`) and its own documentation says the title is "used only when
17
+ * a new record is created" and that different paths may share one — so a title
18
+ * never decides routing, and none of the plugin's routing reads it.
19
+ *
20
+ * Pure and dependency-free, so `scripts/check-diff-ui.mjs` can pin it without a
21
+ * host (the host half imports cordis and cannot load outside DSH).
22
+ */
23
+
24
+ /** Last path segment of an absolute remote path ('' when the path is `/`). */
25
+ function pathBase(remotePath: string): string {
26
+ const parts = remotePath.split('/').filter(part => part !== '')
27
+ return parts.pop() ?? remotePath
28
+ }
29
+
30
+ /** The alias part of a title, with a readable fallback. */
31
+ function aliasOf(alias: string): string {
32
+ return alias.trim() === '' ? 'remote' : alias.trim()
33
+ }
34
+
35
+ /**
36
+ * The title this binding SHOULD have: `alias > workspace name`.
37
+ *
38
+ * @param binding - alias, the name the user typed, and the remote path.
39
+ * @returns `alias > name`, falling back to the path's last segment when no name
40
+ * was given (bindings created before names existed, or an empty field).
41
+ */
42
+ export function workspaceTitle(binding: { alias: string; name?: string; remotePath: string }): string {
43
+ const named = (binding.name ?? '').trim()
44
+ return `${aliasOf(binding.alias)} > ${named !== '' ? named : pathBase(binding.remotePath)}`
45
+ }
46
+
47
+ /**
48
+ * The title the OLD code produced: `alias > <last path segment>`, name ignored.
49
+ *
50
+ * Kept so an existing registration can be retitled ONLY when its current title
51
+ * is still exactly this. That is what keeps the upgrade from ever touching a
52
+ * title the user renamed by hand in the shell's workspace settings.
53
+ *
54
+ * @param binding - alias and remote path; the name is deliberately unused.
55
+ */
56
+ export function legacyWorkspaceTitle(binding: { alias: string; remotePath: string }): string {
57
+ return `${aliasOf(binding.alias)} > ${pathBase(binding.remotePath)}`
58
+ }