@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,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Confirmation for deleting a project.
|
|
8
|
+
*
|
|
9
|
+
* The trash button used to run the delete straight away, and a refusal (the
|
|
10
|
+
* last project, a missing id) went to `console.error` — so the row could vanish
|
|
11
|
+
* from the list on screen while the folder was still there. The dialog names
|
|
12
|
+
* what disappears before anything is removed, and renders a refusal in place.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { useEffect } from 'preact/hooks';
|
|
16
|
+
import { AlertTriangle, Loader2, Trash2 } from 'lucide-preact';
|
|
17
|
+
import { Modal } from '@/client/components/common/Modal';
|
|
18
|
+
import type { ProjectConfigItem } from '@/shared/types';
|
|
19
|
+
|
|
20
|
+
interface DeleteProjectModalProps {
|
|
21
|
+
project: ProjectConfigItem | null;
|
|
22
|
+
isDeleting: boolean;
|
|
23
|
+
error: string | null;
|
|
24
|
+
onClose: () => void;
|
|
25
|
+
onConfirm: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function DeleteProjectModal({
|
|
29
|
+
project,
|
|
30
|
+
isDeleting,
|
|
31
|
+
error,
|
|
32
|
+
onClose,
|
|
33
|
+
onConfirm,
|
|
34
|
+
}: DeleteProjectModalProps) {
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const handler = (e: globalThis.KeyboardEvent) => {
|
|
37
|
+
if (e.key !== 'Escape' || isDeleting) return;
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
onClose();
|
|
40
|
+
};
|
|
41
|
+
window.addEventListener('keydown', handler);
|
|
42
|
+
return () => window.removeEventListener('keydown', handler);
|
|
43
|
+
}, [onClose, isDeleting]);
|
|
44
|
+
|
|
45
|
+
if (!project) return null;
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Modal
|
|
49
|
+
onClose={isDeleting ? () => {} : onClose}
|
|
50
|
+
zClass="z-[70]"
|
|
51
|
+
maxWidthClass="max-w-[440px]"
|
|
52
|
+
ariaLabel="Delete project"
|
|
53
|
+
header={
|
|
54
|
+
<div className="flex items-center gap-3 min-w-0">
|
|
55
|
+
<Trash2 size={16} className="text-error shrink-0" />
|
|
56
|
+
<div className="min-w-0">
|
|
57
|
+
<h2 className="text-sm font-semibold text-ink">Delete project?</h2>
|
|
58
|
+
<p className="text-[11px] text-ink/50 truncate">{project.name}</p>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
}
|
|
62
|
+
footer={
|
|
63
|
+
<div className="flex items-center justify-end gap-2 px-5 py-3.5 border-t border-ink/10">
|
|
64
|
+
<button
|
|
65
|
+
type="button"
|
|
66
|
+
onClick={onClose}
|
|
67
|
+
disabled={isDeleting}
|
|
68
|
+
className="px-3.5 py-1.5 rounded-md border border-ink/20 text-xs font-medium text-ink hover:bg-ink/5 transition-colors cursor-pointer disabled:opacity-50"
|
|
69
|
+
>
|
|
70
|
+
Cancel
|
|
71
|
+
</button>
|
|
72
|
+
<button
|
|
73
|
+
type="button"
|
|
74
|
+
onClick={onConfirm}
|
|
75
|
+
disabled={isDeleting}
|
|
76
|
+
className="px-3.5 py-1.5 rounded-md bg-error text-canvas text-xs font-medium hover:opacity-90 transition-opacity cursor-pointer disabled:opacity-50 flex items-center gap-1.5"
|
|
77
|
+
>
|
|
78
|
+
{isDeleting ? <Loader2 size={13} className="animate-spin" /> : <Trash2 size={13} />}
|
|
79
|
+
<span>{isDeleting ? 'Deleting…' : 'Delete project'}</span>
|
|
80
|
+
</button>
|
|
81
|
+
</div>
|
|
82
|
+
}
|
|
83
|
+
>
|
|
84
|
+
<div className="px-5 py-4 space-y-3">
|
|
85
|
+
<ul className="text-[11.5px] leading-relaxed text-ink/70 space-y-1.5">
|
|
86
|
+
<li>
|
|
87
|
+
The workspace is unregistered from Kabmo — its place in the sidebar, its chats' grouping and
|
|
88
|
+
its settings go.
|
|
89
|
+
</li>
|
|
90
|
+
<li>
|
|
91
|
+
{project.path
|
|
92
|
+
? 'The directory itself is NOT deleted; a tombstone keeps omp discovery from re-adding it on the next boot.'
|
|
93
|
+
: 'It has no directory, so nothing on disk is touched.'}
|
|
94
|
+
</li>
|
|
95
|
+
<li>Chat transcripts stay on disk under ~/.omp/agent/sessions.</li>
|
|
96
|
+
</ul>
|
|
97
|
+
|
|
98
|
+
{error && (
|
|
99
|
+
<div className="flex items-start gap-2 px-3 py-2 rounded-md border border-error/30 bg-error/5 text-[11px] text-ink/75">
|
|
100
|
+
<AlertTriangle size={13} className="mt-0.5 shrink-0 text-error" />
|
|
101
|
+
<span>{error}</span>
|
|
102
|
+
</div>
|
|
103
|
+
)}
|
|
104
|
+
</div>
|
|
105
|
+
</Modal>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { AccentColorOption, ProjectConfigItem } from '@/shared/types';
|
|
2
|
+
import type { ProjectModelChoice } from '@/client/hooks/settings/projects';
|
|
2
3
|
import { ProjectDetailsHeader } from '@/client/components/settings/categories/project-settings/DetailsHeader';
|
|
3
4
|
import { ProjectNameInput } from '@/client/components/settings/categories/project-settings/NameInput';
|
|
5
|
+
import { ProjectPathField } from '@/client/components/settings/categories/project-settings/PathField';
|
|
4
6
|
import { ProjectModelDropdown } from '@/client/components/settings/categories/project-settings/ModelDropdown';
|
|
5
7
|
import { ProjectAccentPalette } from '@/client/components/settings/categories/project-settings/AccentPalette';
|
|
6
8
|
import { ProjectIconGrid } from '@/client/components/settings/categories/project-settings/IconGrid';
|
|
@@ -8,63 +10,77 @@ import { ProjectIconGrid } from '@/client/components/settings/categories/project
|
|
|
8
10
|
interface ProjectDetailsFormProps {
|
|
9
11
|
project: ProjectConfigItem;
|
|
10
12
|
canDelete: boolean;
|
|
13
|
+
isDeleting?: boolean;
|
|
14
|
+
isRevealing?: boolean;
|
|
15
|
+
models: ProjectModelChoice[];
|
|
16
|
+
accentColorOptions?: AccentColorOption[];
|
|
11
17
|
onUpdateField: <K extends keyof ProjectConfigItem>(field: K, value: ProjectConfigItem[K]) => void;
|
|
18
|
+
/** A multi-field write (the icon's two halves go in one request). */
|
|
19
|
+
onUpdateFields: (fields: Partial<ProjectConfigItem>) => void;
|
|
20
|
+
onReveal: () => void;
|
|
12
21
|
onDeleteProject: () => void;
|
|
13
|
-
availableModels?: string[];
|
|
14
|
-
accentColorOptions?: AccentColorOption[];
|
|
15
22
|
}
|
|
16
23
|
|
|
24
|
+
/** The right-hand pane of Settings → Projects: identity, defaults, appearance.
|
|
25
|
+
* It does not own the scroll: the pane scrolls as one column so the worktree
|
|
26
|
+
* section below it is reachable instead of being clipped by a nested list. */
|
|
17
27
|
export function ProjectDetailsForm({
|
|
18
28
|
project,
|
|
19
29
|
canDelete,
|
|
30
|
+
isDeleting = false,
|
|
31
|
+
isRevealing = false,
|
|
32
|
+
models,
|
|
33
|
+
accentColorOptions,
|
|
20
34
|
onUpdateField,
|
|
35
|
+
onUpdateFields,
|
|
36
|
+
onReveal,
|
|
21
37
|
onDeleteProject,
|
|
22
|
-
availableModels,
|
|
23
|
-
accentColorOptions,
|
|
24
38
|
}: ProjectDetailsFormProps) {
|
|
25
39
|
return (
|
|
26
|
-
<div className="
|
|
27
|
-
{/* 1. Header with title, full path, and delete button */}
|
|
40
|
+
<div className="p-6 md:p-8 space-y-7">
|
|
28
41
|
<ProjectDetailsHeader
|
|
29
42
|
project={project}
|
|
30
43
|
canDelete={canDelete}
|
|
44
|
+
isDeleting={isDeleting}
|
|
31
45
|
onDelete={onDeleteProject}
|
|
32
46
|
/>
|
|
33
47
|
|
|
34
|
-
{/* 2. Project Name Input */}
|
|
35
48
|
<ProjectNameInput
|
|
36
49
|
name={project.name}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
50
|
+
onCommit={(name) => onUpdateField('name', name)}
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
<ProjectPathField
|
|
54
|
+
path={project.path}
|
|
55
|
+
onCommit={(path) => onUpdateField('path', path)}
|
|
56
|
+
onReveal={onReveal}
|
|
57
|
+
isRevealing={isRevealing}
|
|
45
58
|
/>
|
|
46
59
|
|
|
47
|
-
{/* 3. Defaults for new chats (Model selection) */}
|
|
48
60
|
<ProjectModelDropdown
|
|
49
61
|
model={project.model}
|
|
50
|
-
|
|
51
|
-
|
|
62
|
+
models={models}
|
|
63
|
+
onSelectModel={(value) => onUpdateField('model', value)}
|
|
52
64
|
/>
|
|
53
65
|
|
|
54
|
-
{/* 4. Accent Color Palette */}
|
|
55
66
|
<ProjectAccentPalette
|
|
56
67
|
accentColor={project.accentColor}
|
|
57
|
-
onSelectColor={(
|
|
58
|
-
|
|
68
|
+
onSelectColor={(color) => onUpdateField('accentColor', color)}
|
|
69
|
+
{...(accentColorOptions && accentColorOptions.length > 0 ? { options: accentColorOptions } : {})}
|
|
59
70
|
/>
|
|
60
71
|
|
|
61
|
-
{/*
|
|
72
|
+
{/* The icon is TWO fields and one write: `icon` says which glyph, and
|
|
73
|
+
`customIconUrl` carries the image. Sent as two PATCHes they race and the
|
|
74
|
+
slower answer wins, which showed up as an uploaded icon that reverted. */}
|
|
62
75
|
<ProjectIconGrid
|
|
63
76
|
currentIcon={project.icon}
|
|
64
77
|
customIconUrl={project.customIconUrl}
|
|
65
78
|
projectName={project.name}
|
|
66
|
-
onSelectIcon={(iconId) =>
|
|
67
|
-
onSetCustomIcon={(url) =>
|
|
79
|
+
onSelectIcon={(iconId) => onUpdateFields({ icon: iconId, customIconUrl: undefined })}
|
|
80
|
+
onSetCustomIcon={(url) => onUpdateFields({
|
|
81
|
+
customIconUrl: url,
|
|
82
|
+
icon: url === undefined ? 'default' : 'custom',
|
|
83
|
+
})}
|
|
68
84
|
/>
|
|
69
85
|
</div>
|
|
70
86
|
);
|
|
@@ -4,22 +4,30 @@ import type { ProjectConfigItem } from '@/shared/types';
|
|
|
4
4
|
interface ProjectDetailsHeaderProps {
|
|
5
5
|
project: ProjectConfigItem;
|
|
6
6
|
canDelete: boolean;
|
|
7
|
+
isDeleting?: boolean;
|
|
7
8
|
onDelete: () => void;
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The detail pane's title block.
|
|
13
|
+
*
|
|
14
|
+
* The path used to live here as read-only text; it is an EDITABLE field now
|
|
15
|
+
* (`PathField`), because a project bound to the wrong directory had to be
|
|
16
|
+
* deleted and re-created to fix it. What stays here is identity plus the one
|
|
17
|
+
* destructive action, named in full so it cannot be mistaken for "close".
|
|
18
|
+
*/
|
|
10
19
|
export function ProjectDetailsHeader({
|
|
11
20
|
project,
|
|
12
21
|
canDelete,
|
|
22
|
+
isDeleting = false,
|
|
13
23
|
onDelete,
|
|
14
24
|
}: ProjectDetailsHeaderProps) {
|
|
15
25
|
return (
|
|
16
26
|
<div className="flex items-start justify-between gap-4 pb-4 border-b border-ink/10">
|
|
17
27
|
<div className="min-w-0 flex-1">
|
|
18
|
-
<h2 className="text-xl font-bold tracking-tight text-ink truncate">
|
|
19
|
-
{project.name}
|
|
20
|
-
</h2>
|
|
28
|
+
<h2 className="text-xl font-bold tracking-tight text-ink truncate">{project.name}</h2>
|
|
21
29
|
<p className="text-[11px] font-mono text-ink/50 truncate mt-0.5 select-all">
|
|
22
|
-
{project.path}
|
|
30
|
+
{project.path || 'Not bound to a directory'}
|
|
23
31
|
</p>
|
|
24
32
|
</div>
|
|
25
33
|
|
|
@@ -27,10 +35,12 @@ export function ProjectDetailsHeader({
|
|
|
27
35
|
<button
|
|
28
36
|
type="button"
|
|
29
37
|
onClick={onDelete}
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
disabled={isDeleting}
|
|
39
|
+
title="Delete this project"
|
|
40
|
+
className="inline-flex items-center gap-1.5 shrink-0 px-2.5 py-1.5 text-[11px] font-medium text-ink/50 hover:text-error hover:bg-error/10 rounded-md transition-colors cursor-pointer disabled:opacity-50"
|
|
32
41
|
>
|
|
33
|
-
<Trash2 size={
|
|
42
|
+
<Trash2 size={13} />
|
|
43
|
+
<span>Delete</span>
|
|
34
44
|
</button>
|
|
35
45
|
)}
|
|
36
46
|
</div>
|
|
@@ -1,37 +1,94 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The project's icon: the shared glyph set, a file upload, and a generated mark.
|
|
8
|
+
*
|
|
9
|
+
* Three things this has to get right, each of which used to fail silently:
|
|
10
|
+
*
|
|
11
|
+
* 1. **The icon is TWO fields (`icon` + `customIconUrl`) and they are ONE
|
|
12
|
+
* write.** Sent as two PATCHes they race and the slower response wins, so an
|
|
13
|
+
* uploaded image appeared, saved, and then reverted to the previous icon.
|
|
14
|
+
* `onSetCustomIcon` carries both facts through one request.
|
|
15
|
+
* 2. **A normal photo is not an error.** A phone picture is several MB, which
|
|
16
|
+
* the old 512 KiB ceiling refused outright. The bytes are downscaled in the
|
|
17
|
+
* browser to a 128px mark first, which is what a sidebar row can draw
|
|
18
|
+
* anyway; only an image that cannot be decoded is refused.
|
|
19
|
+
* 3. **A URL is saved only after it LOADS.** The "generate" mark used to be
|
|
20
|
+
* persisted unverified, so an offline or blocked request replaced the icon
|
|
21
|
+
* with a broken image.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { useRef, useState } from 'preact/hooks';
|
|
2
25
|
import type { ChangeEvent } from 'preact/compat';
|
|
3
|
-
import {
|
|
26
|
+
import { Dice5, Loader2, Upload, X } from 'lucide-preact';
|
|
27
|
+
import { PROJECT_ICON_OPTIONS } from '@/shared/lib/workspace/project-icon';
|
|
4
28
|
|
|
5
29
|
interface ProjectIconGridProps {
|
|
6
30
|
currentIcon: string;
|
|
7
31
|
customIconUrl?: string;
|
|
8
32
|
projectName: string;
|
|
33
|
+
/** Choose a built-in glyph. Clears any custom icon in the same write. */
|
|
9
34
|
onSelectIcon: (iconId: string) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Set (or clear, with `undefined`) the custom mark. The caller writes BOTH
|
|
37
|
+
* `customIconUrl` and the `icon` discriminator in one request.
|
|
38
|
+
*/
|
|
10
39
|
onSetCustomIcon: (url: string | undefined) => void;
|
|
40
|
+
disabled?: boolean;
|
|
11
41
|
}
|
|
12
42
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
/** The side of the mark a sidebar row and this grid draw. */
|
|
44
|
+
const MARK_PX = 128;
|
|
45
|
+
|
|
46
|
+
/** The longest edge the stored data URL may carry (~512 KiB of bytes). */
|
|
47
|
+
const MAX_MARK_CHARS = 700_000;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
Read an image file into a square-ish mark as a PNG data URL.
|
|
51
|
+
|
|
52
|
+
SVG is passed through untouched — it is already a vector and rasterizing it
|
|
53
|
+
would lose quality — and a raster is downscaled to `MARK_PX`, which is smaller
|
|
54
|
+
than any photo and far smaller than the 512 KiB the server accepts. Rejects when
|
|
55
|
+
the browser cannot decode the file, which is the only genuinely unusable case.
|
|
56
|
+
*/
|
|
57
|
+
async function fileToIconMark(file: File): Promise<string> {
|
|
58
|
+
const readable = Promise.withResolvers<string>();
|
|
59
|
+
const reader = new FileReader();
|
|
60
|
+
reader.onload = (event) => {
|
|
61
|
+
const result = event.target?.result;
|
|
62
|
+
if (typeof result === 'string' && result) readable.resolve(result);
|
|
63
|
+
else readable.reject(new Error('That file could not be read as an image.'));
|
|
64
|
+
};
|
|
65
|
+
reader.onerror = () => readable.reject(new Error('That file could not be read as an image.'));
|
|
66
|
+
reader.readAsDataURL(file);
|
|
67
|
+
const asDataUrl = await readable.promise;
|
|
68
|
+
|
|
69
|
+
// A vector needs no resampling, and a GIF loses its animation either way.
|
|
70
|
+
if (file.type === 'image/svg+xml') return asDataUrl;
|
|
71
|
+
|
|
72
|
+
const decoded = Promise.withResolvers<HTMLImageElement>();
|
|
73
|
+
const image = new Image();
|
|
74
|
+
image.onload = () => decoded.resolve(image);
|
|
75
|
+
image.onerror = () => decoded.reject(new Error('That file is not an image Kabmo can read.'));
|
|
76
|
+
image.src = asDataUrl;
|
|
77
|
+
const loaded = await decoded.promise;
|
|
78
|
+
|
|
79
|
+
const scale = Math.min(1, MARK_PX / Math.max(loaded.naturalWidth, loaded.naturalHeight));
|
|
80
|
+
const width = Math.max(1, Math.round(loaded.naturalWidth * scale));
|
|
81
|
+
const height = Math.max(1, Math.round(loaded.naturalHeight * scale));
|
|
82
|
+
const canvas = document.createElement('canvas');
|
|
83
|
+
canvas.width = width;
|
|
84
|
+
canvas.height = height;
|
|
85
|
+
const context = canvas.getContext('2d');
|
|
86
|
+
if (!context) return asDataUrl;
|
|
87
|
+
context.drawImage(loaded, 0, 0, width, height);
|
|
88
|
+
const scaled = canvas.toDataURL('image/png');
|
|
89
|
+
// A downscale that somehow grew (a tiny source re-encoded) keeps the original.
|
|
90
|
+
return scaled.length > 0 && scaled.length < asDataUrl.length ? scaled : asDataUrl;
|
|
91
|
+
}
|
|
35
92
|
|
|
36
93
|
export function ProjectIconGrid({
|
|
37
94
|
currentIcon,
|
|
@@ -39,67 +96,88 @@ export function ProjectIconGrid({
|
|
|
39
96
|
projectName,
|
|
40
97
|
onSelectIcon,
|
|
41
98
|
onSetCustomIcon,
|
|
99
|
+
disabled = false,
|
|
42
100
|
}: ProjectIconGridProps) {
|
|
43
101
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
102
|
+
const [isGenerating, setIsGenerating] = useState(false);
|
|
103
|
+
const [isReading, setIsReading] = useState(false);
|
|
104
|
+
const [error, setError] = useState<string | null>(null);
|
|
44
105
|
|
|
45
|
-
const handleFileUpload = (e: ChangeEvent<HTMLInputElement>) => {
|
|
106
|
+
const handleFileUpload = async (e: ChangeEvent<HTMLInputElement>) => {
|
|
46
107
|
const file = e.currentTarget.files?.[0];
|
|
108
|
+
// Cleared immediately so picking the SAME file twice still fires a change.
|
|
109
|
+
e.currentTarget.value = '';
|
|
47
110
|
if (!file) return;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
|
|
111
|
+
setError(null);
|
|
112
|
+
setIsReading(true);
|
|
113
|
+
try {
|
|
114
|
+
const mark = await fileToIconMark(file);
|
|
115
|
+
if (mark.length > MAX_MARK_CHARS) {
|
|
116
|
+
setError('That image is too detailed to store as a mark — try a PNG or SVG.');
|
|
117
|
+
return;
|
|
55
118
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
119
|
+
onSetCustomIcon(mark);
|
|
120
|
+
} catch (cause) {
|
|
121
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
122
|
+
} finally {
|
|
123
|
+
setIsReading(false);
|
|
124
|
+
}
|
|
59
125
|
};
|
|
60
126
|
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
127
|
+
const handleGenerate = () => {
|
|
128
|
+
const seed = projectName.toLowerCase().replace(/[^a-z0-9]/g, '') || 'project';
|
|
129
|
+
const url = `https://api.dicebear.com/7.x/identicon/svg?seed=${seed}&radius=50&size=${MARK_PX}`;
|
|
130
|
+
setError(null);
|
|
131
|
+
setIsGenerating(true);
|
|
132
|
+
// Verify the mark loads before saving it: a blocked or offline request must
|
|
133
|
+
// not overwrite the icon with a URL that renders as nothing.
|
|
134
|
+
const probe = new Image();
|
|
135
|
+
probe.onload = () => {
|
|
136
|
+
setIsGenerating(false);
|
|
137
|
+
onSetCustomIcon(url);
|
|
138
|
+
};
|
|
139
|
+
probe.onerror = () => {
|
|
140
|
+
setIsGenerating(false);
|
|
141
|
+
setError('The generated icon could not be loaded — check your connection.');
|
|
142
|
+
};
|
|
143
|
+
probe.src = url;
|
|
67
144
|
};
|
|
68
145
|
|
|
146
|
+
const busy = disabled || isReading || isGenerating;
|
|
147
|
+
|
|
69
148
|
return (
|
|
70
149
|
<div className="space-y-3">
|
|
71
|
-
<div className="flex items-center justify-between">
|
|
72
|
-
<h4 className="text-xs font-semibold text-ink">Project
|
|
150
|
+
<div className="flex items-center justify-between gap-2">
|
|
151
|
+
<h4 className="text-xs font-semibold text-ink">Project icon</h4>
|
|
73
152
|
{customIconUrl && (
|
|
74
153
|
<button
|
|
75
154
|
type="button"
|
|
76
155
|
onClick={() => onSetCustomIcon(undefined)}
|
|
77
|
-
|
|
156
|
+
disabled={busy}
|
|
157
|
+
className="text-[11px] text-ink/50 hover:text-error transition-colors cursor-pointer disabled:opacity-50"
|
|
78
158
|
>
|
|
79
|
-
|
|
159
|
+
Use a standard icon
|
|
80
160
|
</button>
|
|
81
161
|
)}
|
|
82
162
|
</div>
|
|
83
163
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{AVAILABLE_ICONS.map((item) => {
|
|
164
|
+
<div className="flex flex-wrap gap-1.5">
|
|
165
|
+
{PROJECT_ICON_OPTIONS.map((item) => {
|
|
87
166
|
const isSelected = !customIconUrl && currentIcon === item.id;
|
|
88
167
|
const IconComp = item.icon;
|
|
89
|
-
|
|
90
168
|
return (
|
|
91
169
|
<button
|
|
92
170
|
key={item.id}
|
|
93
171
|
type="button"
|
|
94
|
-
onClick={() =>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
172
|
+
onClick={() => onSelectIcon(item.id)}
|
|
173
|
+
disabled={busy}
|
|
174
|
+
aria-label={item.label}
|
|
175
|
+
aria-pressed={isSelected}
|
|
98
176
|
title={item.label}
|
|
99
|
-
className={`w-7 h-7 rounded-md flex items-center justify-center transition-all cursor-pointer ${
|
|
177
|
+
className={`w-7 h-7 rounded-md flex items-center justify-center transition-all cursor-pointer disabled:opacity-50 ${
|
|
100
178
|
isSelected
|
|
101
179
|
? 'border border-ink/40 bg-ink/5 text-ink shadow-2xs'
|
|
102
|
-
: 'text-ink/60 hover:text-ink hover:bg-ink/5'
|
|
180
|
+
: 'border border-transparent text-ink/60 hover:text-ink hover:bg-ink/5'
|
|
103
181
|
}`}
|
|
104
182
|
>
|
|
105
183
|
<IconComp size={14} strokeWidth={1.8} />
|
|
@@ -108,45 +186,62 @@ export function ProjectIconGrid({
|
|
|
108
186
|
})}
|
|
109
187
|
</div>
|
|
110
188
|
|
|
111
|
-
|
|
112
|
-
<div className="flex items-center gap-2 pt-1">
|
|
189
|
+
<div className="flex flex-wrap items-center gap-2 pt-1">
|
|
113
190
|
<input
|
|
114
191
|
type="file"
|
|
115
192
|
ref={fileInputRef}
|
|
116
|
-
onChange={handleFileUpload}
|
|
117
|
-
accept="image
|
|
193
|
+
onChange={(event) => void handleFileUpload(event)}
|
|
194
|
+
accept="image/png,image/jpeg,image/svg+xml,image/webp,image/gif"
|
|
118
195
|
className="hidden"
|
|
119
196
|
/>
|
|
120
197
|
<button
|
|
121
198
|
type="button"
|
|
122
199
|
onClick={() => fileInputRef.current?.click()}
|
|
123
|
-
|
|
200
|
+
disabled={busy}
|
|
201
|
+
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md border border-ink/20 hover:border-ink/40 bg-paper text-ink text-xs font-medium transition-colors cursor-pointer shadow-2xs disabled:opacity-50"
|
|
124
202
|
>
|
|
125
|
-
<Upload size={13} className="text-ink/60" />
|
|
126
|
-
<span>
|
|
203
|
+
{isReading ? <Loader2 size={13} className="animate-spin text-ink/60" /> : <Upload size={13} className="text-ink/60" />}
|
|
204
|
+
<span>{isReading ? 'Reading…' : 'Upload image'}</span>
|
|
127
205
|
</button>
|
|
128
206
|
|
|
129
207
|
<button
|
|
130
208
|
type="button"
|
|
131
|
-
onClick={
|
|
132
|
-
|
|
209
|
+
onClick={handleGenerate}
|
|
210
|
+
disabled={busy}
|
|
211
|
+
title="Generate a stable identicon from the project name"
|
|
212
|
+
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-md border border-ink/20 hover:border-ink/40 bg-paper text-ink text-xs font-medium transition-colors cursor-pointer shadow-2xs disabled:opacity-50"
|
|
133
213
|
>
|
|
134
|
-
<
|
|
135
|
-
<span>
|
|
214
|
+
{isGenerating ? <Loader2 size={13} className="animate-spin text-ink/60" /> : <Dice5 size={13} className="text-ink/60" />}
|
|
215
|
+
<span>{isGenerating ? 'Generating…' : 'Generate mark'}</span>
|
|
136
216
|
</button>
|
|
137
217
|
|
|
138
218
|
{customIconUrl && (
|
|
139
|
-
<div className="flex items-center gap-2 ml-
|
|
219
|
+
<div className="flex items-center gap-2 ml-1 pl-2 border-l border-ink/10">
|
|
140
220
|
<img
|
|
141
221
|
src={customIconUrl}
|
|
142
|
-
alt="
|
|
222
|
+
alt="Current custom icon"
|
|
143
223
|
className="w-5 h-5 rounded-xs object-contain border border-ink/15"
|
|
144
224
|
referrerPolicy="no-referrer"
|
|
145
225
|
/>
|
|
146
|
-
<span className="text-[11px] text-ink/60">Custom
|
|
226
|
+
<span className="text-[11px] text-ink/60">Custom icon in use</span>
|
|
227
|
+
<button
|
|
228
|
+
type="button"
|
|
229
|
+
onClick={() => onSetCustomIcon(undefined)}
|
|
230
|
+
disabled={busy}
|
|
231
|
+
aria-label="Remove the custom icon"
|
|
232
|
+
className="p-0.5 rounded text-ink/40 hover:text-error transition-colors cursor-pointer disabled:opacity-50"
|
|
233
|
+
>
|
|
234
|
+
<X size={12} />
|
|
235
|
+
</button>
|
|
147
236
|
</div>
|
|
148
237
|
)}
|
|
149
238
|
</div>
|
|
239
|
+
|
|
240
|
+
<p className="text-[11px] text-ink/50">
|
|
241
|
+
Any image works — it is scaled down to a {MARK_PX}px mark. PNG, JPEG, WebP, GIF or SVG.
|
|
242
|
+
</p>
|
|
243
|
+
|
|
244
|
+
{error && <p className="text-[11px] text-error">{error}</p>}
|
|
150
245
|
</div>
|
|
151
246
|
);
|
|
152
247
|
}
|