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
writer.ts3.5 KB
// Text an agent writes for the panel: a commit message from the changes, a pull request from the branch's commits.
// It runs one prompt through the cheapest model of the user's enabled agents (`api.models`, `models.use`), in a hidden
// session in the workspace that the user's own account pays for; interrupting it cancels the run.
import * as Data from "effect/Data";
import * as Effect from "effect/Effect";
import { Host, Plugin, promise } from "divergence/effect";
import type { GitStatus } from "divergence";
import { cleanMessage, commitPrompt, pullPrompt, splitPull, writerModel } from "./prompts.ts";
import { groups } from "./status.ts";
import type { PullTarget } from "./status.ts";
/** A step that did not work, in git's, gh's or the agent's own words. */
export class ActionFailed extends Data.TaggedError("ActionFailed")<{ readonly message: string }> {}
export const makeWriter = Effect.fn("Git.makeWriter")(function* () {
const host = yield* Host;
const { api } = yield* Plugin;
/** git's output, or its error output as the failure. */
const read = Effect.fn("Git.read")(function* (workspaceId: string, args: readonly string[]) {
const result = yield* host.call("host/git.run", { workspaceId, args });
if (result.code !== 0)
return yield* new ActionFailed({ message: (result.stderr || result.stdout).trim() || `git ${args[0]} failed` });
return result.stdout;
});
const ask = Effect.fn("Git.ask")(function* (workspaceId: string, prompt: string) {
const { agents } = yield* promise("models.list", () => api.models.list({ workspaceId }));
const choice = writerModel(agents);
if (!choice) return yield* new ActionFailed({ message: "no agent is enabled; turn one on in Settings" });
const answer = yield* promise("models.prompt", (signal) =>
api.models.prompt({ ...choice, prompt, workspaceId, signal }),
);
if (answer.status !== "completed")
return yield* new ActionFailed({ message: answer.message ?? "the agent stopped before it answered" });
return answer.text;
});
/** A message for what a commit would take now: the staged changes, or every change when nothing is staged. */
const commitMessage = Effect.fn("Git.writeCommitMessage")(function* (workspaceId: string, status: GitStatus) {
const { staged, changes } = groups(status);
const files = staged.length ? staged : changes;
const diff = yield* read(
workspaceId,
staged.length ? ["diff", "--cached", "--no-color", "-M"] : ["diff", "--no-color", "-M"],
);
const message = cleanMessage(yield* ask(workspaceId, commitPrompt({ branch: status.branch, files, diff })));
if (!message) return yield* new ActionFailed({ message: "the agent answered with no message" });
return message;
});
/** A title and description from the commits the branch has over the default branch; `null` when it has none. */
const pullRequest = Effect.fn("Git.writePullRequest")(function* (workspaceId: string, target: PullTarget) {
const base = `${target.remote}/${target.base}`;
const commits = yield* read(workspaceId, ["log", "--no-merges", "--format=* %s%n%n%b", `${base}..HEAD`]);
if (!commits.trim()) return null;
const stat = yield* read(workspaceId, ["diff", "--stat", "--no-color", `${base}...HEAD`]);
const pull = splitPull(
yield* ask(workspaceId, pullPrompt({ head: target.head, base: target.base, commits, stat })),
);
if (!pull.title) return yield* new ActionFailed({ message: "the agent answered with no title" });
return pull;
});
return { read, commitMessage, pullRequest };
});
No comments yet.