@kabmo-labs/kabmo 0.16.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 (131) hide show
  1. package/README.md +2 -2
  2. package/dist/client/index.html +1 -1
  3. package/dist/client/index.js +417 -417
  4. package/dist/client/static/js/index-3ve31rzx.css +1 -0
  5. package/dist/client/static/js/{index-cpydmygd.js → index-rerjq5th.js} +839 -837
  6. package/package.json +1 -1
  7. package/src/client/components/common/code-surface/bracket-guide.test.ts +2 -2
  8. package/src/client/components/common/code-surface/bracket-guide.ts +2 -2
  9. package/src/client/components/common/code-surface/conflict-markers.ts +5 -5
  10. package/src/client/components/common/code-surface/extensions.ts +7 -4
  11. package/src/client/components/common/code-surface/theme.ts +34 -9
  12. package/src/client/components/common/code-surface/whitespace.test.ts +223 -0
  13. package/src/client/components/common/code-surface/whitespace.ts +140 -0
  14. package/src/client/components/common/{server-switcher/index.tsx → server-control/Panel.tsx} +73 -35
  15. package/src/client/components/common/{server-switcher → server-control}/index.test.tsx +98 -37
  16. package/src/client/components/common/server-control/index.tsx +118 -0
  17. package/src/client/components/layout/desktop-layout/TopNavbar.tsx +8 -50
  18. package/src/client/components/mobile/mobile-main-view/Header.tsx +6 -12
  19. package/src/client/components/mobile/mobile-session-sidebar/Header.tsx +41 -13
  20. package/src/client/components/settings/Modal.tsx +9 -3
  21. package/src/client/components/settings/ProjectSelectorDropdown.tsx +19 -9
  22. package/src/client/components/settings/categories/AgentSettings.tsx +27 -6
  23. package/src/client/components/settings/categories/ProjectSettings.tsx +122 -156
  24. package/src/client/components/settings/categories/SkillCatalogSettings.tsx +220 -260
  25. package/src/client/components/settings/categories/SkillSettings.tsx +6 -3
  26. package/src/client/components/settings/categories/agent-settings/SidebarList.tsx +5 -0
  27. package/src/client/components/settings/categories/project-settings/AccentPalette.test.tsx +189 -0
  28. package/src/client/components/settings/categories/project-settings/AccentPalette.tsx +156 -24
  29. package/src/client/components/settings/categories/project-settings/AddProjectModal.tsx +175 -0
  30. package/src/client/components/settings/categories/project-settings/DeleteProjectModal.tsx +107 -0
  31. package/src/client/components/settings/categories/project-settings/DetailsForm.tsx +40 -24
  32. package/src/client/components/settings/categories/project-settings/DetailsHeader.tsx +17 -7
  33. package/src/client/components/settings/categories/project-settings/IconGrid.tsx +164 -69
  34. package/src/client/components/settings/categories/project-settings/ModelDropdown.test.tsx +122 -0
  35. package/src/client/components/settings/categories/project-settings/ModelDropdown.tsx +124 -53
  36. package/src/client/components/settings/categories/project-settings/NameInput.tsx +57 -11
  37. package/src/client/components/settings/categories/project-settings/PathField.tsx +122 -0
  38. package/src/client/components/settings/categories/project-settings/SidebarList.tsx +100 -59
  39. package/src/client/components/settings/categories/skill-catalog/GitImportPanel.tsx +253 -0
  40. package/src/client/components/settings/categories/skill-catalog/SkillCard.tsx +89 -0
  41. package/src/client/components/settings/categories/skill-catalog/SourceRail.tsx +122 -0
  42. package/src/client/components/settings/categories/skill-catalog/catalog-ui.test.tsx +179 -0
  43. package/src/client/components/settings/categories/skill-settings/DetailHeader.tsx +208 -0
  44. package/src/client/components/settings/categories/skill-settings/DetailPane.tsx +137 -232
  45. package/src/client/components/settings/categories/skill-settings/InstructionsEditor.tsx +84 -0
  46. package/src/client/components/settings/categories/skill-settings/SidebarList.tsx +123 -87
  47. package/src/client/components/settings/categories/skill-settings/pane.test.tsx +179 -0
  48. package/src/client/components/settings/categories/skill-settings/row-meta.ts +58 -0
  49. package/src/client/components/workspace/chat-timeline/index.tsx +6 -1
  50. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.test.ts +46 -0
  51. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Proc.tsx +15 -6
  52. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.test.ts +29 -0
  53. package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +11 -3
  54. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.test.ts +24 -1
  55. package/src/client/components/workspace/chat-timeline/tool-renderers/shared/card-header.ts +6 -2
  56. package/src/client/components/workspace/editor/viewers/SvgPreview.tsx +18 -2
  57. package/src/client/components/workspace/editor/viewers/viewers.test.ts +39 -0
  58. package/src/client/components/workspace/file-explorer/ContextMenu.tsx +18 -5
  59. package/src/client/components/workspace/file-explorer/Modals.tsx +15 -1
  60. package/src/client/components/workspace/file-explorer/RowLabel.tsx +68 -0
  61. package/src/client/components/workspace/file-explorer/TreeItem.tsx +47 -57
  62. package/src/client/components/workspace/file-explorer/collapsed-chain.test.ts +167 -0
  63. package/src/client/components/workspace/file-explorer/drag-props.ts +42 -0
  64. package/src/client/components/workspace/file-explorer/drag.test.ts +43 -0
  65. package/src/client/components/workspace/file-explorer/index.tsx +21 -20
  66. package/src/client/data/settings/omp-schema.json +91 -4
  67. package/src/client/data/settings/project.ts +9 -28
  68. package/src/client/data/settings/skill.ts +6 -32
  69. package/src/client/hooks/chat/timeline/pending-model.ts +28 -0
  70. package/src/client/hooks/settings/projects/index.ts +294 -0
  71. package/src/client/hooks/settings/projects.test.ts +237 -0
  72. package/src/client/hooks/settings/skill-catalog.ts +101 -9
  73. package/src/client/hooks/settings/skill-git-import.ts +153 -0
  74. package/src/client/hooks/shell/servers.test.ts +166 -0
  75. package/src/client/hooks/{desktop → shell}/servers.ts +17 -14
  76. package/src/client/hooks/ui/updates/shell-download.ts +1 -1
  77. package/src/client/hooks/ui/updates/shell-update.ts +2 -6
  78. package/src/client/hooks/workspace/file-row-drag.ts +41 -0
  79. package/src/client/hooks/workspace/file-tree-actions.ts +25 -1
  80. package/src/client/hooks/workspace/file-tree-edits.ts +23 -6
  81. package/src/client/hooks/workspace/root-drop-target.ts +77 -0
  82. package/src/client/hooks/workspace/unfolded-chains.ts +165 -0
  83. package/src/client/lib/desktop/dropped-paths.ts +1 -1
  84. package/src/client/lib/desktop/titlebar.test.ts +12 -3
  85. package/src/client/lib/desktop/titlebar.ts +1 -1
  86. package/src/client/lib/shell/desktop.ts +117 -0
  87. package/src/client/lib/shell/servers.ts +75 -0
  88. package/src/client/lib/shell/transport.ts +216 -0
  89. package/src/client/main.tsx +9 -0
  90. package/src/server/lib/fs/git-merge-conflict.test.ts +14 -1
  91. package/src/server/lib/omp/config/skill-sources.ts +49 -0
  92. package/src/server/lib/omp/config/skills-git-install.ts +155 -0
  93. package/src/server/lib/omp/config/skills-git-repo.ts +288 -0
  94. package/src/server/lib/omp/config/skills-git.test.ts +220 -0
  95. package/src/server/lib/workspace/project-model.server.test.ts +102 -0
  96. package/src/server/lib/workspace/project-model.server.ts +47 -0
  97. package/src/server/lib/workspace/project-patch.server.ts +156 -0
  98. package/src/server/routes/agent/new.ts +8 -1
  99. package/src/server/routes/settings/agents.ts +19 -7
  100. package/src/server/routes/settings/projects.ts +53 -19
  101. package/src/server/routes/settings/settings-projects-routes.test.ts +214 -0
  102. package/src/server/routes/settings/settings-store-routes.test.ts +5 -2
  103. package/src/server/routes/settings/skills-catalog-actions.ts +195 -0
  104. package/src/server/routes/settings/skills.test.ts +225 -0
  105. package/src/server/routes/settings/skills.ts +18 -15
  106. package/src/shared/lib/fs/folder-chain.test.ts +81 -1
  107. package/src/shared/lib/fs/folder-chain.ts +84 -0
  108. package/src/shared/lib/omp/config/schema.test.ts +35 -0
  109. package/src/shared/lib/omp/session/job-progress.test.ts +37 -1
  110. package/src/shared/lib/omp/session/job-progress.ts +31 -0
  111. package/src/shared/lib/omp/session/proc.ts +5 -0
  112. package/src/shared/lib/omp/session/wait.ts +5 -0
  113. package/src/shared/lib/ui/mobile-overlay.ts +61 -0
  114. package/src/shared/lib/ui/svg-scope.test.ts +97 -0
  115. package/src/shared/lib/ui/svg-scope.ts +134 -0
  116. package/src/shared/lib/workspace/project-accent.test.ts +69 -0
  117. package/src/shared/lib/workspace/project-accent.ts +63 -0
  118. package/src/shared/lib/workspace/project-icon.ts +40 -0
  119. package/src/shared/lib/workspace/project-model.test.ts +79 -0
  120. package/src/shared/lib/workspace/project-model.ts +64 -0
  121. package/src/shared/types/settings/skill.ts +53 -3
  122. package/src/test-support/file-explorer-disk.test-util.ts +25 -1
  123. package/src/test-support/file-explorer-drag.test-util.ts +88 -0
  124. package/src/test-support/file-explorer.test-util.ts +47 -47
  125. package/dist/client/static/js/index-fjnq2z2d.css +0 -1
  126. package/src/client/components/common/code-surface/indent-guide.ts +0 -104
  127. package/src/client/components/settings/categories/skill-catalog/AddSourceModal.tsx +0 -133
  128. package/src/client/hooks/desktop/servers.test.ts +0 -73
  129. package/src/client/lib/desktop/bridge.ts +0 -203
  130. package/src/shared/lib/code/editor/indent-guide-rule.test.ts +0 -65
  131. package/src/shared/lib/code/editor/indent-guide-rule.ts +0 -47
@@ -37,7 +37,7 @@ import {
37
37
  } from '@/shared/lib/omp/session/proc';
38
38
  import { FallbackOutput } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/FallbackOutput';
39
39
  import { ToolPanelHeader } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/ToolPanelHeader';
40
- import { jobProgressLine } from '@/shared/lib/omp/session/job-progress';
40
+ import { jobSubject, jobProgressLine } from '@/shared/lib/omp/session/job-progress';
41
41
 
42
42
  /** Tone → class list. A toned chip is text-only; the ink palette has no room
43
43
  * for a filled pill in a dense row. */
@@ -88,13 +88,16 @@ function DaemonFacts({ daemon, now }: { daemon: ProcDaemon; now: number }) {
88
88
  );
89
89
  }
90
90
 
91
- /** A job row: status, id, type, what it runs, how long it has run. */
91
+ /** A job row: status, id, type, what it is for, and how long it has run. */
92
92
  function JobRow({ job }: { job: ProcJob }) {
93
93
  const tone = jobTone(job.status);
94
94
  const running = job.status === 'running';
95
95
  const duration = typeof job.durationMs === 'number' ? formatProcDuration(job.durationMs) : undefined;
96
96
  // This row has no percent chip, so the line carries the estimate itself.
97
97
  const progress = jobProgressLine(job, { includePercent: true });
98
+ // omp 18.15.0 records the caller's intent on the job and leads its own rows
99
+ // with it; the label (the raw command) is the second line, not the subject.
100
+ const subject = jobSubject(job);
98
101
  return (
99
102
  <div className="space-y-0.5 px-3 py-1.5">
100
103
  <div className="flex items-center gap-2 text-[11.5px]">
@@ -113,8 +116,8 @@ function JobRow({ job }: { job: ProcJob }) {
113
116
  {job.type}
114
117
  </span>
115
118
  )}
116
- <span className="min-w-0 flex-1 truncate text-ink/85" title={job.label}>
117
- {job.label ?? job.resultText ?? job.errorText ?? ''}
119
+ <span className="min-w-0 flex-1 truncate text-ink/85" title={subject.primary}>
120
+ {subject.primary ?? job.resultText ?? job.errorText ?? ''}
118
121
  </span>
119
122
  {job.resolvedModel && (
120
123
  <span className="hidden max-w-[120px] truncate font-mono text-[9px] text-ink/40 sm:inline-block">
@@ -126,6 +129,11 @@ function JobRow({ job }: { job: ProcJob }) {
126
129
  <span className={`shrink-0 font-mono text-[9px] font-semibold ${TONE_CLASSES[tone]}`}>{job.status}</span>
127
130
  )}
128
131
  </div>
132
+ {subject.secondary && (
133
+ <div className="truncate font-mono text-[9px] text-ink/45" title={subject.secondary}>
134
+ {subject.secondary}
135
+ </div>
136
+ )}
129
137
  {progress && <div className="truncate font-mono text-[9px] text-ink/40">{progress}</div>}
130
138
  </div>
131
139
  );
@@ -261,12 +269,13 @@ export function Proc({ tool }: { tool: ToolCallData }) {
261
269
  {view.cancelled.map((outcome, index) => {
262
270
  const job = view.jobs.find((row) => row.id === outcome.id);
263
271
  const tone = jobTone(outcome.status);
272
+ const subject = jobSubject(job ?? {});
264
273
  return (
265
274
  <div key={`${outcome.id ?? index}`} className="flex items-center gap-2 px-3 py-1.5 text-[11.5px]">
266
275
  <CircleSlash size={11} className="shrink-0 text-warning" />
267
276
  <span className="shrink-0 font-mono text-[10px] font-semibold text-ink/80">{outcome.id ?? 'job'}</span>
268
- <span className="min-w-0 flex-1 truncate text-ink/70" title={job?.label}>
269
- {job?.label ?? ''}
277
+ <span className="min-w-0 flex-1 truncate text-ink/70" title={subject.primary}>
278
+ {subject.primary ?? subject.secondary ?? ''}
270
279
  </span>
271
280
  <span className={`shrink-0 font-mono text-[9px] font-semibold ${TONE_CLASSES[tone]}`}>
272
281
  {outcome.status}
@@ -280,4 +280,33 @@ describe('Wait panel — interrupted and messaged', () => {
280
280
  expect(text).toContain('Sleeper');
281
281
  expect(text).toContain('sleeper reporting in');
282
282
  });
283
+
284
+ test('leads a job row with the intent omp 18.15.0 records', async () => {
285
+ const el = await mount({
286
+ type: 'wait',
287
+ name: 'wait',
288
+ status: 'running',
289
+ details: {
290
+ op: 'wait',
291
+ jobs: [
292
+ { id: 'bg_1', type: 'bash', status: 'running', label: 'bun run dev', intent: 'Start the dev server', durationMs: 4_000 },
293
+ ],
294
+ },
295
+ });
296
+ const text = el.textContent ?? '';
297
+ expect(text).toContain('Start the dev server');
298
+ expect(text).toContain('bun run dev');
299
+ // The purpose is the row's subject: it comes BEFORE the raw command.
300
+ expect(text.indexOf('Start the dev server')).toBeLessThan(text.indexOf('bun run dev'));
301
+ });
302
+
303
+ test('a task job without an intent still draws its label', async () => {
304
+ const el = await mount({
305
+ type: 'wait',
306
+ name: 'wait',
307
+ status: 'running',
308
+ details: { op: 'wait', jobs: [{ id: 'bg_2', type: 'task', status: 'running', label: 'audit', durationMs: 2_000 }] },
309
+ });
310
+ expect(el.textContent ?? '').toContain('audit');
311
+ });
283
312
  });
@@ -49,7 +49,7 @@ import {
49
49
  } from '@/shared/lib/omp/session/wait';
50
50
  import { FallbackOutput } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/FallbackOutput';
51
51
  import { ToolPanelHeader } from '@/client/components/workspace/chat-timeline/tool-renderers/shared/ToolPanelHeader';
52
- import { jobProgressLine } from '@/shared/lib/omp/session/job-progress';
52
+ import { jobSubject, jobProgressLine } from '@/shared/lib/omp/session/job-progress';
53
53
 
54
54
  const TONE_CLASSES = {
55
55
  ok: 'text-success',
@@ -127,11 +127,14 @@ function ProgressTrack({ percent, active }: { percent: number | null; active: bo
127
127
  );
128
128
  }
129
129
 
130
- /** One job row: what it runs, its status, and how long it has run. */
130
+ /** One job row: what it is for, its status, and how long it has run. */
131
131
  function JobRow({ job }: { job: WaitJob }) {
132
132
  const tone = jobTone(job.status);
133
133
  const running = job.status === 'running';
134
- const label = job.label ?? job.resultText ?? job.errorText ?? job.id ?? '';
134
+ // omp 18.15.0 records the caller's intent on the job and leads its own rows
135
+ // with it, so `bun run dev` is not what the reader sees first.
136
+ const subject = jobSubject(job);
137
+ const label = subject.primary ?? job.resultText ?? job.errorText ?? job.id ?? '';
135
138
  const percent = running ? job.completionPercent : undefined;
136
139
  // The percent is already a chip in this row, so the progress line leaves it out.
137
140
  const progress = jobProgressLine(job);
@@ -176,6 +179,11 @@ function JobRow({ job }: { job: WaitJob }) {
176
179
  {running && percent !== undefined && (
177
180
  <ProgressTrack percent={percent} active />
178
181
  )}
182
+ {subject.secondary && (
183
+ <div className="truncate font-mono text-[9px] text-ink/45" title={subject.secondary}>
184
+ {subject.secondary.split('\n')[0]}
185
+ </div>
186
+ )}
179
187
  {progress && (
180
188
  <div className="truncate font-mono text-[9px] text-ink/40">{progress}</div>
181
189
  )}
@@ -157,12 +157,35 @@ describe('toolCardHeader — read xd:// docs', () => {
157
157
  });
158
158
  });
159
159
 
160
+ describe('toolCardHeader — a wait names what it blocks on', () => {
161
+ test('leads with the job intent omp 18.15.0 records', () => {
162
+ // The header reads the SAME resolver as the job rows, so a card and its row
163
+ // cannot name different things — and the intent is the better subject: the
164
+ // raw command does not say what the job is for.
165
+ expect(header({
166
+ type: 'wait',
167
+ status: 'running',
168
+ details: {
169
+ op: 'wait',
170
+ jobs: [{ id: 'bg_1', type: 'bash', status: 'running', label: 'bun run dev', intent: 'Start the dev server' }],
171
+ },
172
+ })).toEqual({ title: 'Wait', subtitle: 'Start the dev server' });
173
+ });
174
+
175
+ test('falls back to the raw label when the job has no intent', () => {
176
+ expect(header({
177
+ type: 'wait',
178
+ status: 'running',
179
+ details: { op: 'wait', jobs: [{ id: 'bg_2', type: 'task', status: 'running', label: 'audit the diff' }] },
180
+ })).toEqual({ title: 'Wait', subtitle: 'audit the diff' });
181
+ });
182
+ });
183
+
160
184
  describe('toolCardHeader — generic', () => {
161
185
  test('splits a `name — subject` title', () => {
162
186
  expect(header({ type: 'bash', title: 'grep — export function ToolCallCard' }))
163
187
  .toEqual({ title: 'Grep', subtitle: 'export function ToolCallCard' });
164
188
  });
165
-
166
189
  test('carries the subagent from tasks[0] for a task call', () => {
167
190
  expect(header({
168
191
  type: 'task',
@@ -22,6 +22,7 @@ import { toTitleCase } from '@/shared/lib/chat/title-case';
22
22
  import { parseAskQuestions } from '@/shared/lib/chat/ask-questions';
23
23
  import { procOpLabel, procPathOf, procViewOf } from '@/shared/lib/omp/session/proc';
24
24
  import { waitViewOf } from '@/shared/lib/omp/session/wait';
25
+ import { jobSubject } from '@/shared/lib/omp/session/job-progress';
25
26
  import { isXdDocRead, xdDocPath } from '@/client/components/workspace/chat-timeline/tool-renderers/registry';
26
27
  import { resolveTargetFile } from '@/client/components/workspace/chat-timeline/tool-renderers';
27
28
  import {
@@ -114,11 +115,14 @@ export function toolCardHeader(tool: ToolCallData, toolKey: string): ToolCardHea
114
115
  // The generic path printed the tool name and nothing else, so a card that
115
116
  // blocked for two minutes was indistinguishable from a call that never ran.
116
117
  // The subtitle names the job (or the message) the wait was for; the clock is
117
- // a fact chip, not a title line.
118
+ // a fact chip, not a title line. The subject comes from `jobSubject`, the same
119
+ // resolver the job rows read, so a header and its row cannot name different
120
+ // things — and since omp 18.15.0 that means the model's intent when it gave
121
+ // one, with the raw command as the fallback.
118
122
  if (toolKey === 'wait') {
119
123
  const view = waitViewOf(tool);
120
124
  const job = view?.jobs[0];
121
- const subject = job?.label?.split('\n')[0]?.trim() || job?.id || view?.waited?.from;
125
+ const subject = (job ? jobSubject(job).primary?.split('\n')[0]?.trim() : undefined) || job?.id || view?.waited?.from;
122
126
  return { title: 'Wait', subtitle: subject ? clip(subject) : undefined };
123
127
  }
124
128
 
@@ -20,8 +20,9 @@
20
20
  * container whose size is driven by the SVG's own viewBox.
21
21
  */
22
22
 
23
- import { useMemo } from 'preact/hooks';
23
+ import { useMemo, useRef } from 'preact/hooks';
24
24
  import { sanitizeMermaidSvg } from '@/shared/lib/markdown/sanitize';
25
+ import { nextSvgScopePrefix, scopeSvgIds } from '@/shared/lib/ui/svg-scope';
25
26
 
26
27
  interface SvgPreviewProps {
27
28
  content: string;
@@ -29,7 +30,22 @@ interface SvgPreviewProps {
29
30
  }
30
31
 
31
32
  export function SvgPreview({ content, name }: SvgPreviewProps) {
32
- const safeSvg = useMemo(() => sanitizeMermaidSvg(content), [content]);
33
+ // The id namespace is allocated ONCE per mounted preview and kept across
34
+ // edits: a prefix that changed with every keystroke would rewrite every id
35
+ // on every render for no benefit, and the sanitized markup is memoized on
36
+ // `content` alone.
37
+ const scopeRef = useRef('');
38
+ if (!scopeRef.current) scopeRef.current = nextSvgScopePrefix();
39
+
40
+ // SCOPED BEFORE SANITIZED, and the order is the fix rather than a detail.
41
+ // DOMPurify drops any `id` whose value is already a property of the page
42
+ // (`body`, `title`, `name`, …) because that attribute is its DOM-clobbering
43
+ // vector, and the `fill="url(#body)"` that referenced it is left behind — a
44
+ // gradient-painted shape silently adopts the wrong paint. See `svg-scope`.
45
+ const safeSvg = useMemo(
46
+ () => sanitizeMermaidSvg(scopeSvgIds(content, scopeRef.current)),
47
+ [content],
48
+ );
33
49
 
34
50
  return (
35
51
  <div className="flex-1 overflow-auto bg-paper">
@@ -139,6 +139,45 @@ describe('SvgPreview', () => {
139
139
  expect(container.querySelector('script')).toBeNull();
140
140
  expect((globalThis as Record<string, unknown>).__pwned).toBeUndefined();
141
141
  });
142
+
143
+ // THE gradient regression. DOMPurify drops an `id` whose value is already a
144
+ // property of the page — `body` is — while the `fill="url(#body)"` that
145
+ // referenced it survives, so the shape silently paints with whatever else
146
+ // claims that name. Measured on a real icon: the chicken's body and head came
147
+ // out dark green instead of cream. The ids are therefore prefixed before the
148
+ // sanitizer sees them, and BOTH halves must move together.
149
+ test('a defs id the page already owns survives, and its reference follows', async () => {
150
+ await mount(
151
+ h(SvgPreview, {
152
+ content:
153
+ '<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><defs><linearGradient id="body"><stop offset="0" stop-color="#fff"/></linearGradient></defs><rect width="10" height="10" fill="url(#body)"/></svg>',
154
+ name: 'icon.svg',
155
+ }),
156
+ );
157
+ // happy-dom's own sanitizer keeps these; the browser's is the one that
158
+ // would have dropped `id="body"`, which is why the prefix exists at all.
159
+ const gradient = container.querySelector('linearGradient, lineargradient');
160
+ const rect = container.querySelector('rect');
161
+ expect(rect).not.toBeNull();
162
+ const declared = gradient?.getAttribute('id') ?? '';
163
+ expect(declared).toMatch(/^svg\d+-body$/);
164
+ expect(rect?.getAttribute('fill')).toBe(`url(#${declared})`);
165
+ });
166
+
167
+ // Two previews must not resolve one another's definitions: `defs` ids are
168
+ // document-scoped, so an unprefixed pair means the second picture paints with
169
+ // the first one's gradient.
170
+ test('two previews scoped their ids apart', async () => {
171
+ const markup =
172
+ '<svg xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="paint"/></defs><rect width="4" height="4" fill="url(#paint)"/></svg>';
173
+ await mount(h(SvgPreview, { content: markup, name: 'a.svg' }));
174
+ const firstId = container.querySelector('linearGradient, lineargradient')?.getAttribute('id');
175
+ await mount(h(SvgPreview, { content: markup, name: 'b.svg' }));
176
+ const secondId = container.querySelector('linearGradient, lineargradient')?.getAttribute('id');
177
+ expect(firstId).toBeTruthy();
178
+ expect(secondId).toBeTruthy();
179
+ expect(firstId).not.toBe(secondId);
180
+ });
142
181
  });
143
182
 
144
183
  describe('DocxView', () => {
@@ -29,7 +29,7 @@
29
29
 
30
30
  import { createPortal } from 'preact/compat';
31
31
  import type { ReactNode, RefObject } from 'preact/compat';
32
- import { ClipboardPaste, Copy, CopyPlus, Edit2, ExternalLink, Eye, FilePlus, FolderPlus, GitCompare, History, Scissors, Trash2 } from 'lucide-preact';
32
+ import { ChevronDown, ChevronRight, ClipboardPaste, Copy, CopyPlus, Edit2, ExternalLink, Eye, FilePlus, FolderPlus, GitCompare, History, Scissors, Trash2 } from 'lucide-preact';
33
33
 
34
34
  interface ContextMenuProps {
35
35
  x: number;
@@ -38,6 +38,10 @@ interface ContextMenuProps {
38
38
  hasGitStatus?: boolean;
39
39
  /** Label of the Paste row, or null when a paste cannot land on this target. */
40
40
  pasteLabel: string | null;
41
+ /** True when this row's label names more than one directory (a chain). */
42
+ chainLabel?: boolean;
43
+ /** True when this row is an unfolded chain's outermost level. */
44
+ foldable?: boolean;
41
45
  /** True while a transfer is in flight; the acting rows disable on it. */
42
46
  busy: boolean;
43
47
  onAction: (actionType: string) => void;
@@ -55,13 +59,22 @@ const SEPARATOR_PX = 9;
55
59
  const PADDING_PX = 8;
56
60
 
57
61
  /** The rows this target offers, in order — the menu's single source of truth. */
58
- function buildRows(options: { isFolder: boolean; hasGitStatus?: boolean; pasteLabel: string | null; busy: boolean }): MenuEntry[] {
59
- const { isFolder, hasGitStatus, pasteLabel, busy } = options;
62
+ function buildRows(options: { isFolder: boolean; hasGitStatus?: boolean; pasteLabel: string | null; busy: boolean; chainLabel?: boolean; foldable?: boolean }): MenuEntry[] {
63
+ const { isFolder, hasGitStatus, pasteLabel, busy, chainLabel, foldable } = options;
60
64
  const entries: MenuEntry[] = [];
61
65
 
62
66
  if (isFolder) {
63
67
  entries.push({ kind: 'item', id: 'new_file', label: 'New File', icon: <FilePlus size={13} className="text-ink/60" /> });
64
68
  entries.push({ kind: 'item', id: 'new_folder', label: 'New Folder', icon: <FolderPlus size={13} className="text-ink/60" /> });
69
+ // A row labelled `dev/src/main/code` is one row standing for four
70
+ // directories: the levels inside it cannot be dropped on or renamed until
71
+ // they are rows, and this is the explicit way to make them so.
72
+ if (chainLabel) {
73
+ entries.push({ kind: 'item', id: 'unfold', label: 'Unfold Folders', icon: <ChevronDown size={13} className="text-ink/60" /> });
74
+ }
75
+ if (foldable) {
76
+ entries.push({ kind: 'item', id: 'fold', label: 'Fold Folders', icon: <ChevronRight size={13} className="text-ink/60" /> });
77
+ }
65
78
  entries.push({ kind: 'separator' });
66
79
  } else {
67
80
  entries.push({ kind: 'item', id: 'view', label: 'View', icon: <Eye size={13} className="text-ink/60" /> });
@@ -100,9 +113,9 @@ function menuHeightOf(entries: MenuEntry[]): number {
100
113
  return items * ROW_PX + separators * SEPARATOR_PX + PADDING_PX;
101
114
  }
102
115
 
103
- export function FileContextMenu({ x, y, isFolder, hasGitStatus, pasteLabel, busy, onAction, menuRef }: ContextMenuProps) {
116
+ export function FileContextMenu({ x, y, isFolder, hasGitStatus, pasteLabel, chainLabel, foldable, busy, onAction, menuRef }: ContextMenuProps) {
104
117
  const menuWidth = 190;
105
- const entries = buildRows({ isFolder, hasGitStatus, pasteLabel, busy });
118
+ const entries = buildRows({ isFolder, hasGitStatus, pasteLabel, busy, chainLabel, foldable });
106
119
  const menuHeight = menuHeightOf(entries);
107
120
 
108
121
  const posX = typeof window !== 'undefined' ? Math.max(10, Math.min(x, window.innerWidth - menuWidth - 12)) : x;
@@ -132,6 +132,8 @@ interface RenameModalProps {
132
132
  isFolder: boolean;
133
133
  renameValue: string;
134
134
  originalPath: string;
135
+ /** The row's label, when it differs from the path (a collapsed chain). */
136
+ displayName?: string;
135
137
  /** The server's refusal (an existing destination, a bad path), shown inline. */
136
138
  error?: string | null;
137
139
  isLoading: boolean;
@@ -148,8 +150,13 @@ interface RenameModalProps {
148
150
  * `lib/deep/a.ts` both renames the file and moves it, and its parents are
149
151
  * created on the way. A leaf-only field would have made that a create-then-
150
152
  * delete, which is not a rename.
153
+ *
154
+ * A collapsed chain row is LABELLED `dev/src/main/code` while its path is the
155
+ * deepest directory only, so the field shows the path and the dialog says which
156
+ * of the two it renames — typing the label would otherwise move the deepest
157
+ * directory out and leave the rest of the chain behind.
151
158
  */
152
- export function FileRenameModal({ isFolder, renameValue, originalPath, error, isLoading, onChange, onCancel, onSubmit }: RenameModalProps) {
159
+ export function FileRenameModal({ isFolder, renameValue, originalPath, displayName, error, isLoading, onChange, onCancel, onSubmit }: RenameModalProps) {
153
160
  return createPortal(
154
161
  <div className="fixed inset-0 bg-ink/20 z-[100] flex items-center justify-center p-4 backdrop-blur-sm">
155
162
  <form onSubmit={onSubmit} className="bg-paper rounded shadow-xl p-4 w-full max-w-sm border border-ink/10 font-sans">
@@ -167,6 +174,13 @@ export function FileRenameModal({ isFolder, renameValue, originalPath, error, is
167
174
  <p className="text-[10px] text-ink/40 mb-2">
168
175
  Paths are relative to the tree — <span className="font-mono">lib/deep/name.ts</span> moves it too.
169
176
  </p>
177
+ {displayName && (
178
+ <p className="text-[11px] text-ink/50 mb-2">
179
+ The row is <span className="font-mono">{displayName}</span>; this renames{' '}
180
+ <span className="font-mono">{originalPath}</span>. Use{' '}
181
+ <span className="font-mono">Unfold Folders</span> to rename a folder inside the chain.
182
+ </p>
183
+ )}
170
184
  {error && <p className="text-[11px] text-error mb-2">{error}</p>}
171
185
  <div className="flex justify-end space-x-2">
172
186
  <button
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * The Files panel's row LABEL: the disclosure glyph, the icon, the name and the
8
+ * two git marks.
9
+ *
10
+ * Split from `TreeItem.tsx` because it is the row's leaf markup and has no
11
+ * behaviour of its own — every fact it draws is derived by the row and handed
12
+ * in, so the split costs no prop drilling and keeps the row component under the
13
+ * repository's line ceiling.
14
+ */
15
+
16
+ import { ChevronDown, ChevronRight } from 'lucide-preact';
17
+ import { FileIcon } from '@/client/components/common/file-icon';
18
+ import type { FolderGitStatusInfo } from '@/shared/lib/fs/git-status';
19
+
20
+ interface TreeRowLabelProps {
21
+ name: string;
22
+ path: string;
23
+ isFolder: boolean;
24
+ isOpen: boolean;
25
+ /** Git-ignored entries render faded rather than being hidden. */
26
+ ignored: boolean;
27
+ /** This file's own change, when it has one. */
28
+ gitStatus: { colorClass: string; label: string; charStatus: string } | null;
29
+ /** The roll-up a folder wears instead: one dot, its tone from the changes. */
30
+ folderStatus: FolderGitStatusInfo | null | undefined;
31
+ }
32
+
33
+ export function TreeRowLabel({ name, path, isFolder, isOpen, ignored, gitStatus, folderStatus }: TreeRowLabelProps) {
34
+ const tone = gitStatus ? gitStatus.colorClass : folderStatus ? folderStatus.colorClass : ignored ? 'text-ink/40' : '';
35
+ return (
36
+ <>
37
+ {isFolder ? (
38
+ isOpen ? <ChevronDown size={12} className="flex-shrink-0 text-ink/40" /> : <ChevronRight size={12} className="flex-shrink-0 text-ink/40" />
39
+ ) : (
40
+ <span className="w-3 flex-shrink-0"></span>
41
+ )}
42
+
43
+ <FileIcon name={name} isFolder={isFolder} isOpen={isOpen} size={12} className={`flex-shrink-0${ignored ? ' opacity-40' : ''}`} />
44
+ <span className={`truncate min-w-0 flex-1 ${tone}`} title={ignored ? `${path} — git-ignored` : undefined}>
45
+ {name}
46
+ </span>
47
+
48
+ {gitStatus && (
49
+ <span
50
+ className={`font-mono text-[9px] font-bold px-1 rounded flex-shrink-0 ${gitStatus.colorClass}`}
51
+ title={`Git: ${gitStatus.label}`}
52
+ >
53
+ {gitStatus.charStatus}
54
+ </span>
55
+ )}
56
+
57
+ {folderStatus && (
58
+ <span
59
+ className={`w-1.5 h-1.5 rounded-full flex-shrink-0 ${
60
+ folderStatus.hasDeleted ? 'bg-error' :
61
+ folderStatus.hasModified || folderStatus.hasStaged ? 'bg-info' : 'bg-success'
62
+ }`}
63
+ title={`${folderStatus.count} changed file${folderStatus.count > 1 ? 's' : ''}`}
64
+ />
65
+ )}
66
+ </>
67
+ );
68
+ }
@@ -1,17 +1,18 @@
1
1
  import { useEffect, useState } from 'preact/hooks';
2
- import { ChevronDown, ChevronRight } from 'lucide-preact';
3
- import { FileIcon } from '@/client/components/common/file-icon';
2
+ import { TreeRowLabel } from '@/client/components/workspace/file-explorer/RowLabel';
4
3
  import { FileContextMenu } from '@/client/components/workspace/file-explorer/ContextMenu';
5
4
  import { FileCreateModal, FileDeleteModal, FileHistoryModal, FileRenameModal } from '@/client/components/workspace/file-explorer/Modals';
6
5
  import { getGitStatusInfo, type FolderGitStatusInfo } from '@/shared/lib/fs/git-status';
6
+ import { isChainRow } from '@/shared/lib/fs/folder-chain';
7
7
  import { useFileActions } from '@/client/hooks/workspace/file-tree-actions';
8
8
  import { useFileRowDrag } from '@/client/hooks/workspace/file-row-drag';
9
9
  import { useOnClickOutside } from '@/client/hooks/ui/on-click-outside';
10
10
  import { useLongPress } from '@/client/hooks/ui/long-press';
11
11
  import type { FileClipboard, ClipboardTarget } from '@/client/hooks/workspace/file-clipboard';
12
+ import type { FileTreeDragProps } from '@/client/components/workspace/file-explorer/drag-props';
12
13
  import type { GitChange } from '@/shared/types/git';
13
14
 
14
- interface FileTreeItemProps {
15
+ interface FileTreeItemProps extends FileTreeDragProps {
15
16
  file: any;
16
17
  rootPath?: string;
17
18
  /** Absolute base dir of the listing (server-reported `root`), anchors Copy Path. */
@@ -31,12 +32,6 @@ interface FileTreeItemProps {
31
32
  gitFolderMap?: Map<string, FolderGitStatusInfo>;
32
33
  /** The panel's clipboard — one instance for the whole tree, passed down. */
33
34
  clipboard: FileClipboard;
34
- /** The row currently being dragged, or null. Panel state: see `FileTreeItem`. */
35
- dragging: ClipboardTarget | null;
36
- /** A drag of this row started / ended / was dropped on `target`. */
37
- onDragStart: (target: ClipboardTarget) => void;
38
- onDragEnd: () => void;
39
- onDropOn: (target: ClipboardTarget) => void;
40
35
  /**
41
36
  * True on a device typed into with a finger. A row is a drag SOURCE, and on
42
37
  * touch a long press starts a native drag of the whole panel — the reported
@@ -87,6 +82,9 @@ export function FileTreeItem({
87
82
  onDragStart,
88
83
  onDragEnd,
89
84
  onDropOn,
85
+ onUnfold,
86
+ onFold,
87
+ foldRoots,
90
88
  touch = false,
91
89
  }: FileTreeItemProps) {
92
90
  const isFolder = file.type === 'folder';
@@ -126,6 +124,21 @@ export function FileTreeItem({
126
124
  }
127
125
  }, [isFolder, actualIsOpen, file.children, file.path, onLoadChildren, isLoadingChildren, attempted]);
128
126
 
127
+ /**
128
+ * The row as a drag source and a drop target.
129
+ *
130
+ * The row's own identity is what both roles need: a drop on a FILE lands in
131
+ * that file's directory — the same rule a paste obeys (`pasteTargetDir`) — so
132
+ * a drop beside a file is a real destination rather than an invisible one.
133
+ * The handlers themselves live in the hook, which owns the two platform facts
134
+ * they depend on (see `useFileRowDrag`).
135
+ */
136
+ const target: ClipboardTarget = {
137
+ path: file.path,
138
+ name: file.name,
139
+ kind: isFolder ? 'folder' : 'file',
140
+ };
141
+
129
142
  const actions = useFileActions({
130
143
  file: { path: file.path, name: file.name, basePath, rootPath, repo },
131
144
  diff: { staged: gitChange?.staged || (gitChange?.status ? gitChange.status[0] !== ' ' && gitChange.status[0] !== '?' : false), status: gitStatusInfo?.charStatus },
@@ -133,6 +146,13 @@ export function FileTreeItem({
133
146
  onActionComplete,
134
147
  onCreated,
135
148
  onRenamed,
149
+ // A collapsed chain row's label names directories that are not rows, so an
150
+ // unfold is the only way to reach the ones inside it.
151
+ onUnfold: onUnfold && isChainRow({ type: isFolder ? 'folder' : 'file', name: file.name }) ? () => onUnfold(target) : undefined,
152
+ // An UNFOLDED chain draws `dev` → `src` → `main` → `code`, and folding is
153
+ // asked for on the row that starts it: the outermost level named by the
154
+ // chain the listing actually folded.
155
+ onFold: onFold && foldRoots?.has(file.path) ? () => onFold(foldRoots.get(file.path)!) : undefined,
136
156
  clipboard,
137
157
  isFolder,
138
158
  });
@@ -182,72 +202,36 @@ export function FileTreeItem({
182
202
  actions.openContextMenu(e.clientX, e.clientY);
183
203
  };
184
204
 
185
- /**
186
- * The row as a drag source and a drop target.
187
- *
188
- * The row's own identity is what both roles need: a drop on a FILE lands in
189
- * that file's directory — the same rule a paste obeys (`pasteTargetDir`) — so
190
- * a drop beside a file is a real destination rather than an invisible one.
191
- * The handlers themselves live in the hook, which owns the two platform facts
192
- * they depend on (see `useFileRowDrag`).
193
- */
194
- const target: ClipboardTarget = {
195
- path: file.path,
196
- name: file.name,
197
- kind: isFolder ? 'folder' : 'file',
198
- };
199
- const drag = useFileRowDrag({ target, dragging, clipboard, onDragStart, onDragEnd, onDropOn });
205
+ const drag = useFileRowDrag({ target, dragging, clipboard, onDragStart, onDragEnd, onDropOn, onHoverAccept: onUnfold });
200
206
 
201
207
  return (
202
208
  <div>
203
209
  <div
204
210
  className={`flex items-center space-x-1.5 py-1 px-2 hover:bg-ink/5 cursor-pointer rounded group select-none ${
205
211
  drag.isDragging ? 'opacity-40' : ''
206
- } ${drag.acceptsDrop ? 'bg-info/10 ring-1 ring-info/40 ring-inset' : ''}`}
212
+ } ${drag.isDropHovered ? 'bg-info/10 ring-1 ring-info/40 ring-inset' : ''}`}
207
213
  draggable={!touch}
208
214
  onClick={handleToggle}
209
215
  onContextMenu={handleContextMenu}
210
216
  onDragStart={drag.onDragStart}
211
217
  onDragEnd={drag.onDragEnd}
212
218
  onDragOver={drag.onDragOver}
219
+ onDragLeave={drag.onDragLeave}
213
220
  onDrop={drag.onDrop}
214
221
  onTouchStart={longPress.onTouchStart}
215
222
  onTouchMove={longPress.onTouchMove}
216
223
  onTouchEnd={longPress.onTouchEnd}
217
224
  onTouchCancel={longPress.onTouchCancel}
218
225
  >
219
- {isFolder ? (
220
- actualIsOpen ? <ChevronDown size={12} className="flex-shrink-0 text-ink/40" /> : <ChevronRight size={12} className="flex-shrink-0 text-ink/40" />
221
- ) : (
222
- <span className="w-3 flex-shrink-0"></span>
223
- )}
224
-
225
- <FileIcon name={file.name} isFolder={isFolder} isOpen={actualIsOpen} size={12} className={`flex-shrink-0${isIgnored ? ' opacity-40' : ''}`} />
226
- <span
227
- className={`truncate min-w-0 flex-1 ${gitStatusInfo ? gitStatusInfo.colorClass : folderStatus ? folderStatus.colorClass : isIgnored ? 'text-ink/40' : ''}`}
228
- title={isIgnored ? `${file.path} — git-ignored` : undefined}
229
- >
230
- {file.name}
231
- </span>
232
-
233
- {gitStatusInfo && (
234
- <span
235
- className={`font-mono text-[9px] font-bold px-1 rounded flex-shrink-0 ${gitStatusInfo.colorClass}`}
236
- title={`Git: ${gitStatusInfo.label}`}
237
- >
238
- {gitStatusInfo.charStatus}
239
- </span>
240
- )}
241
-
242
- {folderStatus && (
243
- <span
244
- className={`w-1.5 h-1.5 rounded-full flex-shrink-0 ${
245
- folderStatus.hasDeleted ? 'bg-error' :
246
- folderStatus.hasModified || folderStatus.hasStaged ? 'bg-info' : 'bg-success'
247
- }`}
248
- title={`${folderStatus.count} changed file${folderStatus.count > 1 ? 's' : ''}`}
249
- />
250
- )}
226
+ <TreeRowLabel
227
+ name={file.name}
228
+ path={file.path}
229
+ isFolder={isFolder}
230
+ isOpen={actualIsOpen}
231
+ ignored={isIgnored}
232
+ gitStatus={gitStatusInfo}
233
+ folderStatus={folderStatus}
234
+ />
251
235
  </div>
252
236
 
253
237
  {actualIsOpen && isLoadingChildren && (
@@ -277,6 +261,9 @@ export function FileTreeItem({
277
261
  onDragStart={onDragStart}
278
262
  onDragEnd={onDragEnd}
279
263
  onDropOn={onDropOn}
264
+ onUnfold={onUnfold}
265
+ onFold={onFold}
266
+ foldRoots={foldRoots}
280
267
  touch={touch}
281
268
  />
282
269
  ))}
@@ -290,6 +277,8 @@ export function FileTreeItem({
290
277
  isFolder={isFolder}
291
278
  hasGitStatus={hasGitStatus}
292
279
  pasteLabel={actions.pasteLabel}
280
+ chainLabel={actions.chainLabel}
281
+ foldable={actions.foldable}
293
282
  busy={actions.busy}
294
283
  onAction={actions.handleAction}
295
284
  />
@@ -324,6 +313,7 @@ export function FileTreeItem({
324
313
  isFolder={isFolder}
325
314
  renameValue={actions.renameValue}
326
315
  originalPath={file.path}
316
+ displayName={isChainRow({ type: isFolder ? 'folder' : 'file', name: file.name }) ? file.name : undefined}
327
317
  error={actions.renameError}
328
318
  isLoading={actions.busy}
329
319
  onChange={actions.setRenameValue}