Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/studio/behaviour/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
61 changes: 61 additions & 0 deletions scripts/snap/fixtures-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down
4 changes: 3 additions & 1 deletion scripts/snap/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
25 changes: 22 additions & 3 deletions server/src/map_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = strings(&map["ignored"])
.filter(|p| *p != folder)
.filter(|p| *p != folder && !(on && p.starts_with(folder)))
.map(String::from)
.collect();
if on {
Expand Down Expand Up @@ -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<String> = strings(&map["ignored"])
.filter(|p| *p != folder)
.filter(|p| *p != folder && !(on && p.starts_with(folder)))
.map(String::from)
.collect();
if on {
Expand Down Expand Up @@ -829,6 +829,25 @@ mod tests {
}
}

#[test]
fn ignoring_a_parent_folder_drops_the_patterns_inside_it() {
let files: Vec<String> = ["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();
Expand Down
49 changes: 39 additions & 10 deletions ui/map-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string[]>();
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<string, number>();
const ancestors = new Set<string>();
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. */
Expand Down
Loading
Loading