diff --git a/docs/studio/behaviour/map.md b/docs/studio/behaviour/map.md index 94624b5f..986c0661 100644 --- a/docs/studio/behaviour/map.md +++ b/docs/studio/behaviour/map.md @@ -250,7 +250,7 @@ Before drafting, the person may fix the scan's grouping on the scan screen (tick - **Ignore.** The panel lists the candidates as checkboxes, ticked as the scan set them. Ticking one adds it to `ignored` and drops every part path inside it, a part left with none going; unticking it takes it out of `ignored`, and the folder, when no part's path covers it and it holds code, becomes a part of its own. - **Loose files and tests.** One row a folder, naming its files (three, then "and N more"), with a choice of "A new part" or any part and Add. The files go to the part chosen, or to a new part named after their folder ("Root" for the root's own files): as their folder whole when no part's path is inside it, else each by its own path. -- **Ignore a loose folder.** Each loose row offers Ignore beside Add (`ignore-folder`): its folder goes into the skeleton's `ignored`, so its files leave the loose lists and the check needs no part for them, `check_text` and `plotkeeper map check` alike. Ignore is muted with its reason, and the server refuses it, on the root and on a folder that holds a part's files, as `ignored` wins over the parts' paths. The folders so ignored (the skeleton's `ignored` that are not candidates) are listed under Ignored folders, each with Unignore, which takes the folder out of `ignored` and leaves its files loose again, making no part. After either, the focus goes to that folder's Unignore, or to the first Ignore of its rows again. +- **Ignore a loose folder.** Each loose row offers Ignore beside Add (`ignore-folder`): its folder goes into the skeleton's `ignored`, so its files leave the loose lists and the check needs no part for them, `check_text` and `plotkeeper map check` alike. Ignore is muted with its reason, and the server refuses it, on the root and on a folder that holds a part's files, as `ignored` wins over the parts' paths. The folders so ignored (the skeleton's `ignored` that are not candidates) are listed under Ignored folders, each with Unignore, which takes the folder out of `ignored` and leaves its files loose again, making no part. After either, the focus goes to that folder's Unignore, or to the first Ignore of its rows again. A folder with no loose files of its own that holds two or more rows (folders, or other parent rows) gets a **parent row** above them, indented, at every level (#790): it shows the folder and how many rows are right below it, and has Ignore alone, no Give to or Add, muted as a row's is when the folder holds a part's files. One press ignores the whole folder, and the server drops the `ignored` patterns inside it, so its Unignore brings every folder back, one ignored earlier on its own too. A folder with one row below it gets no parent row, since that row's Ignore does the job. - **Merge into… and Split by subfolders.** A plate's press opens its actions beside it. Merge into… moves the part's paths into the part chosen. Split by subfolders makes a part of each subfolder holding the part's code; the part keeps its file paths, the files right in its folders and the subfolders with no code, and goes when it keeps nothing. It is offered when that leaves two parts owning code, else it is muted with the reason. The parts' paths never nest, so which part owns a file never hangs on their order. A new part's id is its folder's name, with its parents' names added while the id is taken, then a number; its name is the folder's words. Each answer redraws the plates and lines; the panel is patched in place, so it stays open at its scroll and a focused box or button keeps the focus, and after a merge or a split the focus goes to the plate merged into or split. A draw of the same scan (a focus, a session's event) keeps the plates, and an open plate's actions with them. diff --git a/scripts/snap/fixtures-map.ts b/scripts/snap/fixtures-map.ts index 5a59796b..017e9e99 100644 --- a/scripts/snap/fixtures-map.ts +++ b/scripts/snap/fixtures-map.ts @@ -1025,6 +1025,67 @@ export const mapScanIgnore = (): Fixture => map_scan: mapScanOf(), map_scan_edit: mapScanOf({ map: testsIgnored, loose_tests: [] }), }); +// The loose files of two parent rows (#790): .claude/skills/ over its two folders, and src/, over two folders beside the parts' own. +const parentFiles = [".claude/skills/a/s.md", ".claude/skills/b/s.md", "src/x/x.ts", "src/y/y.ts"]; +const parentIgnored = (() => { + const map = JSON.parse(mapScanOf().map); + map.ignored = [".claude/skills/", "vendor/"]; + return JSON.stringify(map); +})(); +/** + * A loose folder holding only folders gets one Ignore (#790): `.claude/skills/` shows a parent row above its two folders' rows, indented, with + * Ignore alone and no Give to or Add, and `src/` shows one muted, since the parts hold files there. The muted press sends nothing; the parent's + * sends `ignore-folder` for `.claude/skills/`, the answer leaves only the `src/` rows, lists the folder under Ignored folders and puts the + * focus on its Unignore, whose press sends the edit back. + */ +export const mapScanParent = (): Fixture => + mapBaseOf(` + const screen = document.querySelector("#map .map-scan"); + if (!screen) return log("snap:fail no scan screen"); + const side = screen.querySelector(".map-scan-panel"); + window.__sent = []; + const real = window.fetch; + window.fetch = (url, init) => { + if (String(url).endsWith("/map_scan_edit")) window.__sent.push(JSON.parse(init.body)); + return real(url, init); + }; + const hintText = (node) => document.getElementById(node?.getAttribute("interestfor") ?? node?.getAttribute("data-hint") ?? "")?.textContent; + const rowOf = (folder) => [...side.querySelectorAll(".map-scan-loose")].find((r) => r.querySelector(".map-scan-where code").textContent === folder); + const folders = [...side.querySelectorAll(".map-scan-loose .map-scan-where code")].map((c) => c.textContent); + if (JSON.stringify(folders) !== JSON.stringify([".claude/skills/", ".claude/skills/a/", ".claude/skills/b/", "src/", "src/x/", "src/y/"])) return log("snap:fail the loose rows: " + JSON.stringify(folders)); + const parent = rowOf(".claude/skills/"); + if (!parent?.classList.contains("map-scan-parent") || parent.querySelector("select, .map-scan-pick") || [...parent.querySelectorAll("button")].map((b) => b.textContent).join() !== "Ignore") log("snap:fail the parent row is not an Ignore alone"); + if (!parent.querySelector(".map-scan-names")?.textContent.includes("2 folders")) log("snap:fail the parent says " + parent.textContent); + if (rowOf(".claude/skills/a/").querySelector(".map-scan-parent") || !rowOf(".claude/skills/a/").querySelector("select")) log("snap:fail a folder's row lost its Give to"); + if (parseFloat(getComputedStyle(rowOf(".claude/skills/a/")).marginInlineStart) <= parseFloat(getComputedStyle(parent).marginInlineStart)) log("snap:fail the folders are not indented under their parent"); + const held = rowOf("src/").querySelector("button"); + if (held?.getAttribute("aria-disabled") !== "true" || hintText(held) !== "Ignoring src/ would leave out the files of App, Cli and Lib") log("snap:fail src/'s Ignore: " + JSON.stringify(hintText(held))); + held.click(); + await wait(100); + if (window.__sent.length) log("snap:fail a muted Ignore was sent"); + frame("with a parent row"); + checkColours("with a parent row"); + const ignore = parent.querySelector("button"); + if (ignore.getAttribute("aria-label") !== "Ignore .claude/skills/") log("snap:fail the parent's Ignore is named " + ignore.getAttribute("aria-label")); + ignore.focus(); + ignore.click(); + await wait(300); + const sent = window.__sent[0]; + if (sent?.edit?.kind !== "ignore-folder" || sent.edit.folder !== ".claude/skills/" || sent.edit.ignored !== true) log("snap:fail the Ignore sent " + JSON.stringify(sent)); + if (JSON.stringify([...side.querySelectorAll(".map-scan-loose .map-scan-where code")].map((c) => c.textContent)) !== JSON.stringify(["src/", "src/x/", "src/y/"])) log("snap:fail the rows after Ignore"); + const undo = side.querySelector(".map-scan-ignored button"); + if (undo?.getAttribute("aria-label") !== "Unignore .claude/skills/") log("snap:fail Unignore is named " + undo?.getAttribute("aria-label")); + if (document.activeElement !== undo) log("snap:fail focus is not on Unignore, but on " + document.activeElement?.outerHTML.slice(0, 80)); + frame("after the parent's Ignore"); + undo.click(); + await wait(300); + const back = window.__sent[1]; + if (back?.edit?.kind !== "ignore-folder" || back.edit.folder !== ".claude/skills/" || back.edit.ignored !== false) log("snap:fail the Unignore sent " + JSON.stringify(back)); + log("base ok");`, { + map_state: mapState({ status: "none", source: null, from: null }), + map_scan: mapScanOf({ loose_files: parentFiles, loose_tests: [] }), + map_scan_edit: mapScanOf({ map: parentIgnored, loose_files: parentFiles.slice(2), loose_tests: [] }), + }); /** Draft the map muted when `claude` is not found (#753, story 12): aria-disabled with its one-line reason, a press starts nothing, and the copy-prompt leads. */ export const mapScanNoClaude = (): Fixture => mapOpened(` diff --git a/scripts/snap/fixtures.ts b/scripts/snap/fixtures.ts index 7e2a9646..af36e775 100644 --- a/scripts/snap/fixtures.ts +++ b/scripts/snap/fixtures.ts @@ -7,7 +7,7 @@ import type { Fixture } from "./base.ts"; import { railFixtures } from "./rail-fixtures.ts"; import { list, withSaved } from "./fixtures-shared.ts"; import { alerts, cutText, cutTextStill, hints, listClearLanded, listHeld, listHints, listNarrow, listSecondLines, logDone, logFixture, logos, noticeErrors, notRecording, paletteFocus, paletteOpen, projectChevron, projectMenuScript, projectsSaved, recording, skipLink, snapRealKeys, toastKeys, whatsNewToast } from "./fixtures-page.ts"; -import { mapBadgeList, mapBase, mapCheckout, mapDefaultNoBanner, mapNotGit, mapBriefPairLight, mapBriefSwitch, mapBroken, mapBusy, mapCalm, mapCamera, mapDotsOrder, mapDotsRetry, mapEmpty, mapFog, mapFogPlates, mapFresh, mapGlassMotion, mapGoneFocus, mapHeaderDot, mapMarkHints, mapMarks, mapScan, mapScanIgnore, mapScanMerge, mapScanNoClaude, mapScanSwitch, mapDraftSteps, mapDrafting, mapDraftReview, mapDraftRedraft, mapDraftAccept, mapDraftPr, mapDraftPrMuted, mapDraftReplace, mapDraftWrite, mapKeepCurrent, mapPendingClosed, mapPendingOpen, mapPendingSteps, mapPartKeys, mapPartRedraw, mapProjectGone, mapProjectRemoved, mapRefresher, mapPurposeMore, mapCaughtUp, mapCatchUpOlder, mapReview, mapScrubbed, mapSmallGaps, mapSpotlight, mapStale, mapSwitchSavesViews, mapTalksTo, readmeHero } from "./fixtures-map.ts"; +import { mapBadgeList, mapBase, mapCheckout, mapDefaultNoBanner, mapNotGit, mapBriefPairLight, mapBriefSwitch, mapBroken, mapBusy, mapCalm, mapCamera, mapDotsOrder, mapDotsRetry, mapEmpty, mapFog, mapFogPlates, mapFresh, mapGlassMotion, mapGoneFocus, mapHeaderDot, mapMarkHints, mapMarks, mapScan, mapScanIgnore, mapScanMerge, mapScanParent, mapScanNoClaude, mapScanSwitch, mapDraftSteps, mapDrafting, mapDraftReview, mapDraftRedraft, mapDraftAccept, mapDraftPr, mapDraftPrMuted, mapDraftReplace, mapDraftWrite, mapKeepCurrent, mapPendingClosed, mapPendingOpen, mapPendingSteps, mapPartKeys, mapPartRedraw, mapProjectGone, mapProjectRemoved, mapRefresher, mapPurposeMore, mapCaughtUp, mapCatchUpOlder, mapReview, mapScrubbed, mapSmallGaps, mapSpotlight, mapStale, mapSwitchSavesViews, mapTalksTo, readmeHero } from "./fixtures-map.ts"; import { mapFootprint, mapLatePlace, mapPanelBrief, mapPanelDiff, mapNotPlacedHint, mapPanelFieldHints, mapPanelFocus, mapPanelHead, mapPanelHistory, mapPanelLine2, mapPanelNoSession, mapPanelPeel, mapListFold, mapPanelSettings, mapPanelStory, mapPanelToggle, mapSheetClose, mapSheetExplained, mapSheetHere, mapSheetHolds, mapSheetKeptWidth, mapSheetResizeRedraw, mapSheetScrollShort, mapSheetStill, mapSheetUnratified, mapSheetWidth, mapToastBeside, mapTurnLight, mapPanelPatched, mapPanelAskStays, mapPanelBriefFoot } from "./fixtures-panel.ts"; import { mapBackLaw, mapMicroWorld, mapMicroWorldBuilding, mapPreFlight, mapPreFlightOutside, mapPreFlightOutsideKept, mapPreFlightPalette, mapPreFlightPick, mapPreFlightStatus, mapRuns, mapRunsAnnounced, mapRunsBesideSheet, mapRunsPaused, mapTray, mapTrayAfterPush } from "./fixtures-runs.ts"; import { mapBriefAlsoGroups, mapBriefAnnounce, mapBriefBar, mapBriefBold, mapBriefBoldUnpaired, mapBriefChapterLast, mapBriefChapterMid, mapBriefChapters, mapBriefCopied, mapBriefCopyByHand, mapBriefExplainBack, mapBriefExplained, mapBriefFigure, mapBriefGuard, mapBriefHeights, mapBriefMapCheck, mapBriefNoFacts, mapBriefReview, mapBriefStillTrue, mapBriefNoStaleBase, mapBriefOrderRight, mapBriefOrderSlots, mapBriefOrderWrong, mapBriefOverturn, mapBriefPartialFacts, mapBriefPick, mapBriefRatify, mapBriefRatifyDetail, mapBriefRatifyEvidence, mapBriefShort, mapBriefSince, mapBriefStaleBase, mapBriefStart, mapBriefStepCode, mapBriefStory, mapBriefTall, mapBriefTaller, mapBriefTallScroll, mapBriefUnconfirmed, mapBriefWhy, mapBriefWhyDecision, mapBriefWriting, mapCatchUp, mapCatchUpBold, mapCatchUpCard, mapCatchUpStage, mapCatchUpSummarising, mapCatchUpWriting, mapDiffClosed, mapDiffLitGhost, mapDiffRatifyLit, mapDiffRemoval, mapDiffRemovalBrief, mapDiffSplit, mapDiffSplitBrief, listBriefMark, railBriefReady } from "./fixtures-brief.ts"; @@ -257,6 +257,8 @@ export const fixtures = { mapScanMerge, mapScanIgnore, mapScanIgnoreNarrow: mapScanIgnore, + mapScanParent, + mapScanParentNarrow: mapScanParent, mapScanNoClaude, mapScanSwitch, // The Map draft (#763): the layout steps from scan to review, drafting with a group in, one checking and one failed, the review screen diff --git a/server/src/map_scan.rs b/server/src/map_scan.rs index 93143db9..c3d00829 100644 --- a/server/src/map_scan.rs +++ b/server/src/map_scan.rs @@ -182,7 +182,7 @@ fn fresh_id(map: &Value, new: &[Value], path: &str) -> String { /// holds code becomes a part of its own. fn ignore(map: &mut Value, folder: &str, on: bool, files: &[String]) { let mut list: Vec = strings(&map["ignored"]) - .filter(|p| *p != folder) + .filter(|p| *p != folder && !(on && p.starts_with(folder))) .map(String::from) .collect(); if on { @@ -220,11 +220,11 @@ fn ignore(map: &mut Value, folder: &str, on: bool, files: &[String]) { } } -/// Ignores `folder`, a folder of loose files, or stops ignoring it, its files loose again. A folder that holds a part's files is refused, so +/// Ignores `folder`, a folder of loose files, or stops ignoring it, its files loose again. Ignoring drops the patterns inside the folder, which it covers. A folder that holds a part's files is refused, so /// no part loses files to `ignored`, which the check reads before the parts' paths. fn ignore_folder(map: &mut Value, folder: &str, on: bool, files: &[String]) -> Result<(), String> { let mut list: Vec = strings(&map["ignored"]) - .filter(|p| *p != folder) + .filter(|p| *p != folder && !(on && p.starts_with(folder))) .map(String::from) .collect(); if on { @@ -829,6 +829,25 @@ mod tests { } } + #[test] + fn ignoring_a_parent_folder_drops_the_patterns_inside_it() { + let files: Vec = ["a/b/x.md", "a/c/y.md", "d/z.md"] + .map(String::from) + .to_vec(); + // (ignored before, folder, ignored after): a pattern inside the folder goes, one beside it stays, and Unignore of the parent leaves none. + for (before, folder, after) in [ + (&["a/b/", "d/"][..], "a/", &["a/", "d/"][..]), + (&["a/b/"][..], "a/c/", &["a/b/", "a/c/"][..]), + ] { + let mut map = serde_json::json!({ "ignored": before }); + ignore_folder(&mut map, folder, true, &files).unwrap(); + assert_eq!(map["ignored"], serde_json::json!(after), "{folder}"); + } + let mut map = serde_json::json!({ "ignored": ["a/"] }); + ignore_folder(&mut map, "a/", false, &files).unwrap(); + assert_eq!(map["ignored"], serde_json::json!([])); + } + #[test] fn a_folder_in_no_git_repository_has_no_scan() { let dir = tempfile::tempdir().unwrap(); diff --git a/ui/map-model.ts b/ui/map-model.ts index 980e3c4f..e8632343 100644 --- a/ui/map-model.ts +++ b/ui/map-model.ts @@ -185,26 +185,55 @@ export function draftTime(parts: number): string { return `About ${minutes} ${minutes === 1 ? "minute" : "minutes"}`; } +/** One row of the scan's loose list: a folder's own files, or a parent row (#790) over the rows below it, which holds no files to give. */ +export type LooseRow = { folder: string; label: string; names: string; files: string[]; muted: string | null; parent: boolean; depth: number }; + /** * The loose files or tests of a scan (#761) as the panel offers them: one row a folder, its label, the names of its files, and why Ignore is * muted on it, or null: the root, and a folder holding a path of one of `parts`, whose files `ignored` would take (`map_scan.rs` refuses it). + * A folder with no files of its own that holds two or more rows gets a parent row above them (#790), so one Ignore takes them all; `depth` + * counts the parent rows a row sits under, and a parent row's `names` counts the rows right below it. */ -export function looseGroups(files: string[], parts: { name: string; paths: string[] }[] = []): { folder: string; label: string; names: string; files: string[]; muted: string | null }[] { +export function looseGroups(files: string[], parts: { name: string; paths: string[] }[] = []): LooseRow[] { const byFolder = new Map(); for (const file of files) { const cut = file.lastIndexOf("/") + 1; const folder = file.slice(0, cut); byFolder.set(folder, [...(byFolder.get(folder) ?? []), file]); } - return [...byFolder.entries()] - .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)) - .map(([folder, group]) => { - const names = group.map((file) => file.slice(folder.length)).sort(); - const shown = names.length > 4 ? [...names.slice(0, 3), `${names.length - 3} more`] : names; - const held = parts.filter((part) => part.paths.some((path) => path.startsWith(folder))).map((part) => part.name); - const muted = !folder ? "Ignoring the root would leave out the whole repository" : held.length ? `Ignoring ${folder} would leave out the files of ${listed(held)}` : null; - return { folder, label: folder || "The root", names: listed(shown), files: [...group].sort(), muted }; - }); + // The rows, the deepest candidate parents first, so each counts the rows below it as they stand. The root never gets a parent row. + const rows = new Set(byFolder.keys()); + const below = new Map(); + const ancestors = new Set(); + for (const folder of byFolder.keys()) { + for (let cut = folder.indexOf("/") + 1; cut > 0 && cut < folder.length; cut = folder.indexOf("/", cut) + 1) ancestors.add(folder.slice(0, cut)); + } + const depthOf = (folder: string) => folder.split("/").length; + for (const ancestor of [...ancestors].filter((a) => !byFolder.has(a)).sort((a, b) => depthOf(b) - depthOf(a))) { + const inside = [...rows].filter((row) => row !== ancestor && row.startsWith(ancestor)); + const direct = inside.filter((row) => !inside.some((other) => other !== row && row.startsWith(other))); + if (direct.length < 2) continue; + rows.add(ancestor); + below.set(ancestor, direct.length); + } + const sorted = [...rows].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0)); + return sorted.map((folder) => { + const group = byFolder.get(folder) ?? []; + const names = group.map((file) => file.slice(folder.length)).sort(); + const shown = names.length > 4 ? [...names.slice(0, 3), `${names.length - 3} more`] : names; + const held = parts.filter((part) => part.paths.some((path) => path.startsWith(folder))).map((part) => part.name); + const muted = !folder ? "Ignoring the root would leave out the whole repository" : held.length ? `Ignoring ${folder} would leave out the files of ${listed(held)}` : null; + const parent = below.has(folder); + return { + folder, + label: folder || "The root", + names: parent ? `${below.get(folder)} folders` : listed(shown), + files: [...group].sort(), + muted, + parent, + depth: sorted.filter((other) => other && other !== folder && folder.startsWith(other) && below.has(other)).length, + }; + }); } /** The folders Ignore left out of a scan's loose rows (#753): the skeleton's `ignored` that are not the copies the scan asks about, sorted. */ diff --git a/ui/map-scan.ts b/ui/map-scan.ts index d1e96211..03f2e31c 100644 --- a/ui/map-scan.ts +++ b/ui/map-scan.ts @@ -8,7 +8,7 @@ import { availability, hint, isUnavailable, patch, pressable, svg, text } from "./dom.js"; import { fitCamera } from "./map-camera.js"; -import { autoPlace, draftTime, ignoredFolders, languagesLine, linkLines, looseGroups, type MapDoc, parseMap, plateSize, rimPoint, scanPrompt } from "./map-model.js"; +import { autoPlace, draftTime, ignoredFolders, languagesLine, linkLines, looseGroups, type LooseRow, type MapDoc, parseMap, plateSize, rimPoint, scanPrompt } from "./map-model.js"; import { copyButton } from "./copy-button.js"; import type { MapScan, MapState, ScanEdit } from "./types.js"; @@ -184,6 +184,23 @@ function ignoreBlock(scan: MapScan, acts: ScanActs): HTMLElement | null { return set; } +// A loose row's Ignore, named for its folder and muted with the row's reason. +function ignoreButton(kind: "files" | "tests", group: LooseRow, acts: ScanActs): HTMLButtonElement { + const ignore = pressable(text("button", "Ignore", "btn small"), null, () => { + if (isUnavailable(ignore)) return; + panelFocus = { act: "unignore", folder: group.folder }; + acts.edit({ kind: "ignore-folder", folder: group.folder, ignored: true }); + }); + ignore.type = "button"; + // Each row has an Ignore: its name says which folder. + ignore.setAttribute("aria-label", `Ignore ${group.label}`); + ignore.dataset.key = `scan ignore-folder ${kind} ${group.folder}`; + ignore.dataset.folder = group.folder; + ignore.dataset.act = "ignore"; + availability(ignore, `Leave ${group.folder} out of the map: ${group.parent ? "its folders" : "its files"} need no part`, group.muted); + return ignore; +} + // The loose files or tests, one row a folder, each offered a part or a new part (#753, story 8), or Ignore, muted where it would take a part's files. function looseBlock(kind: "files" | "tests", files: string[], doc: Doc, acts: ScanActs): HTMLElement | null { const groups = looseGroups(files, doc.parts); @@ -199,10 +216,19 @@ function looseBlock(kind: "files" | "tests", files: string[], doc: Doc, acts: Sc row.dataset.key = `scan loose ${kind} ${group.folder}`; // The files go with the form, so a row the panel keeps across a redraw sends what the latest draw listed. row.dataset.files = JSON.stringify(group.files); + row.style.setProperty("--depth", String(group.depth)); const where = text("p", "", "map-scan-where"); const folder = text("code", group.label === "The root" ? group.label : group.folder); folder.setAttribute("translate", "no"); where.append(folder, text("span", ` · ${group.names}`, "map-scan-names")); + const ignore = ignoreButton(kind, group, acts); + // A parent row (#790) has only Ignore: the rows below it give their files a part. + if (group.parent) { + row.classList.add("map-scan-parent"); + row.append(where, ignore); + set.append(row); + return; + } const pick = text("select", "", "map-scan-pick"); pick.id = `map-scan-home-${kind}-${i}`; pick.name = "part"; @@ -212,18 +238,6 @@ function looseBlock(kind: "files" | "tests", files: string[], doc: Doc, acts: Sc const add = Object.assign(pressable(text("button", "Add", "btn small"), null), { type: "submit" }); add.dataset.key = `scan add ${kind} ${group.folder}`; hint(add, kind === "files" ? "Give these files to the part chosen, or to a new part" : "Give these tests to the part chosen, or to a new part"); - const ignore = pressable(text("button", "Ignore", "btn small"), null, () => { - if (isUnavailable(ignore)) return; - panelFocus = { act: "unignore", folder: group.folder }; - acts.edit({ kind: "ignore-folder", folder: group.folder, ignored: true }); - }); - ignore.type = "button"; - // Each row has an Ignore: its name says which folder. - ignore.setAttribute("aria-label", `Ignore ${group.label}`); - ignore.dataset.key = `scan ignore-folder ${kind} ${group.folder}`; - ignore.dataset.folder = group.folder; - ignore.dataset.act = "ignore"; - availability(ignore, `Leave ${group.folder} out of the map: its files need no part`, group.muted); row.append(where, label, pick, add, ignore); row.addEventListener("submit", (event) => { event.preventDefault(); diff --git a/ui/style.css b/ui/style.css index cbe860e7..26ea188f 100644 --- a/ui/style.css +++ b/ui/style.css @@ -741,6 +741,9 @@ body.panel-open .map-empty { inset-inline-start: calc(var(--inset) + var(--panel .map-scan-check input { margin: 0; cursor: pointer; } .map-scan-check code, .map-scan-where code, .map-scan-ignored code { font-family: var(--mono); font-size: var(--size-small); overflow-wrap: anywhere; } .map-scan-loose { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: var(--sp-1) var(--sp-2); } +.map-scan-loose { margin-inline-start: calc(var(--depth, 0) * var(--sp-5)); } +.map-scan-parent { grid-template-columns: minmax(0, 1fr) auto; } +.map-scan-parent .map-scan-where { grid-column: auto; } .map-scan-ignored { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--sp-2); } .map-scan-ignored code { justify-self: start; } .map-scan-where { grid-column: 1 / -1; margin: 0; min-width: 0; overflow-wrap: anywhere; } diff --git a/ui/tests/map.test.mjs b/ui/tests/map.test.mjs index bda2a678..6ecc1b34 100644 --- a/ui/tests/map.test.mjs +++ b/ui/tests/map.test.mjs @@ -441,11 +441,31 @@ test("the loose files are offered by folder, each folder with the names of its f [["README.md", ".claude/settings.json", "docs/guide.md"], [], [["The root", "README.md", root], [".claude/", "settings.json", null], ["docs/", "guide.md", null]]], // Ignore would leave out the files of a part with a path inside the folder, a folder's or a file's: the server refuses it too. [["src/index.ts", "docs/api.md", "wiki/a.md"], parts, [["docs/", "api.md", "Ignoring docs/ would leave out the files of Docs"], ["src/", "index.ts", "Ignoring src/ would leave out the files of App and Lib"], ["wiki/", "a.md", null]]], + // A folder holding two or more loose rows and no files of its own is a parent row above them, at every level; one child row gets none. + [[...["a", "b"].map((n) => `.claude/skills/${n}/s.md`), ".claude/agents/x/a.md", ".claude/agents/y/a.md"], [], [ + [".claude/", "2 folders", null], [".claude/agents/", "2 folders", null], [".claude/agents/x/", "a.md", null], [".claude/agents/y/", "a.md", null], + [".claude/skills/", "2 folders", null], [".claude/skills/a/", "s.md", null], [".claude/skills/b/", "s.md", null], + ]], + [["a/b/f.md"], [], [["a/b/", "f.md", null]]], + // A folder with files of its own keeps its row, and its subfolders' rows follow it; a part's files in a parent mute its Ignore only. + [["d/x.md", "d/e/y.md", "d/f/z.md", "k/p/1.md", "k/q/2.md"], [{ name: "Kit", paths: ["k/q/other.md"] }], [ + ["d/", "x.md", null], ["d/e/", "y.md", null], ["d/f/", "z.md", null], + ["k/", "2 folders", "Ignoring k/ would leave out the files of Kit"], ["k/p/", "1.md", null], ["k/q/", "2.md", "Ignoring k/q/ would leave out the files of Kit"], + ]], ]; for (const [files, held, rows] of cases) { const groups = looseGroups(files, held); assert.deepEqual(groups.map((g) => [g.label, g.names, g.muted]), rows, JSON.stringify(files)); assert.deepEqual(groups.flatMap((g) => g.files).sort(), [...files].sort(), "every file is in one row"); + assert.ok(groups.every((g) => !g.parent || !g.files.length), "a parent row holds no files to give"); + } + // A row's depth is how many parent rows it sits under: the example's .claude/skills/a/ sits under .claude/skills/ and .claude/. + { + const deep = looseGroups([".claude/skills/a/s.md", ".claude/skills/b/s.md", ".claude/agents/x/a.md", ".claude/agents/y/a.md"]); + assert.deepEqual(deep.map((g) => [g.folder, g.parent, g.depth]), [ + [".claude/", true, 0], [".claude/agents/", true, 1], [".claude/agents/x/", false, 2], [".claude/agents/y/", false, 2], + [".claude/skills/", true, 1], [".claude/skills/a/", false, 2], [".claude/skills/b/", false, 2], + ]); } // The folders Ignore left out are the skeleton's ignored ones that are not the copies the scan asks about, which keep their checkboxes. const scan = { map: JSON.stringify({ ignored: ["vendor/", "wiki/", ".claude/"] }), ignore_candidates: [{ path: "vendor/", ticked: true }, { path: "copy/", ticked: false }] };