f514602697
Part A — a fetch/pull/push against a remote that needs a login no longer dies on "terminal prompts disabled": the server answers 409 EGITAUTH with the host, the git bar asks for a username + password/access token and resends the same action. AgentHub keeps its OWN credential store (<CLAUDE_HOME>/agenthub-git-credentials/, 0700/0600), one login per host, shared by every user of the install, managed from Settings -> Git credentials. A login is only sent to one of the repo's own remote hosts, saved only after git accepted it, never returned by any route, and reaches git through an exclusive credential helper (never argv). Part B — merge a branch (or the diverged upstream) from the git bar; a merge that stops on conflicts lists them in the Changes panel with Keep mine / Take theirs / Mark resolved, then Complete merge or Abort merge (confirm gate). Clean tree, repo-root lane and an existing ref only; pull/switch/hunk actions are blocked mid-merge; staging a conflicted file with markers left is refused. Rebase/reset/stash stay out.
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
/**
|
|
* @file HTTP surface for AgentHub's own git credentials (git-credentials.js):
|
|
* list, save/replace, delete. Like the AI Router routes, nothing here ever
|
|
* returns a password — `GET` reports `hasToken` — and every write is behind
|
|
* the same-origin guard. A lane's fetch/pull/push also saves one, through
|
|
* `POST /api/lanes/:id/git/:action` with `credentials.remember`.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
const express = require("express");
|
|
|
|
const creds = require("../lib/git-credentials");
|
|
const { sameOriginGuard } = require("../lib/same-origin");
|
|
|
|
const router = express.Router();
|
|
|
|
function fail(res, e) {
|
|
const status = e.code === "EBADHOST" || e.code === "EBADCRED" ? 400 : 500;
|
|
res.status(status).json({ error: { code: e.code || "EINTERNAL", message: e.message } });
|
|
}
|
|
|
|
router.get("/", (_req, res) => {
|
|
res.json({ items: creds.list() });
|
|
});
|
|
|
|
router.post("/", sameOriginGuard, (req, res) => {
|
|
try {
|
|
const { protocol, host, username, password } = req.body || {};
|
|
creds.save({ protocol, host, username, password });
|
|
res.json({ items: creds.list() });
|
|
} catch (e) {
|
|
fail(res, e);
|
|
}
|
|
});
|
|
|
|
router.delete("/:protocol/:host", sameOriginGuard, (req, res) => {
|
|
try {
|
|
if (!creds.remove(req.params.protocol, req.params.host)) {
|
|
return res.status(404).json({ error: { code: "ENOTFOUND", message: "no such credential" } });
|
|
}
|
|
res.json({ items: creds.list() });
|
|
} catch (e) {
|
|
fail(res, e);
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|