@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.
- package/README.md +3 -2
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +412 -394
- package/dist/client/static/js/index-3ve31rzx.css +1 -0
- package/dist/client/static/js/{index-mx658m43.js → index-rerjq5th.js} +846 -844
- package/marketplace/plugins/stats/README.md +27 -8
- package/marketplace/plugins/stats/package.json +2 -2
- package/marketplace/plugins/stats/src/HeaderReadout.test.tsx +2 -1
- package/marketplace/plugins/stats/src/HeaderReadout.tsx +6 -2
- package/marketplace/plugins/stats/src/KillConfirm.test.tsx +159 -0
- package/marketplace/plugins/stats/src/KillConfirm.tsx +145 -0
- package/marketplace/plugins/stats/src/ProcessTable.tsx +54 -8
- package/marketplace/plugins/stats/src/TotalsBar.test.tsx +5 -2
- package/marketplace/plugins/stats/src/TotalsBar.tsx +13 -3
- package/marketplace/plugins/stats/src/app.test.tsx +100 -4
- package/marketplace/plugins/stats/src/app.tsx +51 -4
- package/marketplace/plugins/stats/src/groups.test.ts +1 -1
- package/marketplace/plugins/stats/src/kill.test.ts +131 -0
- package/marketplace/plugins/stats/src/kill.ts +74 -0
- package/marketplace/plugins/stats/src/labels.test.ts +1 -0
- package/marketplace/plugins/stats/src/machine.test.ts +77 -0
- package/marketplace/plugins/stats/src/machine.ts +115 -0
- package/marketplace/plugins/stats/src/proc/darwin.ts +38 -0
- package/marketplace/plugins/stats/src/proc/linux.ts +4 -0
- package/marketplace/plugins/stats/src/proc/ps.ts +1 -0
- package/marketplace/plugins/stats/src/proc/types.ts +11 -0
- package/marketplace/plugins/stats/src/sampler.test.ts +42 -4
- package/marketplace/plugins/stats/src/sampler.ts +32 -18
- package/marketplace/plugins/stats/src/server.ts +29 -2
- package/marketplace/plugins/stats/src/snapshot.ts +31 -3
- package/package.json +3 -2
- package/src/client/components/common/Modal.tsx +7 -0
- package/src/client/components/common/code-surface/bracket-guide.test.ts +2 -2
- package/src/client/components/common/code-surface/bracket-guide.ts +2 -2
- package/src/client/components/common/code-surface/conflict-markers.ts +5 -5
- package/src/client/components/common/code-surface/extensions.ts +7 -4
- package/src/client/components/common/code-surface/theme.ts +34 -9
- package/src/client/components/common/code-surface/whitespace.test.ts +223 -0
- package/src/client/components/common/code-surface/whitespace.ts +140 -0
- package/src/client/components/common/{server-switcher/index.tsx → server-control/Panel.tsx} +73 -35
- package/src/client/components/common/{server-switcher → server-control}/index.test.tsx +98 -37
- package/src/client/components/common/server-control/index.tsx +118 -0
- package/src/client/components/layout/LeftDock.tsx +1 -0
- package/src/client/components/layout/desktop-layout/TopNavbar.tsx +8 -50
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +1 -0
- package/src/client/components/mobile/RightSidebar.tsx +1 -0
- package/src/client/components/mobile/mobile-main-view/Header.tsx +6 -12
- package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +41 -13
- package/src/client/components/mobile/mobile-session-sidebar/use-dock.ts +1 -0
- package/src/client/components/settings/Modal.tsx +9 -3
- package/src/client/components/settings/ProjectSelectorDropdown.tsx +19 -9
- package/src/client/components/settings/categories/AgentSettings.tsx +27 -6
- package/src/client/components/settings/categories/ProjectSettings.tsx +122 -156
- package/src/client/components/settings/categories/SkillCatalogSettings.tsx +220 -260
- package/src/client/components/settings/categories/SkillSettings.tsx +6 -3
- package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +5 -0
- package/src/client/components/settings/categories/project-settings/AccentPalette.test.tsx +189 -0
- package/src/client/components/settings/categories/project-settings/AccentPalette.tsx +156 -24
- package/src/client/components/settings/categories/project-settings/AddProjectModal.tsx +175 -0
- package/src/client/components/settings/categories/project-settings/DeleteProjectModal.tsx +107 -0
- package/src/client/components/settings/categories/project-settings/DetailsForm.tsx +40 -24
- package/src/client/components/settings/categories/project-settings/DetailsHeader.tsx +17 -7
- package/src/client/components/settings/categories/project-settings/IconGrid.tsx +164 -69
- package/src/client/components/settings/categories/project-settings/ModelDropdown.test.tsx +122 -0
- package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +124 -53
- package/src/client/components/settings/categories/project-settings/NameInput.tsx +57 -11
- package/src/client/components/settings/categories/project-settings/PathField.tsx +122 -0
- package/src/client/components/settings/categories/project-settings/SidebarList.tsx +100 -59
- package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +253 -0
- package/src/client/components/settings/categories/skill-catalog/SkillCard.tsx +89 -0
- package/src/client/components/settings/categories/skill-catalog/SourceRail.tsx +122 -0
- package/src/client/components/settings/categories/skill-catalog/catalog-ui.test.tsx +179 -0
- package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +208 -0
- package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +137 -232
- package/src/client/components/settings/categories/skill-settings/InstructionsEditor.tsx +84 -0
- package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +123 -87
- package/src/client/components/settings/categories/skill-settings/pane.test.tsx +179 -0
- package/src/client/components/settings/categories/skill-settings/row-meta.ts +58 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +46 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +15 -6
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +29 -0
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +11 -3
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +24 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +6 -2
- package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +18 -2
- package/src/client/components/workspace/editor/viewers/viewers.test.ts +39 -0
- package/src/client/components/workspace/file-explorer/ContextMenu.tsx +18 -5
- package/src/client/components/workspace/file-explorer/Modals.tsx +15 -1
- package/src/client/components/workspace/file-explorer/RowLabel.tsx +68 -0
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +47 -57
- package/src/client/components/workspace/file-explorer/collapsed-chain.test.ts +167 -0
- package/src/client/components/workspace/file-explorer/drag-props.ts +42 -0
- package/src/client/components/workspace/file-explorer/drag.test.ts +43 -0
- package/src/client/components/workspace/file-explorer/index.tsx +21 -20
- package/src/client/components/workspace/model-dropdown/Panel.tsx +7 -2
- package/src/client/components/workspace/model-dropdown/Section.test.tsx +13 -0
- package/src/client/components/workspace/model-dropdown/Section.tsx +5 -1
- package/src/client/components/workspace/panels/builtin.tsx +7 -0
- package/src/client/components/workspace/wiki-panel/NavModal.test.tsx +136 -0
- package/src/client/components/workspace/wiki-panel/NavModal.tsx +94 -0
- package/src/client/components/workspace/wiki-panel/PageView.tsx +16 -10
- package/src/client/components/workspace/wiki-panel/index.tsx +44 -9
- package/src/client/data/settings/omp-schema.json +91 -4
- package/src/client/data/settings/project.ts +9 -28
- package/src/client/data/settings/skill.ts +6 -32
- package/src/client/hooks/chat/timeline/pending-model.ts +28 -0
- package/src/client/hooks/settings/projects/index.ts +294 -0
- package/src/client/hooks/settings/projects.test.ts +237 -0
- package/src/client/hooks/settings/skill-catalog.ts +101 -9
- package/src/client/hooks/settings/skill-git-import.ts +153 -0
- package/src/client/hooks/shell/servers.test.ts +166 -0
- package/src/client/hooks/{desktop → shell}/servers.ts +17 -14
- package/src/client/hooks/ui/updates/shell-download.ts +1 -1
- package/src/client/hooks/ui/updates/shell-update.ts +2 -6
- package/src/client/hooks/workspace/file-row-drag.ts +41 -0
- package/src/client/hooks/workspace/file-tree-actions.ts +25 -1
- package/src/client/hooks/workspace/file-tree-edits.ts +23 -6
- package/src/client/hooks/workspace/root-drop-target.ts +77 -0
- package/src/client/hooks/workspace/unfolded-chains.ts +165 -0
- package/src/client/lib/desktop/dropped-paths.ts +1 -1
- package/src/client/lib/desktop/titlebar.test.ts +12 -3
- package/src/client/lib/desktop/titlebar.ts +1 -1
- package/src/client/lib/shell/desktop.ts +117 -0
- package/src/client/lib/shell/servers.ts +75 -0
- package/src/client/lib/shell/transport.ts +216 -0
- package/src/client/main.tsx +9 -0
- package/src/server/lib/db/schema.ts +11 -0
- package/src/server/lib/fs/git-merge-conflict.test.ts +14 -1
- package/src/server/lib/lifecycle/memory.test.ts +41 -1
- package/src/server/lib/lifecycle/memory.ts +131 -14
- package/src/server/lib/omp/config/skill-sources.ts +49 -0
- package/src/server/lib/omp/config/skills-git-install.ts +155 -0
- package/src/server/lib/omp/config/skills-git-repo.ts +288 -0
- package/src/server/lib/omp/config/skills-git.test.ts +220 -0
- package/src/server/lib/omp/session/subagent-presence-scan.test.ts +137 -0
- package/src/server/lib/omp/session/subagent-presence-scan.ts +120 -0
- package/src/server/lib/omp/session/subagent-presence-store.test.ts +120 -0
- package/src/server/lib/omp/session/subagent-presence-store.ts +65 -0
- package/src/server/lib/omp/session/subagent-presence.ts +52 -15
- package/src/server/lib/workspace/project-model.server.test.ts +102 -0
- package/src/server/lib/workspace/project-model.server.ts +47 -0
- package/src/server/lib/workspace/project-patch.server.ts +156 -0
- package/src/server/routes/agent/new.ts +8 -1
- package/src/server/routes/settings/agents.ts +19 -7
- package/src/server/routes/settings/projects.ts +53 -19
- package/src/server/routes/settings/settings-projects-routes.test.ts +214 -0
- package/src/server/routes/settings/settings-store-routes.test.ts +5 -2
- package/src/server/routes/settings/skills-catalog-actions.ts +195 -0
- package/src/server/routes/settings/skills.test.ts +225 -0
- package/src/server/routes/settings/skills.ts +18 -15
- package/src/shared/lib/fs/folder-chain.test.ts +81 -1
- package/src/shared/lib/fs/folder-chain.ts +84 -0
- package/src/shared/lib/omp/config/schema.test.ts +35 -0
- package/src/shared/lib/omp/session/job-progress.test.ts +37 -1
- package/src/shared/lib/omp/session/job-progress.ts +31 -0
- package/src/shared/lib/omp/session/proc.ts +5 -0
- package/src/shared/lib/omp/session/wait.ts +5 -0
- package/src/shared/lib/ui/mobile-overlay.ts +61 -0
- package/src/shared/lib/ui/svg-scope.test.ts +97 -0
- package/src/shared/lib/ui/svg-scope.ts +134 -0
- package/src/shared/lib/workspace/project-accent.test.ts +69 -0
- package/src/shared/lib/workspace/project-accent.ts +63 -0
- package/src/shared/lib/workspace/project-icon.ts +40 -0
- package/src/shared/lib/workspace/project-model.test.ts +79 -0
- package/src/shared/lib/workspace/project-model.ts +64 -0
- package/src/shared/types/settings/skill.ts +53 -3
- package/src/test-support/file-explorer-disk.test-util.ts +25 -1
- package/src/test-support/file-explorer-drag.test-util.ts +88 -0
- package/src/test-support/file-explorer.test-util.ts +47 -47
- package/dist/client/static/js/index-28pwtt69.css +0 -1
- package/src/client/components/common/code-surface/indent-guide.ts +0 -104
- package/src/client/components/settings/categories/skill-catalog/AddSourceModal.tsx +0 -133
- package/src/client/hooks/desktop/servers.test.ts +0 -73
- package/src/client/lib/desktop/bridge.ts +0 -203
- package/src/shared/lib/code/editor/indent-guide-rule.test.ts +0 -65
- package/src/shared/lib/code/editor/indent-guide-rule.ts +0 -47
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whitespace marks, through the REAL surface stack.
|
|
8
|
+
*
|
|
9
|
+
* Pins what makes this feature different from both alternatives, and each case
|
|
10
|
+
* is one a naive version gets wrong:
|
|
11
|
+
*
|
|
12
|
+
* - **A bare caret paints nothing.** The package's `highlightWhitespace()` marks
|
|
13
|
+
* every space in the viewport and a leading-run version marks every block's
|
|
14
|
+
* indentation; both look identical to this one as soon as text is selected,
|
|
15
|
+
* so the CARET case is the only one that tells them apart.
|
|
16
|
+
* - **Only the selected characters are marked**, so a selection that stops
|
|
17
|
+
* mid-line marks the part it covers and nothing past it.
|
|
18
|
+
* - **Collapsing the selection clears the marks.** They are a function of the
|
|
19
|
+
* selection, so a missing rebuild leaves the last painted set on screen.
|
|
20
|
+
*
|
|
21
|
+
* The marks exist only once a view mounts (a `ViewPlugin`), which is why every
|
|
22
|
+
* case here mounts one; `whitespaceDecorations` is also driven directly, so the
|
|
23
|
+
* rules are asserted without depending on the DOM.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
27
|
+
import { Window } from 'happy-dom';
|
|
28
|
+
import { Compartment, EditorState } from '@codemirror/state';
|
|
29
|
+
import { EditorView } from '@codemirror/view';
|
|
30
|
+
|
|
31
|
+
import { surfaceExtensions } from '@/client/components/common/code-surface/extensions';
|
|
32
|
+
import { whitespaceDecorations } from '@/client/components/common/code-surface/whitespace';
|
|
33
|
+
import { SHIKI_THEMES } from '@/shared/lib/code/shiki-themes';
|
|
34
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
35
|
+
|
|
36
|
+
const EXTRA_GLOBALS = ['MutationObserver', 'requestAnimationFrame', 'cancelAnimationFrame'] as const;
|
|
37
|
+
const native: Partial<Record<(typeof EXTRA_GLOBALS)[number], unknown>> = {};
|
|
38
|
+
|
|
39
|
+
let host: HTMLElement;
|
|
40
|
+
|
|
41
|
+
beforeAll(() => {
|
|
42
|
+
const win = new Window({ url: 'http://localhost' });
|
|
43
|
+
installDomGlobals(win);
|
|
44
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
45
|
+
for (const key of EXTRA_GLOBALS) {
|
|
46
|
+
native[key] = target[key];
|
|
47
|
+
target[key] = (win as unknown as Record<string, unknown>)[key];
|
|
48
|
+
}
|
|
49
|
+
host = document.body.appendChild(document.createElement('div'));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterAll(() => {
|
|
53
|
+
const target = globalThis as unknown as Record<string, unknown>;
|
|
54
|
+
for (const key of EXTRA_GLOBALS) {
|
|
55
|
+
if (native[key] === undefined) delete target[key];
|
|
56
|
+
else target[key] = native[key];
|
|
57
|
+
}
|
|
58
|
+
restoreDomGlobals();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/** The component's own stack, mounted at `selection` (offsets into `doc`). */
|
|
62
|
+
function mount(doc: string, selection?: { anchor: number; head: number }): EditorView {
|
|
63
|
+
return new EditorView({
|
|
64
|
+
parent: host,
|
|
65
|
+
state: EditorState.create({
|
|
66
|
+
doc,
|
|
67
|
+
selection,
|
|
68
|
+
extensions: surfaceExtensions({
|
|
69
|
+
language: 'typescript',
|
|
70
|
+
wordWrapCompartment: new Compartment(),
|
|
71
|
+
readOnlyCompartment: new Compartment(),
|
|
72
|
+
themeCompartment: new Compartment(),
|
|
73
|
+
languageCompartment: new Compartment(),
|
|
74
|
+
indentCompartment: new Compartment(),
|
|
75
|
+
typingCompartment: new Compartment(),
|
|
76
|
+
blameCompartment: new Compartment(),
|
|
77
|
+
blame: null,
|
|
78
|
+
indentUnitText: ' ',
|
|
79
|
+
typing: { autoCloseBrackets: false, autocomplete: false },
|
|
80
|
+
wordWrap: false,
|
|
81
|
+
readOnly: false,
|
|
82
|
+
themes: SHIKI_THEMES,
|
|
83
|
+
onDocChange: () => {},
|
|
84
|
+
onState: () => {},
|
|
85
|
+
}),
|
|
86
|
+
}),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The mark classes on each rendered line, in document order. */
|
|
91
|
+
function marksByLine(view: EditorView): Array<{ text: string; marks: string[] }> {
|
|
92
|
+
return Array.from(view.contentDOM.querySelectorAll('.cm-line')).map((line) => ({
|
|
93
|
+
text: line.textContent ?? '',
|
|
94
|
+
marks: Array.from(line.querySelectorAll('.cm-whitespace-space, .cm-whitespace-tab')).map((mark) => mark.className),
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Every marked range of a document, without mounting a view. */
|
|
99
|
+
function ranges(doc: string, selection?: { anchor: number; head: number }): Array<[number, number]> {
|
|
100
|
+
const state = EditorState.create({ doc, selection });
|
|
101
|
+
const out: Array<[number, number]> = [];
|
|
102
|
+
whitespaceDecorations(state).between(0, state.doc.length, (from, to) => {
|
|
103
|
+
out.push([from, to]);
|
|
104
|
+
});
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
describe('whitespace marks', () => {
|
|
109
|
+
test('a caret paints nothing, however much whitespace the file holds', () => {
|
|
110
|
+
const doc = 'function f() {\n const a = 1;\n}\n';
|
|
111
|
+
const view = mount(doc, { anchor: 0, head: 0 });
|
|
112
|
+
expect(marksByLine(view).flatMap((line) => line.marks)).toEqual([]);
|
|
113
|
+
// And the rule agrees without a view.
|
|
114
|
+
expect(ranges(doc)).toEqual([]);
|
|
115
|
+
view.destroy();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('a selection marks every space it covers, indent and between tokens alike', () => {
|
|
119
|
+
const doc = 'function f() {\n const a = 1;\n}\n';
|
|
120
|
+
const lineFrom = doc.indexOf(' const');
|
|
121
|
+
const view = mount(doc, { anchor: lineFrom, head: lineFrom + ' const a = 1;'.length });
|
|
122
|
+
const block = marksByLine(view).find((line) => line.text === ' const a = 1;');
|
|
123
|
+
view.destroy();
|
|
124
|
+
|
|
125
|
+
// Four of indent plus the three between `const`, `a`, `=` and `1`: inside a
|
|
126
|
+
// selection, EVERY space is the point — that is what the reader is counting.
|
|
127
|
+
expect(block?.marks).toEqual(Array(7).fill('cm-whitespace-space'));
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('a selection that stops mid-line marks only the part it covers', () => {
|
|
131
|
+
expect(ranges(' x\n', { anchor: 0, head: 2 })).toEqual([
|
|
132
|
+
[0, 1],
|
|
133
|
+
[1, 2],
|
|
134
|
+
]);
|
|
135
|
+
expect(ranges(' x\n', { anchor: 1, head: 3 })).toEqual([
|
|
136
|
+
[1, 2],
|
|
137
|
+
[2, 3],
|
|
138
|
+
]);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('a tab in the selection is one arrow, not the columns it measures', () => {
|
|
142
|
+
const view = mount('\tif (a) {\n', { anchor: 0, head: 6 });
|
|
143
|
+
expect(marksByLine(view)[0].marks).toEqual(['cm-whitespace-tab', 'cm-whitespace-space']);
|
|
144
|
+
view.destroy();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('a selection spanning several lines marks each covered line', () => {
|
|
148
|
+
const doc = ' a\n b\nc\n';
|
|
149
|
+
expect(ranges(doc, { anchor: 0, head: doc.length })).toEqual([
|
|
150
|
+
[0, 1],
|
|
151
|
+
[1, 2],
|
|
152
|
+
[4, 5],
|
|
153
|
+
[5, 6],
|
|
154
|
+
[6, 7],
|
|
155
|
+
[7, 8],
|
|
156
|
+
]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('a selection ending in a line break does not reach the next line', () => {
|
|
160
|
+
// ` b` is fully covered; `c` starts at offset 9 and must not be touched.
|
|
161
|
+
const doc = ' a\n b\nc\n';
|
|
162
|
+
expect(ranges(doc, { anchor: 4, head: 9 })).toEqual([
|
|
163
|
+
[4, 5],
|
|
164
|
+
[5, 6],
|
|
165
|
+
[6, 7],
|
|
166
|
+
[7, 8],
|
|
167
|
+
]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('collapsing the selection clears the marks instead of leaving them painted', () => {
|
|
171
|
+
const doc = ' a\n b\n';
|
|
172
|
+
const view = mount(doc, { anchor: 0, head: doc.length });
|
|
173
|
+
expect(marksByLine(view).flatMap((line) => line.marks).length).toBe(6);
|
|
174
|
+
|
|
175
|
+
view.dispatch({ selection: { anchor: 3, head: 3 } });
|
|
176
|
+
expect(marksByLine(view).flatMap((line) => line.marks)).toEqual([]);
|
|
177
|
+
view.destroy();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('the mark holds the character it replaces, so a copy keeps its whitespace', () => {
|
|
181
|
+
const view = mount(' x\n', { anchor: 0, head: 4 });
|
|
182
|
+
const mark = view.contentDOM.querySelector('.cm-whitespace-space');
|
|
183
|
+
expect(mark?.textContent).toBe(' ');
|
|
184
|
+
expect(view.contentDOM.querySelector('.cm-line')?.textContent).toBe(' x');
|
|
185
|
+
view.destroy();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('the window bounds the walk, so a whole-document selection is still cheap', () => {
|
|
189
|
+
// The window is the viewport in the plugin; here it stands in for one, and the
|
|
190
|
+
// answer must be the selection INTERSECTED with it — not the whole document.
|
|
191
|
+
const doc = ' a\n b\n c\n';
|
|
192
|
+
const state = EditorState.create({ doc, selection: { anchor: 0, head: doc.length } });
|
|
193
|
+
const out: Array<[number, number]> = [];
|
|
194
|
+
whitespaceDecorations(state, state.selection.ranges, { from: 4, to: 8 }).between(0, state.doc.length, (from, to) => {
|
|
195
|
+
out.push([from, to]);
|
|
196
|
+
});
|
|
197
|
+
// Line 2's two spaces; the newline at 7 and line 3 (from offset 8) are outside
|
|
198
|
+
// the window, so they cost nothing.
|
|
199
|
+
expect(out).toEqual([
|
|
200
|
+
[4, 5],
|
|
201
|
+
[5, 6],
|
|
202
|
+
]);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('whitespace theme', () => {
|
|
207
|
+
test('both marks paint from the surface ink, and no indent guide survives', () => {
|
|
208
|
+
const view = mount(' a\n', { anchor: 0, head: 3 });
|
|
209
|
+
const css = Array.from(document.head.querySelectorAll('style'))
|
|
210
|
+
.map((node) => node.textContent ?? '')
|
|
211
|
+
.join('\n');
|
|
212
|
+
view.destroy();
|
|
213
|
+
|
|
214
|
+
// The package's own `#aaa`/`#888` are chroma the palette does not own, and
|
|
215
|
+
// they disappear against a dark editor theme, so both marks restate the ink.
|
|
216
|
+
expect(css).toMatch(/\.cm-whitespace-space \{[^}]*var\(--editor-fg, var\(--theme-ink\)\)/);
|
|
217
|
+
expect(css).toMatch(/\.cm-whitespace-tab \{[^}]*var\(--editor-fg, var\(--theme-ink\)\)/);
|
|
218
|
+
// One dot per character box, which is what `.4em` with `no-repeat` gives.
|
|
219
|
+
expect(css).toMatch(/\.cm-whitespace-space \{[^}]*background-size: \.4em/);
|
|
220
|
+
// The per-level vertical rule is gone; the marks replaced it.
|
|
221
|
+
expect(css).not.toContain('.cm-indent-guide');
|
|
222
|
+
});
|
|
223
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whitespace marks, drawn only where the text is SELECTED — VS Code's
|
|
8
|
+
* `editor.renderWhitespace: 'selection'`, its default.
|
|
9
|
+
*
|
|
10
|
+
* ## Why the selection, and not the document
|
|
11
|
+
*
|
|
12
|
+
* An always-on mark is a permanent dotted layer over every block in a file: it
|
|
13
|
+
* competes with the code it was meant to explain, and it answers a question
|
|
14
|
+
* nobody asked until they started caring about the bytes. Painting the marks on
|
|
15
|
+
* the selection answers it at the moment it is asked — a drag across a block, or
|
|
16
|
+
* `⇧⌘→` over a line — and leaves the rest of the document as code. The package's
|
|
17
|
+
* own `highlightWhitespace()` marks every space in the viewport; a leading-run
|
|
18
|
+
* version marks every block's indentation. Both were tried and both are noise.
|
|
19
|
+
*
|
|
20
|
+
* ## Two bounds keep it cheap
|
|
21
|
+
*
|
|
22
|
+
* - Only SELECTED characters are considered, so a caret (`empty` range) paints
|
|
23
|
+
* nothing — which is also what makes thousands of `⌘D` cursors free.
|
|
24
|
+
* - Only the selection's intersection with the VIEWPORT is walked, so `⌘A` on a
|
|
25
|
+
* 20 MB file costs the lines on screen rather than the document.
|
|
26
|
+
*
|
|
27
|
+
* ## It is NOT an indent guide
|
|
28
|
+
*
|
|
29
|
+
* Nothing here draws a vertical rule per nesting level — that feature was
|
|
30
|
+
* removed, because a column of rules read as structure the file does not have.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import type { EditorState, SelectionRange } from '@codemirror/state';
|
|
34
|
+
import { RangeSetBuilder } from '@codemirror/state';
|
|
35
|
+
import { Decoration, EditorView, ViewPlugin, type DecorationSet, type ViewUpdate } from '@codemirror/view';
|
|
36
|
+
|
|
37
|
+
/** The two characters a mark is drawn for; a line break is not one of them. */
|
|
38
|
+
const KINDS = {
|
|
39
|
+
' ': Decoration.mark({ class: 'cm-whitespace-space' }),
|
|
40
|
+
'\t': Decoration.mark({ class: 'cm-whitespace-tab' }),
|
|
41
|
+
} as const;
|
|
42
|
+
|
|
43
|
+
type WhitespaceChar = keyof typeof KINDS;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Marks every space and tab in `[from, to)`.
|
|
47
|
+
*
|
|
48
|
+
* One mark per CHARACTER, not per run: a mark's box is what the CSS paints, and
|
|
49
|
+
* a single span over four spaces can hold only one dot (`no-repeat` at `.4em`).
|
|
50
|
+
* Per-character ranges are what make four spaces draw four dots.
|
|
51
|
+
*/
|
|
52
|
+
function addSlice(state: EditorState, from: number, to: number, builder: RangeSetBuilder<Decoration>): void {
|
|
53
|
+
let line = state.doc.lineAt(from);
|
|
54
|
+
for (;;) {
|
|
55
|
+
const start = Math.max(from, line.from);
|
|
56
|
+
const end = Math.min(to, line.to);
|
|
57
|
+
for (let offset = start; offset < end; offset++) {
|
|
58
|
+
const kind = line.text[offset - line.from] as WhitespaceChar;
|
|
59
|
+
// Anything else — a newline, or the file's content — is not a mark.
|
|
60
|
+
if (kind === ' ' || kind === '\t') builder.add(offset, offset + 1, KINDS[kind]);
|
|
61
|
+
}
|
|
62
|
+
if (line.to >= to || line.to >= state.doc.length) break;
|
|
63
|
+
line = state.doc.lineAt(line.to + 1);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The marks for one selection range, clipped to the window `[windowFrom, windowTo)`.
|
|
69
|
+
*
|
|
70
|
+
* The clip is the viewport, which is the bound that makes a whole-document
|
|
71
|
+
* selection cheap: a mark outside the rendered lines could not be seen.
|
|
72
|
+
*/
|
|
73
|
+
function addRange(
|
|
74
|
+
state: EditorState,
|
|
75
|
+
range: SelectionRange,
|
|
76
|
+
windowFrom: number,
|
|
77
|
+
windowTo: number,
|
|
78
|
+
builder: RangeSetBuilder<Decoration>,
|
|
79
|
+
): void {
|
|
80
|
+
const from = Math.max(range.from, windowFrom);
|
|
81
|
+
const to = Math.min(range.to, windowTo);
|
|
82
|
+
// A caret, or a selection entirely outside the window: nothing to paint.
|
|
83
|
+
if (from >= to) return;
|
|
84
|
+
addSlice(state, from, to, builder);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The whitespace marks for `ranges`, in document order.
|
|
89
|
+
*
|
|
90
|
+
* `window` defaults to the whole document, which is what a caller that has no
|
|
91
|
+
* view (a test) wants; the plugin passes its viewport, because that is the only
|
|
92
|
+
* part of a selection that can be seen.
|
|
93
|
+
*/
|
|
94
|
+
export function whitespaceDecorations(
|
|
95
|
+
state: EditorState,
|
|
96
|
+
ranges: readonly SelectionRange[] = state.selection.ranges,
|
|
97
|
+
window: { from: number; to: number } = { from: 0, to: state.doc.length },
|
|
98
|
+
): DecorationSet {
|
|
99
|
+
const builder = new RangeSetBuilder<Decoration>();
|
|
100
|
+
for (const range of ranges) {
|
|
101
|
+
// CodeMirror keeps selection ranges ascending, and the window is one span,
|
|
102
|
+
// so appending as we go yields a sorted set.
|
|
103
|
+
addRange(state, range, window.from, window.to, builder);
|
|
104
|
+
}
|
|
105
|
+
return builder.finish();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The whitespace marks, as a view plugin.
|
|
110
|
+
*
|
|
111
|
+
* Rebuilt on a SELECTION change as well as on an edit or a scroll: the marks are
|
|
112
|
+
* a function of the selection AND of what is rendered, so collapsing the
|
|
113
|
+
* selection is what removes them and scrolling is what produces them elsewhere.
|
|
114
|
+
*/
|
|
115
|
+
export const whitespaceMarks = ViewPlugin.fromClass(
|
|
116
|
+
class {
|
|
117
|
+
decorations: DecorationSet;
|
|
118
|
+
|
|
119
|
+
constructor(view: EditorView) {
|
|
120
|
+
this.decorations = this.build(view);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
update(update: ViewUpdate) {
|
|
124
|
+
if (update.docChanged || update.selectionSet || update.viewportChanged) {
|
|
125
|
+
this.decorations = this.build(update.view);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private build(view: EditorView): DecorationSet {
|
|
130
|
+
const builder = new RangeSetBuilder<Decoration>();
|
|
131
|
+
for (const { from, to } of view.visibleRanges) {
|
|
132
|
+
for (const range of view.state.selection.ranges) {
|
|
133
|
+
if (!range.empty) addRange(view.state, range, from, to, builder);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return builder.finish();
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
{ decorations: (plugin) => plugin.decorations },
|
|
140
|
+
);
|
|
@@ -4,37 +4,33 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* The server panel's own markup: one row per server, the empty state, and the
|
|
8
|
+
* two footers a shell may or may not offer.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* - **Found on this machine** — servers the shell did NOT start: `kabmo serve`
|
|
15
|
-
* in a terminal, `bun run dev`, a login entry. They are read from the
|
|
16
|
-
* per-port records the servers themselves write, so a server that appeared
|
|
17
|
-
* after the panel opened shows up on the next refresh. They can be connected
|
|
18
|
-
* to but not stopped — this window did not start them, and a Stop here would
|
|
19
|
-
* kill a process somebody else is watching.
|
|
20
|
-
* - **Add a server** — a URL and a label.
|
|
21
|
-
*
|
|
22
|
-
* A server is only offered as connectable while it ANSWERS: the shell probes
|
|
23
|
-
* every URL before answering, so `running: false` is a real fact rather than a
|
|
24
|
-
* guess, and the row says so instead of letting a click fail on a blank window.
|
|
10
|
+
* Split from `ServerControl` so the trigger (a chip on a phone, a labelled
|
|
11
|
+
* button in a desktop navbar) and the list can be read and tested apart. The
|
|
12
|
+
* STORE is the control's, not the panel's: the old panel opened a second
|
|
13
|
+
* `useShellServers`, which meant two copies of the list, two 4-second polls and
|
|
14
|
+
* a trigger that could disagree with the rows directly under it.
|
|
25
15
|
*/
|
|
26
16
|
|
|
27
17
|
import { useState } from 'preact/hooks';
|
|
28
18
|
import { Check, Loader2, Play, Plus, RefreshCw, Server, Square, Trash2 } from 'lucide-preact';
|
|
29
|
-
import {
|
|
30
|
-
import type {
|
|
19
|
+
import type { ShellServersStore } from '@/client/hooks/shell/servers';
|
|
20
|
+
import type { ShellServer } from '@/client/lib/shell/servers';
|
|
21
|
+
import { mobileOverlayStyle } from '@/shared/lib/ui/mobile-overlay';
|
|
31
22
|
|
|
32
|
-
|
|
23
|
+
export type ServerControlVariant = 'nav' | 'chip';
|
|
24
|
+
|
|
25
|
+
interface ServerPanelProps {
|
|
33
26
|
open: boolean;
|
|
34
27
|
onClose: () => void;
|
|
28
|
+
/** `nav` hangs under a desktop navbar button; `chip` is a phone sheet. */
|
|
29
|
+
variant: ServerControlVariant;
|
|
30
|
+
store: ShellServersStore;
|
|
35
31
|
}
|
|
36
32
|
|
|
37
|
-
function statusLine(server:
|
|
33
|
+
function statusLine(server: ShellServer): string {
|
|
38
34
|
if (!server.running) return 'Stopped';
|
|
39
35
|
const parts: string[] = [];
|
|
40
36
|
if (server.version) parts.push(`v${server.version}`);
|
|
@@ -51,7 +47,7 @@ function Row({
|
|
|
51
47
|
onStop,
|
|
52
48
|
onRemove,
|
|
53
49
|
}: {
|
|
54
|
-
server:
|
|
50
|
+
server: ShellServer;
|
|
55
51
|
active: boolean;
|
|
56
52
|
busy: boolean;
|
|
57
53
|
onActivate: () => void;
|
|
@@ -113,8 +109,30 @@ function Row({
|
|
|
113
109
|
);
|
|
114
110
|
}
|
|
115
111
|
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Which server this window is on, and how to change it.
|
|
114
|
+
*
|
|
115
|
+
* The panel lists two groups, and the split is the whole design:
|
|
116
|
+
*
|
|
117
|
+
* - **This window** — the servers the shell remembers, with the active one
|
|
118
|
+
* marked. A remote entry is a URL somebody typed; a managed entry is a local
|
|
119
|
+
* server this shell started, which is why it can be stopped here.
|
|
120
|
+
* - **Found on this machine** — servers the shell did NOT start: `kabmo serve`
|
|
121
|
+
* in a terminal, `bun run dev`, a login entry. They are read from the
|
|
122
|
+
* per-port records the servers themselves write, so a server that appeared
|
|
123
|
+
* after the panel opened shows up on the next refresh. They can be connected
|
|
124
|
+
* to but not stopped — this window did not start them, and a Stop here would
|
|
125
|
+
* kill a process somebody else is watching.
|
|
126
|
+
*
|
|
127
|
+
* A phone answers neither group's second half: it cannot spawn a server, and it
|
|
128
|
+
* has no per-port records on the device, so those two sections are ABSENT there
|
|
129
|
+
* rather than drawn empty (`startable: false` and `detected: []` are the facts).
|
|
130
|
+
*
|
|
131
|
+
* A server is only offered as connectable while it ANSWERS: the shell probes
|
|
132
|
+
* every URL before answering, so `running: false` is a real fact rather than a
|
|
133
|
+
* guess, and the row says so instead of letting a click fail on a blank window.
|
|
134
|
+
*/
|
|
135
|
+
export function ServerPanel({ open, onClose, variant, store }: ServerPanelProps) {
|
|
118
136
|
const [label, setLabel] = useState('');
|
|
119
137
|
const [url, setUrl] = useState('');
|
|
120
138
|
const [adding, setAdding] = useState(false);
|
|
@@ -125,6 +143,7 @@ export function ServerSwitcher({ open, onClose }: ServerSwitcherProps) {
|
|
|
125
143
|
const entries = state?.entries ?? [];
|
|
126
144
|
const detected = state?.detected ?? [];
|
|
127
145
|
const activeId = state?.activeId;
|
|
146
|
+
const startable = state?.startable !== false;
|
|
128
147
|
|
|
129
148
|
const submit = async () => {
|
|
130
149
|
if (!url.trim()) return;
|
|
@@ -136,11 +155,24 @@ export function ServerSwitcher({ open, onClose }: ServerSwitcherProps) {
|
|
|
136
155
|
}
|
|
137
156
|
};
|
|
138
157
|
|
|
158
|
+
// Desktop hangs under its navbar button; a phone pins to the VIEWPORT, because
|
|
159
|
+
// its trigger sits in the drawer header and a 340px panel anchored there runs
|
|
160
|
+
// off the right edge (measured at 390) and past the bottom in landscape.
|
|
161
|
+
const placement =
|
|
162
|
+
variant === 'chip'
|
|
163
|
+
? mobileOverlayStyle()
|
|
164
|
+
: undefined;
|
|
165
|
+
|
|
139
166
|
return (
|
|
140
167
|
<div
|
|
141
168
|
role="dialog"
|
|
142
169
|
aria-label="Servers"
|
|
143
|
-
className=
|
|
170
|
+
className={
|
|
171
|
+
variant === 'chip'
|
|
172
|
+
? 'fixed z-50 rounded-xl border border-ink/15 bg-paper shadow-xl overflow-hidden'
|
|
173
|
+
: 'absolute right-2 top-full mt-1 z-50 w-[340px] rounded-xl border border-ink/15 bg-paper shadow-xl overflow-hidden'
|
|
174
|
+
}
|
|
175
|
+
style={placement}
|
|
144
176
|
onKeyDown={(event) => {
|
|
145
177
|
if (event.key === 'Escape') {
|
|
146
178
|
event.stopPropagation();
|
|
@@ -156,7 +188,7 @@ export function ServerSwitcher({ open, onClose }: ServerSwitcherProps) {
|
|
|
156
188
|
type="button"
|
|
157
189
|
onClick={() => void store.reload()}
|
|
158
190
|
disabled={store.busy}
|
|
159
|
-
title="Refresh — re-probe every server
|
|
191
|
+
title="Refresh — re-probe every server"
|
|
160
192
|
aria-label="Refresh servers"
|
|
161
193
|
className="p-1 rounded text-ink/40 hover:text-ink hover:bg-ink/10 cursor-pointer disabled:opacity-40"
|
|
162
194
|
>
|
|
@@ -207,7 +239,7 @@ export function ServerSwitcher({ open, onClose }: ServerSwitcherProps) {
|
|
|
207
239
|
|
|
208
240
|
{state && entries.length === 0 && detected.length === 0 && (
|
|
209
241
|
<p className="px-1 py-2 text-[11px] text-ink/50">
|
|
210
|
-
Nothing
|
|
242
|
+
Nothing here yet. Add a server by address.
|
|
211
243
|
</p>
|
|
212
244
|
)}
|
|
213
245
|
</div>
|
|
@@ -217,14 +249,20 @@ export function ServerSwitcher({ open, onClose }: ServerSwitcherProps) {
|
|
|
217
249
|
)}
|
|
218
250
|
|
|
219
251
|
<div className="border-t border-ink/10 px-2 py-2 space-y-1.5">
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
252
|
+
{/* A phone cannot spawn a server: there is no process to start and no
|
|
253
|
+
terminal to own it. The control is ABSENT rather than disabled,
|
|
254
|
+
because a disabled button would promise a capability the shell does
|
|
255
|
+
not have. */}
|
|
256
|
+
{startable && (
|
|
257
|
+
<button
|
|
258
|
+
type="button"
|
|
259
|
+
onClick={() => void store.start()}
|
|
260
|
+
disabled={store.busy}
|
|
261
|
+
className="w-full flex items-center gap-1.5 rounded-lg border border-ink/15 px-2.5 py-1.5 text-xs text-ink hover:bg-ink/5 cursor-pointer disabled:opacity-40"
|
|
262
|
+
>
|
|
263
|
+
<Play size={12} /> Start a local server
|
|
264
|
+
</button>
|
|
265
|
+
)}
|
|
228
266
|
|
|
229
267
|
{adding ? (
|
|
230
268
|
<form
|