@cueloop/client 0.1.0-alpha.15 → 0.1.0-alpha.16
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/package.json +5 -5
- package/src/App.tsx +67 -12
- package/src/App.walk.test.tsx +208 -0
- package/src/components/ConfirmCard.stories.tsx +15 -0
- package/src/components/ConfirmCard.tsx +8 -1
- package/src/components/WalkWizard.stories.tsx +89 -0
- package/src/components/WalkWizard.tsx +146 -0
- package/src/components/__snapshots__/stories.test.tsx.snap +130 -0
- package/src/config.ts +1 -0
- package/src/key-bindings.test.ts +18 -1
- package/src/key-bindings.ts +22 -1
- package/src/keymap.test.ts +37 -0
- package/src/keymap.ts +27 -2
- package/src/session-controller.ts +76 -2
- package/src/theme.ts +19 -0
- package/src/walk.test.ts +110 -0
- package/src/walk.ts +65 -0
package/src/theme.ts
CHANGED
|
@@ -27,6 +27,25 @@ export interface Theme {
|
|
|
27
27
|
backdrop: string;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* The dimmed variant behind the walk wizard: every reading color drops to
|
|
32
|
+
* the dim token so the file list stays legible context, not competition.
|
|
33
|
+
* Layout tokens (backgrounds, cursor) keep their values.
|
|
34
|
+
*/
|
|
35
|
+
export function dimmedTheme(theme: Theme): Theme {
|
|
36
|
+
return {
|
|
37
|
+
...theme,
|
|
38
|
+
text: theme.textDim,
|
|
39
|
+
textMuted: theme.textDim,
|
|
40
|
+
accent: theme.textDim,
|
|
41
|
+
green: theme.textDim,
|
|
42
|
+
red: theme.textDim,
|
|
43
|
+
blue: theme.textDim,
|
|
44
|
+
insFg: theme.textDim,
|
|
45
|
+
delFg: theme.textDim,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
30
49
|
export const DARK: Theme = {
|
|
31
50
|
bg: "#1f1f29",
|
|
32
51
|
panel: "#1a1a23",
|
package/src/walk.test.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/** Pure walk projections: file steps, resume index, viewed counts, notes. */
|
|
2
|
+
|
|
3
|
+
import { describe, expect, test } from "bun:test";
|
|
4
|
+
import type { Annotation } from "@cueloop/schema";
|
|
5
|
+
import { diffRows } from "./view-diff";
|
|
6
|
+
import { firstUnviewedIndex, noteForFile, viewedCount, walkFiles, WALK_PREVIEW_ROWS } from "./walk";
|
|
7
|
+
|
|
8
|
+
const PATCH = `diff --git a/src/a.ts b/src/a.ts
|
|
9
|
+
index 111..222 100644
|
|
10
|
+
--- a/src/a.ts
|
|
11
|
+
+++ b/src/a.ts
|
|
12
|
+
@@ -1,3 +1,4 @@
|
|
13
|
+
export const a = 1;
|
|
14
|
+
-export const b = 2;
|
|
15
|
+
+export const b = 3;
|
|
16
|
+
+export const c = 4;
|
|
17
|
+
diff --git a/src/b.ts b/src/b.ts
|
|
18
|
+
index 333..444 100644
|
|
19
|
+
--- a/src/b.ts
|
|
20
|
+
+++ b/src/b.ts
|
|
21
|
+
@@ -1,2 +1,2 @@
|
|
22
|
+
// header
|
|
23
|
+
-old line
|
|
24
|
+
+new line
|
|
25
|
+
diff --git a/src/c.ts b/src/c.ts
|
|
26
|
+
index 555..666 100644
|
|
27
|
+
--- a/src/c.ts
|
|
28
|
+
+++ b/src/c.ts
|
|
29
|
+
@@ -1,1 +1,8 @@
|
|
30
|
+
-gone
|
|
31
|
+
+one
|
|
32
|
+
+two
|
|
33
|
+
+three
|
|
34
|
+
+four
|
|
35
|
+
+five
|
|
36
|
+
+six
|
|
37
|
+
+seven
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
const rows = diffRows(PATCH);
|
|
41
|
+
const files = walkFiles(rows);
|
|
42
|
+
|
|
43
|
+
describe("walkFiles", () => {
|
|
44
|
+
test("one step per changed file, in patch order, with counted stats", () => {
|
|
45
|
+
expect(files.map((file) => file.path)).toEqual(["src/a.ts", "src/b.ts", "src/c.ts"]);
|
|
46
|
+
expect(files[0]).toMatchObject({ added: 2, removed: 1 });
|
|
47
|
+
expect(files[1]).toMatchObject({ added: 1, removed: 1 });
|
|
48
|
+
expect(files[2]).toMatchObject({ added: 7, removed: 1 });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("previews carry signed changed lines and cap at the preview budget", () => {
|
|
52
|
+
expect(files[0]!.preview).toEqual([
|
|
53
|
+
{ sign: "-", text: "export const b = 2;" },
|
|
54
|
+
{ sign: "+", text: "export const b = 3;" },
|
|
55
|
+
{ sign: "+", text: "export const c = 4;" },
|
|
56
|
+
]);
|
|
57
|
+
expect(files[2]!.preview.length).toBe(WALK_PREVIEW_ROWS);
|
|
58
|
+
expect(files[2]!.preview[0]).toEqual({ sign: "-", text: "gone" });
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("firstUnviewedIndex", () => {
|
|
63
|
+
test("starts at the first file when nothing is viewed", () => {
|
|
64
|
+
expect(firstUnviewedIndex(files, new Set())).toBe(0);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("skips viewed files - a resumed review lands on its first gap", () => {
|
|
68
|
+
expect(firstUnviewedIndex(files, new Set(["src/a.ts"]))).toBe(1);
|
|
69
|
+
expect(firstUnviewedIndex(files, new Set(["src/a.ts", "src/b.ts"]))).toBe(2);
|
|
70
|
+
// a viewed file later in the list does not block the earlier gap
|
|
71
|
+
expect(firstUnviewedIndex(files, new Set(["src/c.ts"]))).toBe(0);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("all viewed resumes on the end card, not the first file", () => {
|
|
75
|
+
expect(firstUnviewedIndex(files, new Set(["src/a.ts", "src/b.ts", "src/c.ts"]))).toBe(files.length);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("viewedCount", () => {
|
|
80
|
+
test("counts only paths present in the current file set", () => {
|
|
81
|
+
expect(viewedCount(files, new Set(["src/a.ts", "src/gone-in-rev-2.ts"]))).toBe(1);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe("noteForFile", () => {
|
|
86
|
+
const note = (path: string, body: string): Annotation => ({
|
|
87
|
+
id: `a_${path}`,
|
|
88
|
+
kind: "note",
|
|
89
|
+
anchor: { quote: path, prefix: "", suffix: "" },
|
|
90
|
+
body,
|
|
91
|
+
createdAt: "now",
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("finds the note anchored at the file path", () => {
|
|
95
|
+
const annotations = [note("src/a.ts", "Renames b and adds c."), note("src/b.ts", "Swaps the line.")];
|
|
96
|
+
expect(noteForFile(annotations, "src/b.ts")).toBe("Swaps the line.");
|
|
97
|
+
expect(noteForFile(annotations, "src/c.ts")).toBeUndefined();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("ignores non-note annotations that happen to quote the path", () => {
|
|
101
|
+
const comment: Annotation = {
|
|
102
|
+
id: "a_1",
|
|
103
|
+
kind: "comment",
|
|
104
|
+
anchor: { quote: "src/a.ts", prefix: "", suffix: "" },
|
|
105
|
+
body: "not a note",
|
|
106
|
+
createdAt: "now",
|
|
107
|
+
};
|
|
108
|
+
expect(noteForFile([comment], "src/a.ts")).toBeUndefined();
|
|
109
|
+
});
|
|
110
|
+
});
|
package/src/walk.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guided-walk projections (#83): pure helpers over the diff row model - no
|
|
3
|
+
* IO, no React. The walk steps through the changed files in patch order;
|
|
4
|
+
* which files were seen lives on the session record (viewedPaths), which
|
|
5
|
+
* file is on screen is view state in the session controller.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Annotation } from "@cueloop/schema";
|
|
9
|
+
import type { DiffRow } from "./view-diff";
|
|
10
|
+
|
|
11
|
+
/** One wizard step: a changed file with its stats and a short diff preview. */
|
|
12
|
+
export interface WalkFile {
|
|
13
|
+
path: string;
|
|
14
|
+
added: number;
|
|
15
|
+
removed: number;
|
|
16
|
+
/** The first changed lines, signed (+/-), for the card's diff preview. */
|
|
17
|
+
preview: { sign: "+" | "-"; text: string }[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Preview lines per card: enough to recognize the change, never a full diff. */
|
|
21
|
+
export const WALK_PREVIEW_ROWS = 5;
|
|
22
|
+
|
|
23
|
+
/** Collapse the diff rows into one walk step per changed file, in patch order. */
|
|
24
|
+
export function walkFiles(rows: DiffRow[]): WalkFile[] {
|
|
25
|
+
const files: WalkFile[] = [];
|
|
26
|
+
const byPath = new Map<string, WalkFile>();
|
|
27
|
+
for (const row of rows) {
|
|
28
|
+
let file = byPath.get(row.file);
|
|
29
|
+
if (!file) {
|
|
30
|
+
file = { path: row.file, added: 0, removed: 0, preview: [] };
|
|
31
|
+
byPath.set(row.file, file);
|
|
32
|
+
files.push(file);
|
|
33
|
+
}
|
|
34
|
+
if (row.t !== "add" && row.t !== "del") continue;
|
|
35
|
+
if (row.t === "add") file.added += 1;
|
|
36
|
+
else file.removed += 1;
|
|
37
|
+
if (file.preview.length < WALK_PREVIEW_ROWS) {
|
|
38
|
+
file.preview.push({ sign: row.t === "add" ? "+" : "-", text: row.text.replace(/\n$/, "") });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return files;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Where the walk resumes: the first file not yet marked viewed. All files
|
|
46
|
+
* viewed = the end card (index === files.length), so a finished walk reopens
|
|
47
|
+
* on its summary instead of restarting.
|
|
48
|
+
*/
|
|
49
|
+
export function firstUnviewedIndex(files: WalkFile[], viewedPaths: ReadonlySet<string>): number {
|
|
50
|
+
const index = files.findIndex((file) => !viewedPaths.has(file.path));
|
|
51
|
+
return index === -1 ? files.length : index;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Viewed count against the CURRENT file set - stale paths never inflate it. */
|
|
55
|
+
export function viewedCount(files: WalkFile[], viewedPaths: ReadonlySet<string>): number {
|
|
56
|
+
return files.filter((file) => viewedPaths.has(file.path)).length;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The agent's note for a file: an annotation with kind "note" whose anchor
|
|
61
|
+
* quote is the file path (the note contract in the shared review core).
|
|
62
|
+
*/
|
|
63
|
+
export function noteForFile(annotations: Annotation[], path: string): string | undefined {
|
|
64
|
+
return annotations.find((annotation) => annotation.kind === "note" && annotation.anchor.quote === path)?.body;
|
|
65
|
+
}
|