@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,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The Skills Catalog's git actions: sources, inspection and install.
|
|
8
|
+
*
|
|
9
|
+
* Split from the skill CRUD route (which is already the largest module in
|
|
10
|
+
* `settings/`) because these two families answer different questions. A CRUD
|
|
11
|
+
* request names a skill Kabmo already discovered; a catalog request names a
|
|
12
|
+
* repository Kabmo has never seen, and its answer is a LIST of skills plus what
|
|
13
|
+
* the server refuses to install.
|
|
14
|
+
*
|
|
15
|
+
* Three refusals are load-bearing:
|
|
16
|
+
*
|
|
17
|
+
* - **A duplicate repository is a 409, not a second card.** Two cards for one
|
|
18
|
+
* repository mean two `skillCount`s and two scan buttons that disagree.
|
|
19
|
+
* - **A project install with no workspace is refused**, never redirected to the
|
|
20
|
+
* user root: the user picked a scope, and landing the files elsewhere is how a
|
|
21
|
+
* skill "vanishes" from the list being viewed.
|
|
22
|
+
* - **A registry install is one `bunx skills add --skill <name>` per picked
|
|
23
|
+
* skill**, and a failure is reported per skill. The CLI has no batch form that
|
|
24
|
+
* names individual skills, and an unscoped add installs the whole repository
|
|
25
|
+
* (measured: 20 directories for one click).
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { json } from '@/server/lib/remix-compat';
|
|
29
|
+
import { isMockMode } from '@/server/mock.server';
|
|
30
|
+
import type { DiscoveryScope } from '@/server/lib/omp/config/scope';
|
|
31
|
+
import type { SkillCatalogSource } from '@/shared/types';
|
|
32
|
+
import { DEFAULT_CATALOG_SKILLS } from '@/client/data/settings/skill';
|
|
33
|
+
import { searchSkillCatalog, toCatalogSkills, installCatalogSkill } from '@/server/lib/omp/config/skills-catalog';
|
|
34
|
+
import { inspectSkillRepo, toSkillRepoRef } from '@/server/lib/omp/config/skills-git-repo';
|
|
35
|
+
import { installSkillCopies } from '@/server/lib/omp/config/skills-git-install';
|
|
36
|
+
import { readCatalogSources, writeCatalogSources } from '@/server/lib/omp/config/skill-sources';
|
|
37
|
+
import type { DbClient } from '@/server/lib/db/client';
|
|
38
|
+
import { reloadLiveSessions } from '@/server/lib/omp/session/reload.server';
|
|
39
|
+
|
|
40
|
+
export interface CatalogDeps {
|
|
41
|
+
db: DbClient;
|
|
42
|
+
scope: DiscoveryScope;
|
|
43
|
+
/**
|
|
44
|
+
* True only when the request actually NAMED a workspace root.
|
|
45
|
+
*
|
|
46
|
+
* `resolveDiscoveryScope` answers the server's own cwd for a request with no
|
|
47
|
+
* `root` — which is correct for a read (omp is asked about the directory it
|
|
48
|
+
* would spawn in) and wrong for an install: the catalog pane sends no root, so
|
|
49
|
+
* a `project` default wrote the copied skill into the server's working
|
|
50
|
+
* directory. Measured: a UI install landed in `<repo>/.omp/skills/new-skill`
|
|
51
|
+
* while the user was looking at a user-scope list.
|
|
52
|
+
*/
|
|
53
|
+
hasWorkspace: boolean;
|
|
54
|
+
/** The live discovery list, re-read after a write. */
|
|
55
|
+
listSkills: (scope: DiscoveryScope) => Promise<{ name: string }[]>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function message(error: unknown): string {
|
|
59
|
+
return error instanceof Error ? error.message : String(error);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Handle one catalog action. Returns `null` when `type` is not a catalog action,
|
|
64
|
+
* so the caller can fall through to the skill CRUD branches.
|
|
65
|
+
*/
|
|
66
|
+
export async function runCatalogAction(body: Record<string, unknown>, deps: CatalogDeps): Promise<Response | null> {
|
|
67
|
+
const mock = isMockMode();
|
|
68
|
+
const { db, scope } = deps;
|
|
69
|
+
const type = typeof body.type === 'string' ? body.type : '';
|
|
70
|
+
|
|
71
|
+
if (type === 'add_source') {
|
|
72
|
+
const ref = toSkillRepoRef(typeof body.repo === 'string' ? body.repo : '');
|
|
73
|
+
if (!ref) return json({ error: 'Expected a git URL or an owner/repo pair' }, { status: 400 });
|
|
74
|
+
const sources = await readCatalogSources(db);
|
|
75
|
+
if (sources.some((source) => source.repo === ref.slug)) {
|
|
76
|
+
return json({ error: `${ref.slug} is already a source` }, { status: 409 });
|
|
77
|
+
}
|
|
78
|
+
const source: SkillCatalogSource = {
|
|
79
|
+
id: `custom-${Date.now().toString(36)}`,
|
|
80
|
+
name: typeof body.name === 'string' && body.name.trim() ? body.name.trim() : ref.slug,
|
|
81
|
+
repo: ref.slug,
|
|
82
|
+
skillCount: null,
|
|
83
|
+
scannedAt: null,
|
|
84
|
+
isCustom: true,
|
|
85
|
+
};
|
|
86
|
+
const updated = [...sources, source];
|
|
87
|
+
await writeCatalogSources(db, updated);
|
|
88
|
+
return json({ success: true, catalogSources: updated, source });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (type === 'remove_source') {
|
|
92
|
+
const id = typeof body.id === 'string' ? body.id : '';
|
|
93
|
+
if (!id) return json({ error: 'id is required' }, { status: 400 });
|
|
94
|
+
const sources = await readCatalogSources(db);
|
|
95
|
+
const updated = sources.filter((source) => source.id !== id);
|
|
96
|
+
if (updated.length === sources.length) return json({ error: 'Source not found' }, { status: 404 });
|
|
97
|
+
await writeCatalogSources(db, updated);
|
|
98
|
+
return json({ success: true, catalogSources: updated });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Real search over skills.sh. The Browse box used to filter the ~26 entries the
|
|
102
|
+
// loader had pre-fetched, so a query the catalog actually held answered "no
|
|
103
|
+
// skills found".
|
|
104
|
+
if (type === 'search_catalog') {
|
|
105
|
+
const query = typeof body.q === 'string' ? body.q.trim() : '';
|
|
106
|
+
if (!query) return json({ query, catalogSkills: [] });
|
|
107
|
+
if (mock) {
|
|
108
|
+
const needle = query.toLowerCase();
|
|
109
|
+
return json({
|
|
110
|
+
query,
|
|
111
|
+
catalogSkills: DEFAULT_CATALOG_SKILLS.filter((skill) =>
|
|
112
|
+
`${skill.name} ${skill.description} ${skill.repoTag}`.toLowerCase().includes(needle),
|
|
113
|
+
),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const seen = new Set<string>();
|
|
117
|
+
const catalogSkills = toCatalogSkills(await searchSkillCatalog(query, 24), 'skills-sh').filter((item) =>
|
|
118
|
+
seen.has(item.repoTag) ? false : (seen.add(item.repoTag), true),
|
|
119
|
+
);
|
|
120
|
+
return json({ query, catalogSkills });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (type === 'inspect_git_repo' || type === 'scan_source') {
|
|
124
|
+
if (mock) return json({ error: 'Repository inspection is unavailable in mock mode' }, { status: 409 });
|
|
125
|
+
|
|
126
|
+
let repo: string;
|
|
127
|
+
let previous: SkillCatalogSource[] = [];
|
|
128
|
+
let sourceId: string | null = null;
|
|
129
|
+
if (type === 'scan_source') {
|
|
130
|
+
const id = typeof body.id === 'string' ? body.id : '';
|
|
131
|
+
previous = await readCatalogSources(db);
|
|
132
|
+
const source = previous.find((candidate) => candidate.id === id);
|
|
133
|
+
if (!source) return json({ error: 'Source not found' }, { status: 404 });
|
|
134
|
+
repo = source.repo;
|
|
135
|
+
sourceId = id;
|
|
136
|
+
} else {
|
|
137
|
+
repo = typeof body.url === 'string' ? body.url : '';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const inspection = await inspectSkillRepo(repo);
|
|
141
|
+
const installed = new Set((await deps.listSkills(scope)).map((skill) => skill.name));
|
|
142
|
+
const skills = inspection.skills.map((skill) => ({ ...skill, installed: installed.has(skill.name) }));
|
|
143
|
+
if (!sourceId) return json({ ...inspection, skills });
|
|
144
|
+
|
|
145
|
+
// A stored count must come from a scan: this is the only place one is written.
|
|
146
|
+
const updated = previous.map((candidate) =>
|
|
147
|
+
candidate.id === sourceId
|
|
148
|
+
? { ...candidate, skillCount: skills.filter((skill) => skill.loadable).length, scannedAt: Date.now() }
|
|
149
|
+
: candidate,
|
|
150
|
+
);
|
|
151
|
+
await writeCatalogSources(db, updated);
|
|
152
|
+
return json({ ...inspection, skills, sourceId, catalogSources: updated });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (type === 'install_git_skills') {
|
|
156
|
+
if (mock) return json({ error: 'Skill install is unavailable in mock mode' }, { status: 409 });
|
|
157
|
+
const url = typeof body.url === 'string' ? body.url : '';
|
|
158
|
+
const paths = Array.isArray(body.paths) ? body.paths.filter((path): path is string => typeof path === 'string') : [];
|
|
159
|
+
if (paths.length === 0) return json({ error: 'Select at least one skill to install' }, { status: 400 });
|
|
160
|
+
|
|
161
|
+
if (body.mode === 'registry') {
|
|
162
|
+
const installed: string[] = [];
|
|
163
|
+
const skipped: Array<{ name: string; reason: string }> = [];
|
|
164
|
+
for (const path of paths) {
|
|
165
|
+
const name = path.split('/').pop() ?? '';
|
|
166
|
+
try {
|
|
167
|
+
// The CLI takes `owner/repo`; any accepted URL form maps to it.
|
|
168
|
+
await installCatalogSkill(toSkillRepoRef(url)?.slug ?? url.trim(), name);
|
|
169
|
+
installed.push(name);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
skipped.push({ name, reason: message(error) });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
await reloadLiveSessions();
|
|
175
|
+
return json({ repo: url, mode: 'registry', installed, skipped, skills: await deps.listSkills(scope) });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// USER by default: the catalog pane names no workspace, and a managed copy
|
|
179
|
+
// there is the skill the user owns globally. A `project` request needs a
|
|
180
|
+
// root the caller actually named.
|
|
181
|
+
const location = body.location === 'project' ? 'project' : 'user';
|
|
182
|
+
if (location === 'project' && !deps.hasWorkspace) {
|
|
183
|
+
return json({ error: 'Select a workspace to install a project skill' }, { status: 400 });
|
|
184
|
+
}
|
|
185
|
+
const outcome = await installSkillCopies(url, paths, {
|
|
186
|
+
scope: location,
|
|
187
|
+
projectDir: location === 'project' ? scope.workspace : null,
|
|
188
|
+
overwrite: body.overwrite === true,
|
|
189
|
+
});
|
|
190
|
+
if (outcome.installed.length > 0) await reloadLiveSessions();
|
|
191
|
+
return json({ repo: url, mode: 'managed_copy', ...outcome, skills: await deps.listSkills(scope) });
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The skills route's catalog-source and git-import contract.
|
|
8
|
+
*
|
|
9
|
+
* Every case here pins a request shape the client depends on and that the server
|
|
10
|
+
* used to get wrong:
|
|
11
|
+
*
|
|
12
|
+
* - **`catalogSources` used to be a write nobody read.** The client sent
|
|
13
|
+
* `{ catalogSources: [...] }`, which matched no branch and came back `400
|
|
14
|
+
* Unsupported skill action` behind a `.catch(console.error)` — so "Add your own
|
|
15
|
+
* source" reported success and changed nothing. Adding a source now has its own
|
|
16
|
+
* `type`, refuses a duplicate repository, and answers the stored list.
|
|
17
|
+
* - **A source carries no invented metadata.** `skillCount` is `null` until a
|
|
18
|
+
* scan reports a real one, and the old `stars`/`updatedAt` literals are dropped
|
|
19
|
+
* on read instead of being passed through a narrower type.
|
|
20
|
+
* - **With no query, the scope is the app root, and a project install needs a
|
|
21
|
+
* workspace.** `install_git_skills` therefore refuses rather than falling back
|
|
22
|
+
* to the user root behind the user's back.
|
|
23
|
+
* - **MOCK answers 409 for every operation that would spawn a process.** A demo
|
|
24
|
+
* install that reports success while nothing is cloned is worse than a refusal.
|
|
25
|
+
*
|
|
26
|
+
* The DB is a temp file and the agent dir a temp tree, so nothing reaches the
|
|
27
|
+
* developer's real `~/.kabmo` or `~/.omp`.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
|
|
31
|
+
import fs from 'fs';
|
|
32
|
+
import { tmpdir } from 'os';
|
|
33
|
+
import { join } from 'path';
|
|
34
|
+
import { getDb } from '@/server/db.server';
|
|
35
|
+
import { action as skillsAction, loader as skillsLoader } from '@/server/routes/settings/skills';
|
|
36
|
+
import { removeDir } from '@/test-support/remove-dir';
|
|
37
|
+
|
|
38
|
+
const API = 'http://localhost/api/settings/skills';
|
|
39
|
+
const ROOT = join(tmpdir(), 'kabmo-skill-routes-test');
|
|
40
|
+
const AGENT_DIR = join(ROOT, 'agent');
|
|
41
|
+
const WORKSPACE = join(ROOT, 'workspace');
|
|
42
|
+
const REPO = join(ROOT, 'repo');
|
|
43
|
+
|
|
44
|
+
type Handler = (args: never) => unknown;
|
|
45
|
+
|
|
46
|
+
function call(handler: Handler, request: Request): Promise<Response> {
|
|
47
|
+
return handler({ request, params: {} } as never) as Promise<Response>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function send(body: unknown): Request {
|
|
51
|
+
return new Request(API, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
body: JSON.stringify(body),
|
|
54
|
+
headers: { 'content-type': 'application/json' },
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function writeSkill(dir: string, frontmatter: string): void {
|
|
59
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
60
|
+
fs.writeFileSync(join(dir, 'SKILL.md'), `---\n${frontmatter}\n---\n\nbody\n`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
beforeAll(async () => {
|
|
64
|
+
removeDir(ROOT);
|
|
65
|
+
fs.mkdirSync(AGENT_DIR, { recursive: true });
|
|
66
|
+
fs.mkdirSync(WORKSPACE, { recursive: true });
|
|
67
|
+
writeSkill(join(REPO, 'skills', 'alpha'), 'name: alpha\ndescription: First skill');
|
|
68
|
+
writeSkill(join(REPO, 'skills', 'beta'), 'name: beta\ndescription: Second skill');
|
|
69
|
+
// A real repository: the installer clones, and a plain directory is not clonable.
|
|
70
|
+
Bun.spawnSync({ cmd: ['git', 'init', '--quiet'], cwd: REPO });
|
|
71
|
+
Bun.spawnSync({ cmd: ['git', 'add', '.'], cwd: REPO });
|
|
72
|
+
Bun.spawnSync({
|
|
73
|
+
cmd: ['git', '-c', 'user.email=t@example.com', '-c', 'user.name=t', 'commit', '-qm', 'init'],
|
|
74
|
+
cwd: REPO,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
Bun.env.PI_CODING_AGENT_DIR = AGENT_DIR;
|
|
78
|
+
Bun.env.KABMO_DB_PATH = join(ROOT, 'db.sqlite');
|
|
79
|
+
Bun.env.SYNC_WORKSPACE = 'false';
|
|
80
|
+
delete Bun.env.MOCK;
|
|
81
|
+
globalThis.__kabmoDb = undefined;
|
|
82
|
+
await getDb();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
afterAll(() => {
|
|
86
|
+
globalThis.__kabmoDb?.resolved?.raw.close();
|
|
87
|
+
globalThis.__kabmoDb = undefined;
|
|
88
|
+
delete Bun.env.PI_CODING_AGENT_DIR;
|
|
89
|
+
delete Bun.env.KABMO_DB_PATH;
|
|
90
|
+
delete Bun.env.SYNC_WORKSPACE;
|
|
91
|
+
delete Bun.env.MOCK;
|
|
92
|
+
removeDir(ROOT);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('catalog sources', () => {
|
|
96
|
+
test('the defaults report an unscanned count rather than a number', async () => {
|
|
97
|
+
const body = await (await call(skillsLoader, new Request(API))).json();
|
|
98
|
+
expect(Array.isArray(body.catalogSources)).toBe(true);
|
|
99
|
+
expect(body.catalogSources.every((source: { skillCount: unknown }) => source.skillCount === null)).toBe(true);
|
|
100
|
+
expect(body.catalogSources.some((source: { stars?: unknown }) => source.stars !== undefined)).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('adding a source stores a normalised repo slug and answers the list', async () => {
|
|
104
|
+
const res = await call(skillsAction, send({ type: 'add_source', repo: 'https://github.com/acme/skills', name: 'Acme' }));
|
|
105
|
+
expect(res.status).toBe(200);
|
|
106
|
+
const body = await res.json();
|
|
107
|
+
expect(body.source).toMatchObject({ name: 'Acme', repo: 'acme/skills', skillCount: null, isCustom: true });
|
|
108
|
+
expect(body.catalogSources.at(-1).repo).toBe('acme/skills');
|
|
109
|
+
|
|
110
|
+
const reloaded = await (await call(skillsLoader, new Request(API))).json();
|
|
111
|
+
expect(reloaded.catalogSources.at(-1).repo).toBe('acme/skills');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('the same repository twice is a 409, not a second card', async () => {
|
|
115
|
+
const res = await call(skillsAction, send({ type: 'add_source', repo: 'acme/skills' }));
|
|
116
|
+
expect(res.status).toBe(409);
|
|
117
|
+
expect((await res.json()).error).toContain('already a source');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('an unusable repo is a 400', async () => {
|
|
121
|
+
const res = await call(skillsAction, send({ type: 'add_source', repo: 'not a repo' }));
|
|
122
|
+
expect(res.status).toBe(400);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('removing a source drops it, and an unknown id is a 404', async () => {
|
|
126
|
+
const list = await (await call(skillsLoader, new Request(API))).json();
|
|
127
|
+
const id = list.catalogSources.at(-1).id;
|
|
128
|
+
const removed = await call(skillsAction, send({ type: 'remove_source', id }));
|
|
129
|
+
expect(removed.status).toBe(200);
|
|
130
|
+
expect((await removed.json()).catalogSources.some((source: { id: string }) => source.id === id)).toBe(false);
|
|
131
|
+
|
|
132
|
+
expect((await call(skillsAction, send({ type: 'remove_source', id }))).status).toBe(404);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('git inspection and install', () => {
|
|
137
|
+
test('an inspect on MOCK is refused instead of inventing a repository', async () => {
|
|
138
|
+
Bun.env.MOCK = 'true';
|
|
139
|
+
try {
|
|
140
|
+
const res = await call(skillsAction, send({ type: 'inspect_git_repo', url: REPO }));
|
|
141
|
+
expect(res.status).toBe(409);
|
|
142
|
+
} finally {
|
|
143
|
+
delete Bun.env.MOCK;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('install with no selection is a 400', async () => {
|
|
148
|
+
const res = await call(skillsAction, send({ type: 'install_git_skills', url: REPO, paths: [] }));
|
|
149
|
+
expect(res.status).toBe(400);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('a project install with no workspace is refused, not redirected to another root', async () => {
|
|
153
|
+
// `?scope=user` is the request with no workspace. A create made there while
|
|
154
|
+
// the draft says `project` must be refused: writing it to the user root
|
|
155
|
+
// instead is how a skill "vanishes" from the list the user was looking at,
|
|
156
|
+
// and writing it under the server's cwd is how a test leaked a real
|
|
157
|
+
// `<repo>/.omp/skills/alpha` once.
|
|
158
|
+
const res = await call(
|
|
159
|
+
skillsAction,
|
|
160
|
+
new Request(`${API}?scope=user`, {
|
|
161
|
+
method: 'POST',
|
|
162
|
+
body: JSON.stringify({
|
|
163
|
+
type: 'install_git_skills',
|
|
164
|
+
url: REPO,
|
|
165
|
+
paths: ['skills/alpha'],
|
|
166
|
+
mode: 'managed_copy',
|
|
167
|
+
location: 'project',
|
|
168
|
+
}),
|
|
169
|
+
headers: { 'content-type': 'application/json' },
|
|
170
|
+
}),
|
|
171
|
+
);
|
|
172
|
+
expect(res.status).toBe(400);
|
|
173
|
+
expect((await res.json()).error).toContain('workspace');
|
|
174
|
+
expect(fs.existsSync(join(AGENT_DIR, 'skills', 'alpha'))).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('a user-scope install lands in the agent dir', async () => {
|
|
178
|
+
const res = await call(
|
|
179
|
+
skillsAction,
|
|
180
|
+
new Request(`${API}?scope=user`, {
|
|
181
|
+
method: 'POST',
|
|
182
|
+
body: JSON.stringify({ type: 'install_git_skills', url: REPO, paths: ['skills/alpha'], mode: 'managed_copy', location: 'user' }),
|
|
183
|
+
headers: { 'content-type': 'application/json' },
|
|
184
|
+
}),
|
|
185
|
+
);
|
|
186
|
+
const body = await res.json();
|
|
187
|
+
expect(body.installed).toEqual(['alpha']);
|
|
188
|
+
expect(fs.existsSync(join(AGENT_DIR, 'skills', 'alpha', 'SKILL.md'))).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test('a request that names no location installs into the USER root, not the server cwd', async () => {
|
|
192
|
+
// Measured: the catalog pane sends no root and no location, and a `project`
|
|
193
|
+
// default wrote the copy into `<server cwd>/.omp/skills` — the repository
|
|
194
|
+
// Kabmo was started from — while the user was looking at a user-scope list.
|
|
195
|
+
const before = fs.existsSync(join(process.cwd(), '.omp', 'skills', 'beta'));
|
|
196
|
+
const res = await call(
|
|
197
|
+
skillsAction,
|
|
198
|
+
new Request(API, {
|
|
199
|
+
method: 'POST',
|
|
200
|
+
body: JSON.stringify({ type: 'install_git_skills', url: REPO, paths: ['skills/beta'], mode: 'managed_copy' }),
|
|
201
|
+
headers: { 'content-type': 'application/json' },
|
|
202
|
+
}),
|
|
203
|
+
);
|
|
204
|
+
expect(res.status).toBe(200);
|
|
205
|
+
expect(fs.existsSync(join(AGENT_DIR, 'skills', 'beta', 'SKILL.md'))).toBe(true);
|
|
206
|
+
expect(fs.existsSync(join(process.cwd(), '.omp', 'skills', 'beta'))).toBe(before);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('installing the same skill again is skipped with the reason', async () => {
|
|
210
|
+
const request = () =>
|
|
211
|
+
new Request(`${API}?scope=user`, {
|
|
212
|
+
method: 'POST',
|
|
213
|
+
body: JSON.stringify({ type: 'install_git_skills', url: REPO, paths: ['skills/alpha'], mode: 'managed_copy', location: 'user' }),
|
|
214
|
+
headers: { 'content-type': 'application/json' },
|
|
215
|
+
});
|
|
216
|
+
const body = await (await call(skillsAction, request())).json();
|
|
217
|
+
expect(body.installed).toEqual([]);
|
|
218
|
+
expect(body.skipped[0].reason).toContain('already installed');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('catalog search with an empty query answers nothing and spawns nothing', async () => {
|
|
222
|
+
const body = await (await call(skillsAction, send({ type: 'search_catalog', q: ' ' }))).json();
|
|
223
|
+
expect(body.catalogSkills).toEqual([]);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
@@ -5,7 +5,7 @@ import { getDb } from '@/server/db.server';
|
|
|
5
5
|
import { DEFAULT_CATALOG_SKILLS, DEFAULT_CATALOG_SOURCES, DEFAULT_SKILLS } from '@/client/data/settings/skill';
|
|
6
6
|
import { isMockMode } from '@/server/mock.server';
|
|
7
7
|
import type { SkillItem } from '@/shared/types';
|
|
8
|
-
import {
|
|
8
|
+
import { readCatalogSources } from '@/server/lib/omp/config/skill-sources';
|
|
9
9
|
import {
|
|
10
10
|
deleteSkillDir,
|
|
11
11
|
discoverSkills,
|
|
@@ -20,11 +20,10 @@ import {
|
|
|
20
20
|
toCatalogSkills,
|
|
21
21
|
uninstallCatalogSkill,
|
|
22
22
|
} from '@/server/lib/omp/config/skills-catalog';
|
|
23
|
+
import { runCatalogAction } from '@/server/routes/settings/skills-catalog-actions';
|
|
23
24
|
import { resolveDiscoveryScope, type DiscoveryScope } from '@/server/lib/omp/config/scope';
|
|
24
25
|
import { reloadLiveSessions } from '@/server/lib/omp/session/reload.server';
|
|
25
26
|
|
|
26
|
-
const SOURCES_KEY = 'omp_catalog_sources';
|
|
27
|
-
|
|
28
27
|
/** Human label for an omp discovery source. */
|
|
29
28
|
const SOURCE_LABELS: Record<string, string> = {
|
|
30
29
|
'native:user': 'User / omp agent',
|
|
@@ -83,10 +82,9 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
|
|
83
82
|
try {
|
|
84
83
|
if (mock) {
|
|
85
84
|
const db = await getDb();
|
|
86
|
-
const storedSources = await readSettingsJson<typeof DEFAULT_CATALOG_SOURCES>(db, SOURCES_KEY, DEFAULT_CATALOG_SOURCES);
|
|
87
85
|
return json({
|
|
88
86
|
skills: DEFAULT_SKILLS,
|
|
89
|
-
catalogSources:
|
|
87
|
+
catalogSources: await readCatalogSources(db),
|
|
90
88
|
catalogSkills: DEFAULT_CATALOG_SKILLS,
|
|
91
89
|
root: null,
|
|
92
90
|
isMock: true,
|
|
@@ -96,9 +94,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
|
|
96
94
|
const db = await getDb();
|
|
97
95
|
const url = new URL(request.url);
|
|
98
96
|
const scope = await resolveDiscoveryScope(url.searchParams.get('root'), url.searchParams.get('scope'));
|
|
99
|
-
|
|
100
|
-
const storedSources = await readSettingsJson<typeof DEFAULT_CATALOG_SOURCES>(db, SOURCES_KEY, DEFAULT_CATALOG_SOURCES);
|
|
101
|
-
const catalogSources = Array.isArray(storedSources) && storedSources.length > 0 ? storedSources : DEFAULT_CATALOG_SOURCES;
|
|
97
|
+
const catalogSources = await readCatalogSources(db);
|
|
102
98
|
|
|
103
99
|
const [skills, popular, curated] = await Promise.all([
|
|
104
100
|
listSkills(scope),
|
|
@@ -106,8 +102,10 @@ export async function loader({ request }: LoaderFunctionArgs) {
|
|
|
106
102
|
searchSkillCatalog('code review', 8),
|
|
107
103
|
]);
|
|
108
104
|
|
|
105
|
+
// skills.sh entries are their own source: their install runs the CLI against
|
|
106
|
+
// a registry package, which is a different path from a local source card.
|
|
109
107
|
const seen = new Set<string>();
|
|
110
|
-
const catalogSkills = toCatalogSkills([...popular, ...curated],
|
|
108
|
+
const catalogSkills = toCatalogSkills([...popular, ...curated], 'skills-sh')
|
|
111
109
|
.filter((item) => (seen.has(item.repoTag) ? false : (seen.add(item.repoTag), true)));
|
|
112
110
|
|
|
113
111
|
return json({ skills, catalogSources, catalogSkills, root: scope.workspace, isMock: false });
|
|
@@ -170,12 +168,17 @@ export async function action({ request, params }: ActionFunctionArgs) {
|
|
|
170
168
|
return json({ success: true, reloaded });
|
|
171
169
|
}
|
|
172
170
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
171
|
+
const catalogResponse = await runCatalogAction(body as Record<string, unknown>, {
|
|
172
|
+
db,
|
|
173
|
+
scope,
|
|
174
|
+
// A request that names no root is scoped to the app root for READING, but
|
|
175
|
+
// that is not a workspace a write may land in.
|
|
176
|
+
hasWorkspace:
|
|
177
|
+
Boolean(url.searchParams.get('root') ?? (typeof body.root === 'string' ? body.root : null)) &&
|
|
178
|
+
(url.searchParams.get('scope') ?? body.scope) !== 'user',
|
|
179
|
+
listSkills: async (target) => listSkills(target),
|
|
180
|
+
});
|
|
181
|
+
if (catalogResponse) return catalogResponse;
|
|
179
182
|
|
|
180
183
|
// Catalog install/uninstall goes through the real skills CLI, which is what
|
|
181
184
|
// actually puts the skill where omp reads it.
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
import { describe, expect, test } from 'bun:test';
|
|
24
24
|
import type { FsNode } from '@/shared/types';
|
|
25
|
-
import { drawnAncestors, foldSingleChildFolders } from '@/shared/lib/fs/folder-chain';
|
|
25
|
+
import { chainLevelPaths, drawnAncestors, foldSingleChildFolders, unfoldChains } from '@/shared/lib/fs/folder-chain';
|
|
26
26
|
|
|
27
27
|
const baseNameOf = (path: string): string => path.slice(path.lastIndexOf('/') + 1);
|
|
28
28
|
const file = (path: string): FsNode => ({ name: baseNameOf(path), path, type: 'file' });
|
|
@@ -67,6 +67,86 @@ describe('foldSingleChildFolders', () => {
|
|
|
67
67
|
});
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
+
describe('chainLevelPaths', () => {
|
|
71
|
+
test('the levels a folded row stands for, outermost first', () => {
|
|
72
|
+
expect(chainLevelPaths('dev/src/main/code', 'dev/src/main/code')).toEqual([
|
|
73
|
+
'dev',
|
|
74
|
+
'dev/src',
|
|
75
|
+
'dev/src/main',
|
|
76
|
+
'dev/src/main/code',
|
|
77
|
+
]);
|
|
78
|
+
// A chain inside a folder is labelled relative to that folder, so only the
|
|
79
|
+
// part of the path the label names moves.
|
|
80
|
+
expect(chainLevelPaths('com/java/app/package', 'java/app/package')).toEqual([
|
|
81
|
+
'com/java',
|
|
82
|
+
'com/java/app',
|
|
83
|
+
'com/java/app/package',
|
|
84
|
+
]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('a row whose label is its own name is not a chain', () => {
|
|
88
|
+
expect(chainLevelPaths('src/deep', 'deep')).toBeNull();
|
|
89
|
+
expect(chainLevelPaths('src', 'src')).toBeNull();
|
|
90
|
+
// A label naming more segments than the path has cannot be a chain.
|
|
91
|
+
expect(chainLevelPaths('a', 'b/c')).toBeNull();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('unfoldChains', () => {
|
|
96
|
+
const chain = (): FsNode[] => [{
|
|
97
|
+
name: 'dev/src/main/code',
|
|
98
|
+
path: 'dev/src/main/code',
|
|
99
|
+
type: 'folder',
|
|
100
|
+
children: [file('dev/src/main/code/a.ts')],
|
|
101
|
+
}];
|
|
102
|
+
|
|
103
|
+
test('a named chain becomes one row per directory, the deepest keeping its children', () => {
|
|
104
|
+
const { nodes, roots } = unfoldChains(chain(), new Set(['dev/src/main/code']));
|
|
105
|
+
|
|
106
|
+
expect(nodes).toHaveLength(1);
|
|
107
|
+
expect(nodes[0]!.name).toBe('dev');
|
|
108
|
+
expect(nodes[0]!.path).toBe('dev');
|
|
109
|
+
expect(nodes[0]!.children?.[0]!.path).toBe('dev/src');
|
|
110
|
+
expect(nodes[0]!.children?.[0]!.children?.[0]!.path).toBe('dev/src/main');
|
|
111
|
+
const deepest = nodes[0]!.children![0]!.children![0]!.children![0]!;
|
|
112
|
+
expect(deepest.name).toBe('code');
|
|
113
|
+
expect(deepest.path).toBe('dev/src/main/code');
|
|
114
|
+
// The deepest level is the row that owns the read, so unfolding costs none.
|
|
115
|
+
expect(deepest.children?.map((node) => node.path)).toEqual(['dev/src/main/code/a.ts']);
|
|
116
|
+
expect(roots.get('dev')).toBe('dev/src/main/code');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('a chain nothing unfolded keeps its own array and node identities', () => {
|
|
120
|
+
const tree = chain();
|
|
121
|
+
const projected = unfoldChains(tree, new Set());
|
|
122
|
+
|
|
123
|
+
expect(projected.nodes).toBe(tree);
|
|
124
|
+
expect(projected.roots.size).toBe(0);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('a plain folder is not unfoldable, even when it is named', () => {
|
|
128
|
+
const tree = [folder('src', [file('src/a.ts')])];
|
|
129
|
+
expect(unfoldChains(tree, new Set(['src'])).nodes[0]).toBe(tree[0]);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test('a chain nested inside an open branch unfolds in place', () => {
|
|
133
|
+
// The shape the server lists for `com`: its one child is folded into a row
|
|
134
|
+
// labelled relative to `com`, whose path is the chain's deepest directory.
|
|
135
|
+
const tree = [folder('com', [{
|
|
136
|
+
name: 'java/app',
|
|
137
|
+
path: 'com/java/app',
|
|
138
|
+
type: 'folder',
|
|
139
|
+
children: [file('com/java/app/Main.java')],
|
|
140
|
+
}])];
|
|
141
|
+
const { nodes, roots } = unfoldChains(tree, new Set(['com/java/app']));
|
|
142
|
+
|
|
143
|
+
expect(nodes[0]!.path).toBe('com');
|
|
144
|
+
expect(nodes[0]!.children?.[0]!.path).toBe('com/java');
|
|
145
|
+
expect(nodes[0]!.children?.[0]!.children?.[0]!.path).toBe('com/java/app');
|
|
146
|
+
expect(roots.get('com/java')).toBe('com/java/app');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
70
150
|
describe('drawnAncestors', () => {
|
|
71
151
|
test('a reveal expands only the rows that exist, never a chain’s inner levels', () => {
|
|
72
152
|
const tree = [folder('lib/deep', [])];
|