@a2f0/agent-tool 0.1.61 → 0.1.63
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
CHANGED
|
@@ -533,6 +533,12 @@
|
|
|
533
533
|
cursor: pointer;
|
|
534
534
|
}
|
|
535
535
|
|
|
536
|
+
/* At the start or end of the row, a step button stays focusable but reads as unavailable. */
|
|
537
|
+
.shots-carousel-step:where([aria-disabled="true"]) {
|
|
538
|
+
opacity: 0.4;
|
|
539
|
+
cursor: default;
|
|
540
|
+
}
|
|
541
|
+
|
|
536
542
|
@media (prefers-reduced-motion: no-preference) {
|
|
537
543
|
:is(.shots-track, .shots-carousel-track, .shots-filmstrip) {
|
|
538
544
|
scroll-behavior: smooth;
|
|
@@ -60,17 +60,12 @@ export function nearestSlide(scrollLeft: number, offset: number, pitch: number,
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
63
|
+
* Whether a horizontal scroller can still move back toward its start or
|
|
64
|
+
* forward toward its end. The 1px tolerance absorbs fractional scroll
|
|
65
|
+
* positions, so a scroller resting at an edge reads as at that edge.
|
|
66
66
|
*/
|
|
67
|
-
|
|
68
|
-
return
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** How many copies each side needs so a full viewport of clones is always ready. */
|
|
72
|
-
export function loopCopies(viewportWidth: number, copyWidth: number): number {
|
|
73
|
-
return copyWidth > 0 ? Math.max(1, Math.ceil(viewportWidth / copyWidth)) : 1;
|
|
67
|
+
function scrollRoom(scrollLeft: number, scrollWidth: number, clientWidth: number): { back: boolean; forward: boolean } {
|
|
68
|
+
return { back: scrollLeft > 1, forward: scrollLeft < scrollWidth - clientWidth - 1 };
|
|
74
69
|
}
|
|
75
70
|
|
|
76
71
|
/** Wheel travel, in CSS pixels on a gesture's dominant axis, that steps one screen. */
|
|
@@ -183,7 +178,7 @@ export interface ScreenshotGalleryElement extends HTMLElement {
|
|
|
183
178
|
}
|
|
184
179
|
export interface ScreenshotCarouselElement extends HTMLElement {
|
|
185
180
|
manifestData: ScreenshotManifest | null;
|
|
186
|
-
/** Scrolls `delta` pages of slides,
|
|
181
|
+
/** Scrolls `delta` pages of slides, stopping at the first and last slide. */
|
|
187
182
|
step(delta: number): void;
|
|
188
183
|
}
|
|
189
184
|
|
|
@@ -733,10 +728,8 @@ function defineCarousel(): CustomElementConstructor {
|
|
|
733
728
|
#data: ScreenshotManifest | null = null;
|
|
734
729
|
#abort: AbortController | null = null;
|
|
735
730
|
#track: HTMLDivElement | null = null;
|
|
736
|
-
#count = 0;
|
|
737
|
-
#copies = 1;
|
|
738
731
|
#slides: HTMLElement[] = [];
|
|
739
|
-
#
|
|
732
|
+
#steps: { previous: HTMLButtonElement; next: HTMLButtonElement } | null = null;
|
|
740
733
|
|
|
741
734
|
constructor() {
|
|
742
735
|
super();
|
|
@@ -785,69 +778,65 @@ function defineCarousel(): CustomElementConstructor {
|
|
|
785
778
|
}
|
|
786
779
|
|
|
787
780
|
#render(manifest: ScreenshotManifest): void {
|
|
788
|
-
this.#manifest = manifest;
|
|
789
781
|
const slides = this.#slidesFor(manifest);
|
|
790
782
|
const signal = this.#abort!.signal;
|
|
791
|
-
this.#
|
|
783
|
+
this.#track = null;
|
|
784
|
+
this.#slides = [];
|
|
785
|
+
this.#steps = null;
|
|
792
786
|
if (!slides.length) { this.replaceChildren(); this.hidden = true; this.dataset["state"] = "empty"; return; }
|
|
793
787
|
this.hidden = false;
|
|
794
788
|
this.dataset["state"] = "ready";
|
|
795
789
|
const project = slides[0]!.light.project;
|
|
796
790
|
const frame = projectFrame(manifest, project);
|
|
797
|
-
const
|
|
798
|
-
const track = element("div", { class: "shots-carousel-track", tabindex: "0" }, [
|
|
791
|
+
const list = this.#list(manifest, slides);
|
|
792
|
+
const track = element("div", { class: "shots-carousel-track", tabindex: "0" }, [list]);
|
|
799
793
|
this.#track = track;
|
|
800
794
|
const root = element("div", { class: "shots-carousel", role: "region", "aria-roledescription": "carousel", "aria-label": this.getAttribute("label") ?? "Screenshots", "data-frame": frame }, [track]);
|
|
801
795
|
const controls = element("div", { class: "shots-carousel-controls" });
|
|
802
796
|
const viewAll = this.getAttribute("view-all-href");
|
|
803
797
|
if (viewAll) controls.append(element("a", { class: "shots-carousel-view-all", href: viewAll, text: this.getAttribute("view-all-label") || "View all screenshots" }));
|
|
804
|
-
if (
|
|
798
|
+
if (slides.length > 1) {
|
|
805
799
|
const previous = element("button", { type: "button", class: "shots-carousel-step", "data-step": "-1", "aria-label": "Previous screens" }, [icon("prev")]);
|
|
806
800
|
const next = element("button", { type: "button", class: "shots-carousel-step", "data-step": "1", "aria-label": "Next screens" }, [icon("next")]);
|
|
807
801
|
previous.addEventListener("click", () => this.step(-1), { signal });
|
|
808
802
|
next.addEventListener("click", () => this.step(1), { signal });
|
|
809
803
|
controls.append(previous, next);
|
|
810
|
-
|
|
804
|
+
this.#steps = { previous, next };
|
|
805
|
+
// Touch, trackpad, keyboard, and the buttons all scroll the track; a resize moves its end.
|
|
806
|
+
track.addEventListener("scroll", () => this.#updateSteps(), { passive: true, signal });
|
|
811
807
|
if (typeof ResizeObserver === "function") {
|
|
812
|
-
const observer = new ResizeObserver(() => this.#
|
|
808
|
+
const observer = new ResizeObserver(() => this.#updateSteps());
|
|
813
809
|
observer.observe(track);
|
|
810
|
+
observer.observe(list);
|
|
814
811
|
signal.addEventListener("abort", () => observer.disconnect());
|
|
815
812
|
}
|
|
816
813
|
}
|
|
817
814
|
if (controls.childElementCount) root.append(controls);
|
|
818
815
|
this.replaceChildren(root);
|
|
819
|
-
|
|
816
|
+
this.#updateSteps();
|
|
820
817
|
}
|
|
821
818
|
|
|
822
|
-
/**
|
|
823
|
-
#list(manifest: ScreenshotManifest, slides: { name: string; light: ScreenshotEntry; dark: ScreenshotEntry | undefined }[]
|
|
819
|
+
/** One list item per slide, each shown once. */
|
|
820
|
+
#list(manifest: ScreenshotManifest, slides: { name: string; light: ScreenshotEntry; dark: ScreenshotEntry | undefined }[]): HTMLUListElement {
|
|
824
821
|
const project = slides[0]!.light.project;
|
|
825
822
|
const linkBase = this.getAttribute("link-base");
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
const item = element("li", { class: "shots-carousel-slide", "data-index": index, "aria-hidden": clone ? "true" : undefined, "data-clone": clone || undefined }, [
|
|
844
|
-
element("figure", {}, [device, element("figcaption", { text: screen.label })]),
|
|
845
|
-
]);
|
|
846
|
-
this.#slides.push(item);
|
|
847
|
-
list.append(item);
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
return list;
|
|
823
|
+
this.#slides = slides.map((slide, index) => {
|
|
824
|
+
const screen = screenInfo(manifest, slide.name);
|
|
825
|
+
const picture = element("picture", {}, slide.dark ? [element("source", { media: "(prefers-color-scheme: dark)", srcset: slide.dark.src, width: slide.dark.width, height: slide.dark.height })] : []);
|
|
826
|
+
picture.append(element("img", {
|
|
827
|
+
src: slide.light.src, alt: screen.alt ?? `${screen.label}, ${projectInfo(manifest, project).label.toLowerCase()} screenshot`,
|
|
828
|
+
width: slide.light.width, height: slide.light.height, decoding: "async",
|
|
829
|
+
// The first slide rests at the start edge on load: fetch it first, and the rest as they near the viewport.
|
|
830
|
+
loading: index === 0 ? "eager" : "lazy", fetchpriority: index === 0 ? "high" : undefined,
|
|
831
|
+
}));
|
|
832
|
+
const device = linkBase
|
|
833
|
+
? element("a", { class: "shots-device", href: screenshotPath(linkBase, project, slide.name) }, [picture])
|
|
834
|
+
: element("div", { class: "shots-device" }, [picture]);
|
|
835
|
+
return element("li", { class: "shots-carousel-slide", "data-index": index }, [
|
|
836
|
+
element("figure", {}, [device, element("figcaption", { text: screen.label })]),
|
|
837
|
+
]);
|
|
838
|
+
});
|
|
839
|
+
return element("ul", { class: "shots-carousel-list", role: "list" }, this.#slides);
|
|
851
840
|
}
|
|
852
841
|
|
|
853
842
|
#pitch(): number {
|
|
@@ -859,49 +848,34 @@ function defineCarousel(): CustomElementConstructor {
|
|
|
859
848
|
const track = this.#track!, padding = parseFloat(getComputedStyle(track).scrollPaddingLeft);
|
|
860
849
|
return this.#slides[0]!.offsetLeft - (Number.isFinite(padding) ? padding : 0);
|
|
861
850
|
}
|
|
862
|
-
#current(): number { return nearestSlide(this.#track!.scrollLeft, this.#offset(), this.#pitch(), this.#slides.length); }
|
|
863
|
-
#jump(slide: number): void {
|
|
864
|
-
const track = this.#track;
|
|
865
|
-
if (!track || !this.#pitch()) return;
|
|
866
|
-
track.scrollTo({ left: this.#offset() + slide * this.#pitch(), behavior: "instant" });
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
/** Silently moves a settled track back to the same slide in the middle copy. */
|
|
870
|
-
#normalize(): void {
|
|
871
|
-
const track = this.#track, pitch = this.#pitch();
|
|
872
|
-
if (!track || !pitch) return;
|
|
873
|
-
const current = this.#current(), target = loopSlide(current, this.#count, this.#copies);
|
|
874
|
-
// Only a track resting on a slide jumps; a snap still in progress settles again.
|
|
875
|
-
if (Math.abs(track.scrollLeft - (this.#offset() + current * pitch)) > 2) return;
|
|
876
|
-
if (target !== current) this.#jump(target);
|
|
877
|
-
}
|
|
878
851
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
});
|
|
894
|
-
} else this.#normalize();
|
|
852
|
+
/**
|
|
853
|
+
* Marks the step button for a direction the track cannot move in with
|
|
854
|
+
* `aria-disabled`, read from the scroll position each time. Unlike
|
|
855
|
+
* `disabled`, it keeps the button focusable, so a keyboard user who steps
|
|
856
|
+
* onto the last page keeps focus there; a click on it does nothing.
|
|
857
|
+
*/
|
|
858
|
+
#updateSteps(): void {
|
|
859
|
+
const track = this.#track, steps = this.#steps;
|
|
860
|
+
if (!track || !steps) return;
|
|
861
|
+
const room = scrollRoom(track.scrollLeft, track.scrollWidth, track.clientWidth);
|
|
862
|
+
for (const [button, open] of [[steps.previous, room.back], [steps.next, room.forward]] as const) {
|
|
863
|
+
if (open) button.removeAttribute("aria-disabled");
|
|
864
|
+
else if (button.getAttribute("aria-disabled") !== "true") button.setAttribute("aria-disabled", "true");
|
|
865
|
+
}
|
|
895
866
|
}
|
|
896
867
|
|
|
897
868
|
step(delta: number): void {
|
|
898
869
|
const track = this.#track, pitch = this.#pitch();
|
|
899
|
-
if (!track || !pitch) return;
|
|
900
|
-
|
|
901
|
-
|
|
870
|
+
if (!track || !pitch || !delta) return;
|
|
871
|
+
const room = scrollRoom(track.scrollLeft, track.scrollWidth, track.clientWidth);
|
|
872
|
+
if (!(delta < 0 ? room.back : room.forward)) return;
|
|
902
873
|
const visible = Math.max(1, Math.floor((track.clientWidth + 1) / pitch));
|
|
903
|
-
const
|
|
904
|
-
|
|
874
|
+
const offset = this.#offset(), position = (track.scrollLeft - offset) / pitch;
|
|
875
|
+
// The last page can end mid-slide; stepping back from it counts from the first slide fully in view.
|
|
876
|
+
const from = delta < 0 ? Math.ceil(position - 0.1) : Math.round(position);
|
|
877
|
+
const end = Math.max(0, track.scrollWidth - track.clientWidth);
|
|
878
|
+
track.scrollTo({ left: Math.min(end, Math.max(0, offset + (from + delta * visible) * pitch)), behavior: scrollBehavior() });
|
|
905
879
|
}
|
|
906
880
|
};
|
|
907
881
|
}
|
package/src/workflows/branch.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { readFileSync } from "node:fs";
|
|
|
3
3
|
import { loadConfig, type AgentToolConfig } from "../config";
|
|
4
4
|
import { remoteBranchHead } from "../git/prContext";
|
|
5
5
|
import { gitEnvironment } from "../git/environment";
|
|
6
|
-
import { assert, clean, currentBranch, flag, git, head, mutateGit, nativeBranch, oid, option, output, repository } from "./core";
|
|
6
|
+
import { assert, clean, currentBranch, flag, git, head, mutateGit, mutateGitCaptured, nativeBranch, oid, option, output, repository } from "./core";
|
|
7
7
|
|
|
8
8
|
export function branchErrors(name: string, config: AgentToolConfig): string[] {
|
|
9
9
|
const errors: string[] = [];
|
|
@@ -75,7 +75,7 @@ export function branchCommand(args: string[]): number {
|
|
|
75
75
|
assert(baseOid, `Remote base '${base}' does not exist.`);
|
|
76
76
|
git(["fetch", "--no-tags", remote, `refs/heads/${base}`]);
|
|
77
77
|
assert(git(["rev-parse", "FETCH_HEAD"]) === baseOid && remoteBranchHead(url, base) === baseOid, "Base moved while fetching; retry creation.");
|
|
78
|
-
|
|
78
|
+
mutateGitCaptured(["switch", "--no-track", "-c", name, oid(baseOid)]);
|
|
79
79
|
assert(currentBranch() === name && head() === baseOid, "Checkout changed during branch creation.");
|
|
80
80
|
output({ branch: name, headOid: baseOid, baseBranch: base, baseOid, remote }); return 0;
|
|
81
81
|
}
|
package/src/workflows/core.ts
CHANGED
|
@@ -12,12 +12,36 @@ export function read(command: string, args: string[], cwd = process.cwd()): stri
|
|
|
12
12
|
}
|
|
13
13
|
export function git(args: string[], cwd = process.cwd()): string { return read("git", args, cwd); }
|
|
14
14
|
export function json<T>(args: string[]): T { return JSON.parse(read("gh", args)) as T; }
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Mutating Git commands deliberately retain normal hooks and their environment.
|
|
17
|
+
* This one streams Git's and its hooks' output to stderr for commands people
|
|
18
|
+
* watch live, such as a push and its push gate.
|
|
19
|
+
*/
|
|
16
20
|
export function mutateGit(args: string[]): void {
|
|
17
21
|
const result = spawnSync("git", args, { stdio: ["inherit", 2, 2], env: process.env });
|
|
18
22
|
if (result.error) throw result.error;
|
|
19
23
|
assert(result.status === 0, `git ${args[0]} failed (${result.signal ?? result.status}). Inspect checkout state before retrying.`);
|
|
20
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* A local Git mutation whose output nobody reads live, with the same hooks and
|
|
27
|
+
* environment as `mutateGit`. Its output and its hooks' are captured rather than
|
|
28
|
+
* inherited: a caller whose stderr pipe lost its reader (`2>&1 | jq` once jq
|
|
29
|
+
* quits) would otherwise kill Git with SIGPIPE part-way through a multi-step
|
|
30
|
+
* mutation. Stdin is closed, since a prompt could not be seen. On failure the
|
|
31
|
+
* error carries Git's exit status or signal and the tail of its stderr.
|
|
32
|
+
*/
|
|
33
|
+
export function mutateGitCaptured(args: string[]): void {
|
|
34
|
+
const result = spawnSync("git", args, { stdio: ["ignore", "pipe", "pipe"], env: process.env, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 });
|
|
35
|
+
if (result.error) throw result.error;
|
|
36
|
+
if (result.status === 0) return;
|
|
37
|
+
const detail = outputTail(result.stderr || result.stdout || "");
|
|
38
|
+
throw new Error(`git ${args[0]} failed (${result.signal ?? result.status})${detail ? `: ${detail}` : "."} Inspect checkout state before retrying.`);
|
|
39
|
+
}
|
|
40
|
+
/** The last lines of a command's output, bounded for an error message. */
|
|
41
|
+
export function outputTail(text: string, lines = 20, characters = 2000): string {
|
|
42
|
+
const tail = text.trim().split("\n").slice(-lines).join("\n");
|
|
43
|
+
return tail.length > characters ? `…${tail.slice(-characters)}` : tail;
|
|
44
|
+
}
|
|
21
45
|
export function clean(): void { assert(!git(["status", "--porcelain=v1", "--untracked-files=all"]), "Checkout has local changes; preserve them before continuing."); }
|
|
22
46
|
export function head(): string { return oid(git(["rev-parse", "HEAD"])); }
|
|
23
47
|
export function currentBranch(): string {
|
package/src/workflows/hooks.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
3
3
|
import { chmodSync, copyFileSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, realpathSync, renameSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { loadConfig } from "../config";
|
|
6
|
-
import { assert, flag, git, output } from "./core";
|
|
6
|
+
import { assert, flag, git, mutateGitCaptured, output } from "./core";
|
|
7
7
|
|
|
8
8
|
const manifestName = ".agent-tool-hooks.json";
|
|
9
9
|
interface Manifest { schemaVersion: 1; files: Record<string, { hash: string; executable: boolean }> }
|
|
@@ -126,7 +126,7 @@ function install(root: string, common: string, destination: string, sources: Hoo
|
|
|
126
126
|
const temporary = path.join(destination, `.agent-tool-manifest-${randomUUID()}`);
|
|
127
127
|
writeFileSync(temporary, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600, flag: "wx" });
|
|
128
128
|
renameSync(temporary, manifestFile);
|
|
129
|
-
if (configure)
|
|
129
|
+
if (configure) mutateGitCaptured(["config", "--local", "core.hooksPath", destination]);
|
|
130
130
|
const after = config(["--type=path", "--get", "core.hooksPath"]);
|
|
131
131
|
assert(resolveDirectory(after ? path.resolve(root, after) : path.join(common, "hooks")) === destination, "Effective hooksPath does not match installation; inspect Git configuration.");
|
|
132
132
|
output({ ok: true, applied: true, destination, changes, backups });
|
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import { loadConfig } from "../config";
|
|
5
5
|
import { remoteBranchHead, resolveFreshBaseRef, resolveRepositoryGitUrl } from "../git/prContext";
|
|
6
6
|
import { viewCurrentBranchPr } from "../git/currentBranchPr";
|
|
7
|
-
import { assert, clean, currentBranch, flag, git, head,
|
|
7
|
+
import { assert, clean, currentBranch, flag, git, head, mutateGitCaptured, oid, output, read, repository } from "./core";
|
|
8
8
|
import { pullRequest } from "./pr";
|
|
9
9
|
import { assertStrictBaseFreshness } from "../pr/baseFreshness";
|
|
10
10
|
import { baseHealthCommand } from "./baseHealth";
|
|
@@ -55,15 +55,15 @@ export function repoCommand(args: string[]): number {
|
|
|
55
55
|
const localDefault = spawnSync("git", ["rev-parse", "--verify", `refs/heads/${defaultBranch}`], { encoding: "utf8" });
|
|
56
56
|
if (localDefault.status === 0) {
|
|
57
57
|
assert(git(["merge-base", localDefault.stdout.trim(), defaultOid]) === localDefault.stdout.trim(), "Local default branch diverged; preserve it for inspection.");
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
} else { assert(localDefault.status === 128, "Could not inspect local default branch.");
|
|
58
|
+
mutateGitCaptured(["switch", defaultBranch]);
|
|
59
|
+
mutateGitCaptured(["merge", "--ff-only", defaultOid]);
|
|
60
|
+
} else { assert(localDefault.status === 128, "Could not inspect local default branch."); mutateGitCaptured(["switch", "--no-track", "-c", defaultBranch, defaultOid]); }
|
|
61
61
|
assert(currentBranch() === defaultBranch && head() === defaultOid, "Checkout changed during default-branch update.");
|
|
62
62
|
clean(); completed.push("updated-default");
|
|
63
63
|
if (!keep) {
|
|
64
64
|
if (feature.status === 0) {
|
|
65
65
|
assert(git(["rev-parse", `refs/heads/${pr.headRefName}`]) === shipped, "Local feature branch changed before deletion.");
|
|
66
|
-
|
|
66
|
+
mutateGitCaptured(["branch", "-D", "--", pr.headRefName]); completed.push("deleted-local-branch");
|
|
67
67
|
}
|
|
68
68
|
const live = remoteBranchHead(url, pr.headRefName);
|
|
69
69
|
assert(!live || live === shipped, "Remote feature branch changed before deletion.");
|