@kabmo-labs/kabmo 0.15.0 → 0.17.0

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 (177) hide show
  1. package/README.md +3 -2
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +412 -394
  4. package/dist/client/static/js/index-3ve31rzx.css +1 -0
  5. package/dist/client/static/js/{index-mx658m43.js → index-rerjq5th.js} +846 -844
  6. package/marketplace/plugins/stats/README.md +27 -8
  7. package/marketplace/plugins/stats/package.json +2 -2
  8. package/marketplace/plugins/stats/src/HeaderReadout.test.tsx +2 -1
  9. package/marketplace/plugins/stats/src/HeaderReadout.tsx +6 -2
  10. package/marketplace/plugins/stats/src/KillConfirm.test.tsx +159 -0
  11. package/marketplace/plugins/stats/src/KillConfirm.tsx +145 -0
  12. package/marketplace/plugins/stats/src/ProcessTable.tsx +54 -8
  13. package/marketplace/plugins/stats/src/TotalsBar.test.tsx +5 -2
  14. package/marketplace/plugins/stats/src/TotalsBar.tsx +13 -3
  15. package/marketplace/plugins/stats/src/app.test.tsx +100 -4
  16. package/marketplace/plugins/stats/src/app.tsx +51 -4
  17. package/marketplace/plugins/stats/src/groups.test.ts +1 -1
  18. package/marketplace/plugins/stats/src/kill.test.ts +131 -0
  19. package/marketplace/plugins/stats/src/kill.ts +74 -0
  20. package/marketplace/plugins/stats/src/labels.test.ts +1 -0
  21. package/marketplace/plugins/stats/src/machine.test.ts +77 -0
  22. package/marketplace/plugins/stats/src/machine.ts +115 -0
  23. package/marketplace/plugins/stats/src/proc/darwin.ts +38 -0
  24. package/marketplace/plugins/stats/src/proc/linux.ts +4 -0
  25. package/marketplace/plugins/stats/src/proc/ps.ts +1 -0
  26. package/marketplace/plugins/stats/src/proc/types.ts +11 -0
  27. package/marketplace/plugins/stats/src/sampler.test.ts +42 -4
  28. package/marketplace/plugins/stats/src/sampler.ts +32 -18
  29. package/marketplace/plugins/stats/src/server.ts +29 -2
  30. package/marketplace/plugins/stats/src/snapshot.ts +31 -3
  31. package/package.json +3 -2
  32. package/src/client/components/common/Modal.tsx +7 -0
  33. package/src/client/components/common/code-surface/bracket-guide.test.ts +2 -2
  34. package/src/client/components/common/code-surface/bracket-guide.ts +2 -2
  35. package/src/client/components/common/code-surface/conflict-markers.ts +5 -5
  36. package/src/client/components/common/code-surface/extensions.ts +7 -4
  37. package/src/client/components/common/code-surface/theme.ts +34 -9
  38. package/src/client/components/common/code-surface/whitespace.test.ts +223 -0
  39. package/src/client/components/common/code-surface/whitespace.ts +140 -0
  40. package/src/client/components/common/{server-switcher/index.tsx → server-control/Panel.tsx} +73 -35
  41. package/src/client/components/common/{server-switcher → server-control}/index.test.tsx +98 -37
  42. package/src/client/components/common/server-control/index.tsx +118 -0
  43. package/src/client/components/layout/LeftDock.tsx +1 -0
  44. package/src/client/components/layout/desktop-layout/TopNavbar.tsx +8 -50
  45. package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +1 -0
  46. package/src/client/components/mobile/RightSidebar.tsx +1 -0
  47. package/src/client/components/mobile/mobile-main-view/Header.tsx +6 -12
  48. package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +41 -13
  49. package/src/client/components/mobile/mobile-session-sidebar/use-dock.ts +1 -0
  50. package/src/client/components/settings/Modal.tsx +9 -3
  51. package/src/client/components/settings/ProjectSelectorDropdown.tsx +19 -9
  52. package/src/client/components/settings/categories/AgentSettings.tsx +27 -6
  53. package/src/client/components/settings/categories/ProjectSettings.tsx +122 -156
  54. package/src/client/components/settings/categories/SkillCatalogSettings.tsx +220 -260
  55. package/src/client/components/settings/categories/SkillSettings.tsx +6 -3
  56. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +5 -0
  57. package/src/client/components/settings/categories/project-settings/AccentPalette.test.tsx +189 -0
  58. package/src/client/components/settings/categories/project-settings/AccentPalette.tsx +156 -24
  59. package/src/client/components/settings/categories/project-settings/AddProjectModal.tsx +175 -0
  60. package/src/client/components/settings/categories/project-settings/DeleteProjectModal.tsx +107 -0
  61. package/src/client/components/settings/categories/project-settings/DetailsForm.tsx +40 -24
  62. package/src/client/components/settings/categories/project-settings/DetailsHeader.tsx +17 -7
  63. package/src/client/components/settings/categories/project-settings/IconGrid.tsx +164 -69
  64. package/src/client/components/settings/categories/project-settings/ModelDropdown.test.tsx +122 -0
  65. package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +124 -53
  66. package/src/client/components/settings/categories/project-settings/NameInput.tsx +57 -11
  67. package/src/client/components/settings/categories/project-settings/PathField.tsx +122 -0
  68. package/src/client/components/settings/categories/project-settings/SidebarList.tsx +100 -59
  69. package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +253 -0
  70. package/src/client/components/settings/categories/skill-catalog/SkillCard.tsx +89 -0
  71. package/src/client/components/settings/categories/skill-catalog/SourceRail.tsx +122 -0
  72. package/src/client/components/settings/categories/skill-catalog/catalog-ui.test.tsx +179 -0
  73. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +208 -0
  74. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +137 -232
  75. package/src/client/components/settings/categories/skill-settings/InstructionsEditor.tsx +84 -0
  76. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +123 -87
  77. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +179 -0
  78. package/src/client/components/settings/categories/skill-settings/row-meta.ts +58 -0
  79. package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
  80. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +46 -0
  81. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +15 -6
  82. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +29 -0
  83. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +11 -3
  84. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +24 -1
  85. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +6 -2
  86. package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +18 -2
  87. package/src/client/components/workspace/editor/viewers/viewers.test.ts +39 -0
  88. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +18 -5
  89. package/src/client/components/workspace/file-explorer/Modals.tsx +15 -1
  90. package/src/client/components/workspace/file-explorer/RowLabel.tsx +68 -0
  91. package/src/client/components/workspace/file-explorer/TreeItem.tsx +47 -57
  92. package/src/client/components/workspace/file-explorer/collapsed-chain.test.ts +167 -0
  93. package/src/client/components/workspace/file-explorer/drag-props.ts +42 -0
  94. package/src/client/components/workspace/file-explorer/drag.test.ts +43 -0
  95. package/src/client/components/workspace/file-explorer/index.tsx +21 -20
  96. package/src/client/components/workspace/model-dropdown/Panel.tsx +7 -2
  97. package/src/client/components/workspace/model-dropdown/Section.test.tsx +13 -0
  98. package/src/client/components/workspace/model-dropdown/Section.tsx +5 -1
  99. package/src/client/components/workspace/panels/builtin.tsx +7 -0
  100. package/src/client/components/workspace/wiki-panel/NavModal.test.tsx +136 -0
  101. package/src/client/components/workspace/wiki-panel/NavModal.tsx +94 -0
  102. package/src/client/components/workspace/wiki-panel/PageView.tsx +16 -10
  103. package/src/client/components/workspace/wiki-panel/index.tsx +44 -9
  104. package/src/client/data/settings/omp-schema.json +91 -4
  105. package/src/client/data/settings/project.ts +9 -28
  106. package/src/client/data/settings/skill.ts +6 -32
  107. package/src/client/hooks/chat/timeline/pending-model.ts +28 -0
  108. package/src/client/hooks/settings/projects/index.ts +294 -0
  109. package/src/client/hooks/settings/projects.test.ts +237 -0
  110. package/src/client/hooks/settings/skill-catalog.ts +101 -9
  111. package/src/client/hooks/settings/skill-git-import.ts +153 -0
  112. package/src/client/hooks/shell/servers.test.ts +166 -0
  113. package/src/client/hooks/{desktop → shell}/servers.ts +17 -14
  114. package/src/client/hooks/ui/updates/shell-download.ts +1 -1
  115. package/src/client/hooks/ui/updates/shell-update.ts +2 -6
  116. package/src/client/hooks/workspace/file-row-drag.ts +41 -0
  117. package/src/client/hooks/workspace/file-tree-actions.ts +25 -1
  118. package/src/client/hooks/workspace/file-tree-edits.ts +23 -6
  119. package/src/client/hooks/workspace/root-drop-target.ts +77 -0
  120. package/src/client/hooks/workspace/unfolded-chains.ts +165 -0
  121. package/src/client/lib/desktop/dropped-paths.ts +1 -1
  122. package/src/client/lib/desktop/titlebar.test.ts +12 -3
  123. package/src/client/lib/desktop/titlebar.ts +1 -1
  124. package/src/client/lib/shell/desktop.ts +117 -0
  125. package/src/client/lib/shell/servers.ts +75 -0
  126. package/src/client/lib/shell/transport.ts +216 -0
  127. package/src/client/main.tsx +9 -0
  128. package/src/server/lib/db/schema.ts +11 -0
  129. package/src/server/lib/fs/git-merge-conflict.test.ts +14 -1
  130. package/src/server/lib/lifecycle/memory.test.ts +41 -1
  131. package/src/server/lib/lifecycle/memory.ts +131 -14
  132. package/src/server/lib/omp/config/skill-sources.ts +49 -0
  133. package/src/server/lib/omp/config/skills-git-install.ts +155 -0
  134. package/src/server/lib/omp/config/skills-git-repo.ts +288 -0
  135. package/src/server/lib/omp/config/skills-git.test.ts +220 -0
  136. package/src/server/lib/omp/session/subagent-presence-scan.test.ts +137 -0
  137. package/src/server/lib/omp/session/subagent-presence-scan.ts +120 -0
  138. package/src/server/lib/omp/session/subagent-presence-store.test.ts +120 -0
  139. package/src/server/lib/omp/session/subagent-presence-store.ts +65 -0
  140. package/src/server/lib/omp/session/subagent-presence.ts +52 -15
  141. package/src/server/lib/workspace/project-model.server.test.ts +102 -0
  142. package/src/server/lib/workspace/project-model.server.ts +47 -0
  143. package/src/server/lib/workspace/project-patch.server.ts +156 -0
  144. package/src/server/routes/agent/new.ts +8 -1
  145. package/src/server/routes/settings/agents.ts +19 -7
  146. package/src/server/routes/settings/projects.ts +53 -19
  147. package/src/server/routes/settings/settings-projects-routes.test.ts +214 -0
  148. package/src/server/routes/settings/settings-store-routes.test.ts +5 -2
  149. package/src/server/routes/settings/skills-catalog-actions.ts +195 -0
  150. package/src/server/routes/settings/skills.test.ts +225 -0
  151. package/src/server/routes/settings/skills.ts +18 -15
  152. package/src/shared/lib/fs/folder-chain.test.ts +81 -1
  153. package/src/shared/lib/fs/folder-chain.ts +84 -0
  154. package/src/shared/lib/omp/config/schema.test.ts +35 -0
  155. package/src/shared/lib/omp/session/job-progress.test.ts +37 -1
  156. package/src/shared/lib/omp/session/job-progress.ts +31 -0
  157. package/src/shared/lib/omp/session/proc.ts +5 -0
  158. package/src/shared/lib/omp/session/wait.ts +5 -0
  159. package/src/shared/lib/ui/mobile-overlay.ts +61 -0
  160. package/src/shared/lib/ui/svg-scope.test.ts +97 -0
  161. package/src/shared/lib/ui/svg-scope.ts +134 -0
  162. package/src/shared/lib/workspace/project-accent.test.ts +69 -0
  163. package/src/shared/lib/workspace/project-accent.ts +63 -0
  164. package/src/shared/lib/workspace/project-icon.ts +40 -0
  165. package/src/shared/lib/workspace/project-model.test.ts +79 -0
  166. package/src/shared/lib/workspace/project-model.ts +64 -0
  167. package/src/shared/types/settings/skill.ts +53 -3
  168. package/src/test-support/file-explorer-disk.test-util.ts +25 -1
  169. package/src/test-support/file-explorer-drag.test-util.ts +88 -0
  170. package/src/test-support/file-explorer.test-util.ts +47 -47
  171. package/dist/client/static/js/index-28pwtt69.css +0 -1
  172. package/src/client/components/common/code-surface/indent-guide.ts +0 -104
  173. package/src/client/components/settings/categories/skill-catalog/AddSourceModal.tsx +0 -133
  174. package/src/client/hooks/desktop/servers.test.ts +0 -73
  175. package/src/client/lib/desktop/bridge.ts +0 -203
  176. package/src/shared/lib/code/editor/indent-guide-rule.test.ts +0 -65
  177. package/src/shared/lib/code/editor/indent-guide-rule.ts +0 -47
@@ -0,0 +1,153 @@
1
+ import { useCallback, useState } from 'preact/hooks';
2
+ import type { GitRepoInspection, GitSkillEntry, GitSkillInstallMode, GitSkillInstallResult } from '@/shared/types';
3
+
4
+ export interface GitImportState {
5
+ inspecting: boolean;
6
+ installing: boolean;
7
+ /** The repository as the last successful inspection named it. */
8
+ repo: string | null;
9
+ url: string;
10
+ skills: GitSkillEntry[];
11
+ notes: string[];
12
+ /** Repo-relative paths the user ticked. */
13
+ selected: string[];
14
+ mode: GitSkillInstallMode;
15
+ overwrite: boolean;
16
+ error: string | null;
17
+ result: GitSkillInstallResult | null;
18
+ }
19
+
20
+ export interface GitImportController extends GitImportState {
21
+ inspect: (url: string) => Promise<void>;
22
+ toggle: (path: string) => void;
23
+ toggleAll: (select: boolean) => void;
24
+ setMode: (mode: GitSkillInstallMode) => void;
25
+ setOverwrite: (overwrite: boolean) => void;
26
+ install: () => Promise<GitSkillInstallResult | null>;
27
+ reset: () => void;
28
+ }
29
+
30
+ const INITIAL: GitImportState = {
31
+ inspecting: false,
32
+ installing: false,
33
+ repo: null,
34
+ url: '',
35
+ skills: [],
36
+ notes: [],
37
+ selected: [],
38
+ mode: 'managed_copy',
39
+ overwrite: false,
40
+ error: null,
41
+ result: null,
42
+ };
43
+
44
+ async function post<T>(body: unknown): Promise<T> {
45
+ const response = await fetch('/api/settings/skills', {
46
+ method: 'POST',
47
+ headers: { 'Content-Type': 'application/json' },
48
+ body: JSON.stringify(body),
49
+ });
50
+ const data = (await response.json().catch(() => ({}))) as T & { error?: string };
51
+ if (!response.ok || data.error) throw new Error(data.error || `Request failed (${response.status})`);
52
+ return data;
53
+ }
54
+
55
+ /**
56
+ * The From-Git pane's state machine: inspect a repository, pick skills, install.
57
+ *
58
+ * Every entry starts TICKED except the ones the server already reported as
59
+ * installed or unloadable — the common case is "install everything in this
60
+ * repository", and a row that would be skipped anyway is better pre-unticked than
61
+ * reported as a failure after the click.
62
+ *
63
+ * `install` never clears `result`: the dialog renders the outcome (installed and
64
+ * skipped, with the server's reason per row) instead of a toast that closes the
65
+ * only place the reasons could be read.
66
+ */
67
+ export function useSkillGitImport(): GitImportController {
68
+ const [state, setState] = useState<GitImportState>(INITIAL);
69
+
70
+ const inspect = useCallback(async (url: string) => {
71
+ const trimmed = url.trim();
72
+ if (!trimmed) {
73
+ setState((prev) => ({ ...prev, error: 'Paste a repository URL first.' }));
74
+ return;
75
+ }
76
+ setState((prev) => ({ ...prev, inspecting: true, error: null, result: null, url: trimmed }));
77
+ try {
78
+ const inspection = await post<GitRepoInspection & { repo: string }>({ type: 'inspect_git_repo', url: trimmed });
79
+ const installable = inspection.skills.filter((skill) => skill.loadable && !skill.installed);
80
+ setState((prev) => ({
81
+ ...prev,
82
+ inspecting: false,
83
+ repo: inspection.repo,
84
+ url: trimmed,
85
+ skills: inspection.skills,
86
+ notes: inspection.notes ?? [],
87
+ selected: installable.map((skill) => skill.path),
88
+ }));
89
+ } catch (error) {
90
+ setState((prev) => ({
91
+ ...prev,
92
+ inspecting: false,
93
+ skills: [],
94
+ selected: [],
95
+ repo: null,
96
+ error: error instanceof Error ? error.message : String(error),
97
+ }));
98
+ }
99
+ }, []);
100
+
101
+ const toggle = useCallback((path: string) => {
102
+ setState((prev) => ({
103
+ ...prev,
104
+ selected: prev.selected.includes(path)
105
+ ? prev.selected.filter((entry) => entry !== path)
106
+ : [...prev.selected, path],
107
+ }));
108
+ }, []);
109
+
110
+ const toggleAll = useCallback((select: boolean) => {
111
+ setState((prev) => ({
112
+ ...prev,
113
+ selected: select
114
+ ? prev.skills.filter((skill) => skill.loadable && !skill.installed).map((skill) => skill.path)
115
+ : [],
116
+ }));
117
+ }, []);
118
+
119
+ const setMode = useCallback((mode: GitSkillInstallMode) => {
120
+ setState((prev) => ({ ...prev, mode }));
121
+ }, []);
122
+
123
+ const setOverwrite = useCallback((overwrite: boolean) => {
124
+ setState((prev) => ({ ...prev, overwrite }));
125
+ }, []);
126
+
127
+ const install = useCallback(async () => {
128
+ if (state.selected.length === 0 || !state.url) return null;
129
+ setState((prev) => ({ ...prev, installing: true, error: null, result: null }));
130
+ try {
131
+ const result = await post<GitSkillInstallResult>({
132
+ type: 'install_git_skills',
133
+ url: state.url,
134
+ paths: state.selected,
135
+ mode: state.mode,
136
+ overwrite: state.overwrite,
137
+ });
138
+ setState((prev) => ({ ...prev, installing: false, result }));
139
+ return result;
140
+ } catch (error) {
141
+ setState((prev) => ({
142
+ ...prev,
143
+ installing: false,
144
+ error: error instanceof Error ? error.message : String(error),
145
+ }));
146
+ return null;
147
+ }
148
+ }, [state.selected, state.url, state.mode, state.overwrite]);
149
+
150
+ const reset = useCallback(() => setState(INITIAL), []);
151
+
152
+ return { ...state, inspect, toggle, toggleAll, setMode, setOverwrite, install, reset };
153
+ }
@@ -0,0 +1,166 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The shell bridge, driven through three different transports.
8
+ *
9
+ * The interesting failures are about what the page can tell apart:
10
+ *
11
+ * 1. a browser has no shell at all, and every command refuses;
12
+ * 2. a desktop shell installs `__kabmoCall` itself, and answers on the first
13
+ * paint (`__kabmoDesktop`);
14
+ * 3. a PHONE exposes only a host object, so the console adapts it — and that
15
+ * adapter must be distinguishable from a desktop, because the titlebar inset
16
+ * treats "a shell with no identity" as a macOS window.
17
+ *
18
+ * None of it is visible in the panel's markup: a control that never works looks
19
+ * exactly like one that does until it is pressed.
20
+ */
21
+
22
+ import { beforeEach, describe, expect, test } from 'bun:test';
23
+ import { desktopInfo } from '@/client/lib/shell/desktop';
24
+ import { addRemoteServer, readServers } from '@/client/lib/shell/servers';
25
+ import {
26
+ bridgeError,
27
+ hasShellBridge,
28
+ installShellTransport,
29
+ isDesktopShell,
30
+ isMobileShell,
31
+ shellHost,
32
+ } from '@/client/lib/shell/transport';
33
+
34
+ type Reply = (id: number, ok: boolean, payload: unknown) => void;
35
+
36
+ interface ShellWindow {
37
+ __kabmoCall?: (method: string, params?: Record<string, unknown>) => Promise<unknown>;
38
+ __kabmoDesktop?: unknown;
39
+ __kabmoReply?: Reply;
40
+ __kabmoShellHost?: 'android' | 'ios';
41
+ kabmoHost?: { post: (method: string, id: string, params: string) => void };
42
+ webkit?: { messageHandlers?: { kabmo?: { postMessage: (message: unknown) => void } } };
43
+ }
44
+
45
+ const shell = () => globalThis as unknown as { window?: ShellWindow };
46
+
47
+ describe('shell bridge', () => {
48
+ beforeEach(() => {
49
+ delete shell().window;
50
+ });
51
+
52
+ test('a browser has no shell, and every call refuses', async () => {
53
+ shell().window = {};
54
+ expect(shellHost()).toBeNull();
55
+ expect(hasShellBridge()).toBe(false);
56
+ expect(isDesktopShell()).toBe(false);
57
+ expect(isMobileShell()).toBe(false);
58
+ expect(await desktopInfo()).toBeNull();
59
+ await expect(readServers()).rejects.toThrow('Not running inside a Kabmo shell.');
60
+ });
61
+
62
+ test('the injected identity is readable before any command runs', async () => {
63
+ shell().window = {
64
+ __kabmoCall: async () => null,
65
+ __kabmoDesktop: { platform: 'macos', shellVersion: '0.1.0', overlayTitlebar: true, trafficLightInset: '5rem' },
66
+ };
67
+ expect(isDesktopShell()).toBe(true);
68
+ expect(isMobileShell()).toBe(false);
69
+ const info = await desktopInfo();
70
+ expect(info?.overlayTitlebar).toBe(true);
71
+ expect(info?.trafficLightInset).toBe('5rem');
72
+ });
73
+
74
+ /**
75
+ * macOS and Linux post over `window.webkit.messageHandlers.kabmo` — the same
76
+ * handler NAME iOS uses — so "is there a WebKit handler?" cannot decide which
77
+ * shell this is. When it did, `isDesktopShell()` answered false in every macOS
78
+ * window, `titlebarInsetLeft` stopped reserving the 5rem for the traffic
79
+ * lights, and the wordmark was drawn under close / minimise / maximise.
80
+ */
81
+ test('a macOS shell is not read as an iPhone, though it posts over the same handler', () => {
82
+ shell().window = {
83
+ __kabmoCall: async () => null,
84
+ __kabmoDesktop: { platform: 'macos', shellVersion: '0.1.0', overlayTitlebar: true, trafficLightInset: '5rem' },
85
+ webkit: { messageHandlers: { kabmo: { postMessage: () => {} } } },
86
+ };
87
+ expect(shellHost()).toBe('desktop');
88
+ expect(isDesktopShell()).toBe(true);
89
+ expect(isMobileShell()).toBe(false);
90
+ });
91
+
92
+ test('a command answers through __kabmoCall', async () => {
93
+ const seen: string[] = [];
94
+ shell().window = {
95
+ __kabmoCall: async (method) => {
96
+ seen.push(method);
97
+ return { entries: [], detected: [], activeId: 'local:1' };
98
+ },
99
+ };
100
+ const state = await readServers();
101
+ expect(seen).toEqual(['servers_state']);
102
+ expect(state.activeId).toBe('local:1');
103
+ });
104
+
105
+ /**
106
+ * The phone's transport is ADAPTED, not replaced: the native side gets
107
+ * `(method, id, params)` and answers by evaluating `__kabmoReply`, exactly as
108
+ * the desktop shells do. Params are form-encoded because Android's `org.json`
109
+ * is a stub in a JVM unit test, and state comes back as JSON text.
110
+ */
111
+ test('an Android host becomes __kabmoCall, with form-encoded params and JSON text back', async () => {
112
+ const posts: Array<{ method: string; id: string; params: string }> = [];
113
+ shell().window = {
114
+ kabmoHost: {
115
+ post: (method, id, params) => {
116
+ posts.push({ method, id, params });
117
+ // Answer the way the native side does: a JSON TEXT payload, on the
118
+ // next microtask rather than a real timer.
119
+ queueMicrotask(() => {
120
+ shell().window?.__kabmoReply?.(Number(id), true, '{"entries":[],"detected":[],"activeUrl":"http://10.0.0.2:3000"}');
121
+ });
122
+ },
123
+ },
124
+ };
125
+ installShellTransport();
126
+ expect(isMobileShell()).toBe(true);
127
+ // The distinction that matters: a phone is NOT a desktop, or the header
128
+ // would reserve 5rem for traffic lights it does not have.
129
+ expect(isDesktopShell()).toBe(false);
130
+ expect(hasShellBridge()).toBe(true);
131
+
132
+ const state = await addRemoteServer('NAS', 'http://10.0.0.2:3000');
133
+ expect(state.activeUrl).toBe('http://10.0.0.2:3000');
134
+ expect(posts).toHaveLength(1);
135
+ expect(posts[0].method).toBe('servers_add');
136
+ expect(posts[0].params).toBe('label=NAS&url=http%3A%2F%2F10.0.0.2%3A3000');
137
+ });
138
+
139
+ test('an iOS host posts to the WebKit message handler', async () => {
140
+ const posts: unknown[] = [];
141
+ shell().window = {
142
+ webkit: {
143
+ messageHandlers: {
144
+ kabmo: {
145
+ postMessage: (message) => {
146
+ posts.push(message);
147
+ const { id } = message as { id: number };
148
+ queueMicrotask(() => shell().window?.__kabmoReply?.(id, true, '{"entries":[],"detected":[]}'));
149
+ },
150
+ },
151
+ },
152
+ },
153
+ };
154
+ installShellTransport();
155
+ expect(isMobileShell()).toBe(true);
156
+ await readServers();
157
+ expect(posts).toEqual([{ id: 1, method: 'servers_state', params: '' }]);
158
+ });
159
+
160
+ test('a refusal keeps the shell’s own sentence, unstripped', async () => {
161
+ expect(bridgeError(new Error('Use the server’s root address — a base path is not supported.'))).toBe(
162
+ 'Use the server’s root address — a base path is not supported.',
163
+ );
164
+ expect(bridgeError('plain')).toBe('plain');
165
+ });
166
+ });
@@ -4,35 +4,38 @@
4
4
  */
5
5
 
6
6
  /**
7
- * The server list the desktop shell owns, as the navbar reads it.
7
+ * The server list the SHELL owns, as the console reads it.
8
8
  *
9
- * One store per window, not per component: the navbar button, its popover and
10
- * anything else that asks "which server am I on" must not each hold a copy —
11
- * two copies is how a start on one side leaves the other showing `Stopped`.
9
+ * One store per window, not per component: the navbar chip, the phone drawer's
10
+ * chip, the popover and anything else that asks "which server am I on" must not
11
+ * each hold a copy — two copies is how a start on one side leaves the other
12
+ * showing `Stopped`.
12
13
  *
13
14
  * Every mutation answers with the WHOLE state (`ServersState`), and the shell is
14
15
  * the source of truth: it re-reads its own list, re-probes every URL and
15
16
  * re-discovers local instances before answering. Adopting the response verbatim
16
17
  * is what keeps the panel from inventing a running state the shell does not
17
18
  * agree with.
19
+ *
20
+ * `available` is `hasShellBridge()` and not `isDesktopShell()`: a phone answers
21
+ * the same four commands the desktop shells do, so it must get the same control.
18
22
  */
19
23
 
20
24
  import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
21
25
  import {
22
26
  activateServer,
23
27
  addRemoteServer,
24
- bridgeError,
25
- isDesktopShell,
26
28
  readServers,
27
29
  removeServer,
28
30
  startLocalServer,
29
31
  stopLocalServer,
30
- type DesktopServersState,
31
- } from '@/client/lib/desktop/bridge';
32
+ type ShellServersState,
33
+ } from '@/client/lib/shell/servers';
34
+ import { bridgeError, hasShellBridge } from '@/client/lib/shell/transport';
32
35
 
33
- export interface DesktopServersStore {
36
+ export interface ShellServersStore {
34
37
  available: boolean;
35
- state: DesktopServersState | null;
38
+ state: ShellServersState | null;
36
39
  /** A request is in flight; the panel disables its controls rather than queueing. */
37
40
  busy: boolean;
38
41
  error: string | null;
@@ -55,9 +58,9 @@ export interface DesktopServersStore {
55
58
  */
56
59
  const REFRESH_INTERVAL_MS = 4000;
57
60
 
58
- export function useDesktopServers(open: boolean): DesktopServersStore {
59
- const available = isDesktopShell();
60
- const [state, setState] = useState<DesktopServersState | null>(null);
61
+ export function useShellServers(open: boolean): ShellServersStore {
62
+ const available = hasShellBridge();
63
+ const [state, setState] = useState<ShellServersState | null>(null);
61
64
  const [busy, setBusy] = useState(false);
62
65
  const [error, setError] = useState<string | null>(null);
63
66
  // A mutation and a poll can overlap; the poll must not overwrite the answer
@@ -76,7 +79,7 @@ export function useDesktopServers(open: boolean): DesktopServersStore {
76
79
  }, [available]);
77
80
 
78
81
  const run = useCallback(
79
- async (action: () => Promise<DesktopServersState>) => {
82
+ async (action: () => Promise<ShellServersState>) => {
80
83
  mutationsRef.current += 1;
81
84
  setBusy(true);
82
85
  setError(null);
@@ -283,7 +283,7 @@ export interface DesktopIdentity {
283
283
 
284
284
  function readDesktopIdentity(): DesktopIdentity | null {
285
285
  if (typeof window === 'undefined') return null;
286
- // `window.__kabmoDesktop` is declared by `lib/desktop/bridge` — the same
286
+ // `window.__kabmoDesktop` is declared by `lib/shell/desktop` — the same
287
287
  // object the shell injects, so this reads the shell's own contract rather
288
288
  // than re-declaring its shape here.
289
289
  return window.__kabmoDesktop ?? null;
@@ -30,12 +30,8 @@
30
30
  */
31
31
 
32
32
  import { useCallback, useRef, useState } from 'preact/hooks';
33
- import {
34
- applyShellUpdate,
35
- bridgeError,
36
- isDesktopShell,
37
- type ShellUpdateOutcome,
38
- } from '@/client/lib/desktop/bridge';
33
+ import { applyShellUpdate, type ShellUpdateOutcome } from '@/client/lib/shell/desktop';
34
+ import { bridgeError, isDesktopShell } from '@/client/lib/shell/transport';
39
35
  import type { ShellDownload } from '@/client/hooks/ui/updates/shell-download';
40
36
 
41
37
  /** What the control is doing right now. */
@@ -26,6 +26,7 @@
26
26
  * onto the folder it already sits in would move it out.
27
27
  */
28
28
 
29
+ import { useEffect, useState } from 'preact/hooks';
29
30
  import type { TargetedDragEvent } from 'preact';
30
31
  import type { ClipboardTarget, FileClipboard } from '@/client/hooks/workspace/file-clipboard';
31
32
 
@@ -40,6 +41,15 @@ export interface FileRowDragOptions {
40
41
  onDragStart: (target: ClipboardTarget) => void;
41
42
  onDragEnd: () => void;
42
43
  onDropOn: (target: ClipboardTarget) => void;
44
+ /**
45
+ * The drag has been hovering this row and this row would accept it.
46
+ *
47
+ * What makes a COLLAPSED CHAIN reachable: `dev/src/main/code` is one row, so
48
+ * the levels inside its label are not drop targets at all and a drop lands in
49
+ * the deepest directory. The panel unfolds the row when this fires, which
50
+ * turns each level into a row of its own before the user lets go.
51
+ */
52
+ onHoverAccept?: (target: ClipboardTarget) => void;
43
53
  }
44
54
 
45
55
  export interface FileRowDrag {
@@ -47,9 +57,20 @@ export interface FileRowDrag {
47
57
  isDragging: boolean;
48
58
  /** True while this row would accept the drag in flight. */
49
59
  acceptsDrop: boolean;
60
+ /**
61
+ * True only while the pointer is OVER this row AND it would accept the drag.
62
+ *
63
+ * Deliberately not `acceptsDrop`: that one is a CAPABILITY ("a drop here would
64
+ * be legal"), so styling it highlighted every on-screen folder and file the
65
+ * instant a drag started — measured, dragging `a.ts` over a tree of `b` and
66
+ * `c` painted BOTH rows' `bg-info` blocks. A highlight is a promise about the
67
+ * drop the pointer is on, so it has to be driven by the pointer.
68
+ */
69
+ isDropHovered: boolean;
50
70
  onDragStart: (e: TargetedDragEvent<HTMLElement>) => void;
51
71
  onDragEnd: () => void;
52
72
  onDragOver: (e: TargetedDragEvent<HTMLElement>) => void;
73
+ onDragLeave: () => void;
53
74
  onDrop: (e: TargetedDragEvent<HTMLElement>) => void;
54
75
  }
55
76
 
@@ -60,13 +81,27 @@ export function useFileRowDrag({
60
81
  onDragStart,
61
82
  onDragEnd,
62
83
  onDropOn,
84
+ onHoverAccept,
63
85
  }: FileRowDragOptions): FileRowDrag {
64
86
  const isDragging = dragging?.path === target.path;
65
87
  const acceptsDrop = Boolean(dragging) && !isDragging && clipboard.moveRefusalFor(dragging!, target) === null;
88
+ /**
89
+ * The row the pointer is over, owned here rather than by the panel: `dragover`
90
+ * and `dragleave` are per row, and a row that could not leave its own state
91
+ * would stay highlighted after the pointer moved on.
92
+ */
93
+ const [hovered, setHovered] = useState(false);
94
+ // A drag that ENDED (dropped, cancelled, or left the window) leaves no row
95
+ // hovering: `dragleave` is not guaranteed for the row the drop happened on.
96
+ useEffect(() => {
97
+ if (!dragging) setHovered(false);
98
+ }, [dragging]);
99
+ const isDropHovered = hovered && acceptsDrop;
66
100
 
67
101
  return {
68
102
  isDragging,
69
103
  acceptsDrop,
104
+ isDropHovered,
70
105
  onDragStart: (e) => {
71
106
  // The tree's own payload is what a drop INSIDE the panel reads, and
72
107
  // `text/plain` carries the path so a drag out to another surface (a
@@ -83,10 +118,16 @@ export function useFileRowDrag({
83
118
  // Claimed even when refused — see the module doc: the background is the
84
119
  // root's target, and letting this bubble would move the entry there.
85
120
  e.stopPropagation();
121
+ setHovered(acceptsDrop);
86
122
  if (!acceptsDrop) return;
87
123
  e.preventDefault();
88
124
  if (e.dataTransfer) e.dataTransfer.dropEffect = 'move';
125
+ // Hovering an accepting row is the moment its hidden levels can be
126
+ // offered: `dragover` fires repeatedly and the panel's own set makes the
127
+ // repeat a no-op, so this is idempotent by construction.
128
+ onHoverAccept?.(target);
89
129
  },
130
+ onDragLeave: () => setHovered(false),
90
131
  onDrop: (e) => {
91
132
  if (!dragging) return;
92
133
  e.stopPropagation();
@@ -51,6 +51,16 @@ export interface FileActionDeps {
51
51
  onCreated?: (entry: CreatedEntry) => void;
52
52
  /** A row the panel just renamed, moved locally — same reason as `onCreated`. */
53
53
  onRenamed?: (fromPath: string, toPath: string) => void;
54
+ /**
55
+ * Split this row's collapsed chain into one row per directory.
56
+ *
57
+ * Present only where an unfold makes sense (a folder whose label names more
58
+ * than one directory); the menu row that calls it is drawn from the same
59
+ * condition, so a menu never offers an action the panel cannot perform.
60
+ */
61
+ onUnfold?: () => void;
62
+ /** Fold this row back into the one chain row it is listed as. */
63
+ onFold?: () => void;
54
64
  /** The panel's clipboard: Cut/Copy fill it, Paste reads it. */
55
65
  clipboard: FileClipboard;
56
66
  /** Whether this row is a folder — what Cut/Copy/Paste need to name their target. */
@@ -80,6 +90,14 @@ export interface FileActions {
80
90
  busy: boolean;
81
91
  /** Label of the row's Paste action, or null when a paste cannot land here. */
82
92
  pasteLabel: string | null;
93
+ /**
94
+ * True when the row's label names more than one directory — a collapsed
95
+ * chain, whose inner levels are not rows and therefore not renameable until
96
+ * it is unfolded.
97
+ */
98
+ chainLabel: boolean;
99
+ /** True when this row is an unfolded chain's outermost level, so it can fold. */
100
+ foldable: boolean;
83
101
  /** The fetcher's own state/data, for the history modal. */
84
102
  fetcherState: string;
85
103
  fetcherData: FsActionResponse | undefined;
@@ -93,7 +111,7 @@ export interface FileActions {
93
111
  closeHistory: () => void;
94
112
  }
95
113
 
96
- export function useFileActions({ file, diff, onOpenFile, onActionComplete, onCreated, onRenamed, clipboard, isFolder }: FileActionDeps): FileActions {
114
+ export function useFileActions({ file, diff, onOpenFile, onActionComplete, onCreated, onRenamed, onUnfold, onFold, clipboard, isFolder }: FileActionDeps): FileActions {
97
115
  const actionFetcher = useFetcher<FsActionResponse>();
98
116
  const [contextMenu, setContextMenu] = useState<{ x: number; y: number } | null>(null);
99
117
  const contextMenuRef = useRef<HTMLDivElement>(null);
@@ -212,6 +230,10 @@ export function useFileActions({ file, diff, onOpenFile, onActionComplete, onCre
212
230
  } else if (actionType === 'rename') {
213
231
  setRenameValue(file.path);
214
232
  setShowRenameModal(true);
233
+ } else if (actionType === 'unfold') {
234
+ onUnfold?.();
235
+ } else if (actionType === 'fold') {
236
+ onFold?.();
215
237
  } else if (actionType === 'new_file') {
216
238
  create.openDialog('file');
217
239
  } else if (actionType === 'new_folder') {
@@ -264,6 +286,8 @@ export function useFileActions({ file, diff, onOpenFile, onActionComplete, onCre
264
286
  renameError,
265
287
  busy: actionFetcher.state !== 'idle' || create.busy || clipboard.busy,
266
288
  pasteLabel,
289
+ chainLabel: onUnfold !== undefined,
290
+ foldable: onFold !== undefined,
267
291
  fetcherState: actionFetcher.state,
268
292
  fetcherData: actionFetcher.data,
269
293
  handleAction,
@@ -35,6 +35,14 @@ export interface FileTreeEditDeps {
35
35
  * the only honest way to learn where the row went.
36
36
  */
37
37
  reload: () => void;
38
+ /**
39
+ * A rename landed, in the panel's own coordinates.
40
+ *
41
+ * The listing re-keys its expansion set itself; this is for the OTHER
42
+ * per-path state a rename has to move with the row — the panel's unfolded
43
+ * chains. Absent means "nothing else remembers a path".
44
+ */
45
+ onMoved?: (fromPath: string, toPath: string) => void;
38
46
  }
39
47
 
40
48
  export interface FileTreeEdits {
@@ -49,6 +57,7 @@ export function useFileTreeEdits({
49
57
  setExpandedPaths,
50
58
  setStoredExpandedPaths,
51
59
  reload,
60
+ onMoved,
52
61
  }: FileTreeEditDeps): FileTreeEdits {
53
62
  /**
54
63
  * Open every folder row that leads to `path`.
@@ -82,22 +91,30 @@ export function useFileTreeEdits({
82
91
  * A folder's descendants and every open branch beneath it carry its path as a
83
92
  * prefix, so the expansion set is rekeyed in the same step — an open `src`
84
93
  * renamed to `lib` must stay open as `lib`, not collapse.
94
+ *
95
+ * The re-key runs BEFORE the local placement is attempted and whatever it
96
+ * answers: an unfolded chain row's inner levels are not in the tree's own
97
+ * coordinates, so a rename of one of them answers "not in this tree" and
98
+ * falls back to a reload — and the paths every other holder of this state
99
+ * remembers (the expansion set, the panel's unfolded chains) have still
100
+ * moved.
85
101
  */
86
102
  const moveRenamed = useCallback((fromPath: string, toPath: string) => {
87
- const tree = listing.moveEntry(fromPath, toPath);
88
- if (!tree) {
89
- reload();
90
- return;
91
- }
103
+ onMoved?.(fromPath, toPath);
92
104
  setExpandedPaths((prev) => {
93
105
  const next = rekeyExpansion(prev, fromPath, toPath);
94
106
  setStoredExpandedPaths(Array.from(next));
95
107
  return next;
96
108
  });
109
+ const tree = listing.moveEntry(fromPath, toPath);
110
+ if (!tree) {
111
+ reload();
112
+ return;
113
+ }
97
114
  // A rename INTO a new folder (`a.ts` → `nested/a.ts`) has the same problem a
98
115
  // nested create does: the destination folder is one nobody has opened.
99
116
  reveal(toPath, tree);
100
- }, [listing, reload, reveal, setExpandedPaths, setStoredExpandedPaths]);
117
+ }, [listing, reload, reveal, setExpandedPaths, setStoredExpandedPaths, onMoved]);
101
118
 
102
119
  return { insertCreated, moveRenamed };
103
120
  }