Official
git
Built-in git UI (JavaScript UI plugin).
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/git@0.3.0
Permissions in 0.3.0
Files
controller.ts4.3 KB
// Own one repository status reader and one panel state in the plugin scope.
// Changes during a read coalesce into one follow-up read, just as before conversion.
// Each status the panel shows also tells the pull request lookup which branch is on screen.
import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as Stream from "effect/Stream";
import { Host, Plugin, Services } from "divergence/effect";
import type { ViewHandle } from "divergence";
import type { Tabs } from "../tabs/contract.ts";
import { makeActions } from "./actions.ts";
import { makePulls } from "./pulls.ts";
import { initialState } from "./status.ts";
import { makeWriter } from "./writer.ts";
const makeGit = Effect.fn("Git.make")(function* () {
const host = yield* Host;
const plugin = yield* Plugin;
const services = yield* Services;
const scope = yield* Effect.scope;
const state = initialState();
const views: ViewHandle[] = [];
const redraw = () => {
for (const view of views) view.update();
};
let loading = false;
let again = false;
// Typed by hand: the pull request lookup it feeds is built from actions that refresh in turn.
const refresh: () => Effect.Effect<void> = Effect.fn("Git.refresh")(function* () {
if (!state.workspaceId) return;
if (loading) {
again = true;
return;
}
do {
const workspaceId = state.workspaceId;
if (!workspaceId) return;
loading = true;
yield* host.call("host/git.status", { workspaceId }).pipe(
Effect.tap((status) =>
Effect.gen(function* () {
if (workspaceId !== state.workspaceId) return;
Object.assign(state, { status, error: null });
yield* pulls.follow(workspaceId, status);
}),
),
Effect.catchTag(["HostCallFailed", "NeedsReview", "PermissionNotGranted"], (error) =>
Effect.sync(() => {
if (workspaceId === state.workspaceId) state.error = error.message;
}),
),
Effect.ensuring(
Effect.sync(() => {
loading = false;
}),
),
);
redraw();
if (!again) return;
again = false;
} while (true);
});
const show = Effect.fn("Git.show")(function* (workspaceId: string | undefined) {
if (!workspaceId || workspaceId === state.workspaceId) return;
Object.assign(state, { workspaceId, status: null, error: null, confirm: null, menuOpen: false, branchOpen: false });
// What an agent was writing and the pull request belong to the workspace the user left.
yield* actions.stopWriting;
yield* pulls.reset;
redraw();
// Older hosts lack watch; preserve their turn-finished/manual-refresh fallback.
const watch: unknown = plugin.api.host.git.watch;
if (typeof watch === "function")
yield* Effect.forkIn(
host
.call("host/git.watch", { workspaceId })
.pipe(
Effect.catchTag(["HostCallFailed", "NeedsReview", "PermissionNotGranted"], (error) =>
Effect.sync(() => console.warn(`git watch failed: ${error.message}`)),
),
),
scope,
{ startImmediately: true },
);
yield* refresh();
});
const writer = yield* makeWriter();
const actions = yield* makeActions(state, writer, refresh, redraw);
const pulls = yield* makePulls(state, writer, actions.git, redraw);
/** The Refresh button: the status, and the pull request gh knows of. */
const reload = Effect.gen(function* () {
yield* pulls.recheck;
yield* refresh();
});
// Diffs and files need the tabs plugin; without it they stay closed, as
// the shared request they replaced would have had no reader.
yield* services.when<typeof Tabs>("divergence/tabs").pipe(
Stream.runForEach((option) =>
Effect.sync(() => {
state.tabs = option._tag === "Some" ? option.value : undefined;
}),
),
Effect.forkIn(scope, { startImmediately: true }),
);
return {
state,
views,
refresh,
reload,
show,
...actions,
createPull: pulls.create,
editPull: pulls.edit,
cancelPull: pulls.cancel,
openPull: pulls.open,
openPullLink: pulls.openLink,
};
});
export class Git extends Context.Service<Git, Effect.Success<ReturnType<typeof makeGit>>>()("git/Git") {
static readonly layer = Layer.effect(Git, makeGit());
}
No comments yet.