Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions chatbot/src/QuickAccessWizard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ function parseGitHubRepo(raw) {
// SSH preview first (it leaves github.com to the GitHub parser, matching the
// server); self-hosted legacy repositories keep the git.example.com form.
export function parseGongfengRepo(raw) {
const httpsInfo = globalThis.LoopForgeGitHTTPS(raw);
if (httpsInfo) return httpsInfo;
const sshInfo = globalThis.LoopForgeGitSSH(raw);
if (sshInfo) return sshInfo;
const github = parseGitHubRepo(raw);
Expand Down Expand Up @@ -996,7 +998,7 @@ export default function QuickAccessWizard({
(item) => Number(item.id) === Number(user?.id),
) || user;
setStoredUser(mergeFreshUser(user, freshUser));
if (freshUser?.gitTokenConfigured && freshUser?.id) {
if (freshUser?.gitHubCredentialConfigured && freshUser?.id) {
void verifyStoredGitToken(freshUser.id);
}
const nextProjects = Array.isArray(projectsRes)
Expand Down Expand Up @@ -1107,7 +1109,7 @@ export default function QuickAccessWizard({
);
if (fresh) {
setStoredUser((prev) => mergeFreshUser(prev, fresh));
if (fresh.gitTokenConfigured) {
if (fresh.gitHubCredentialConfigured) {
void verifyStoredGitToken(fresh.id);
}
}
Expand Down Expand Up @@ -1183,7 +1185,7 @@ export default function QuickAccessWizard({
const activeStepIndex = phase === "success" ? STEPS.length - 1 : step;
const activeStep = STEPS[activeStepIndex] || STEPS[0];
const wizardStepCount = STEPS.length - 1;
const gitReady = Boolean(storedUser?.gitTokenConfigured || gitToken.trim());
const gitReady = Boolean(storedUser?.gitHubCredentialConfigured || gitToken.trim());
const hasSSHKeys = Boolean(storedUser?.gitSshKeyConfigured);
const selectedSSHRepo = parsedRepo || parseGongfengRepo(defaultRepo?.cloneUrl);
const sshKeysLoaded = sshCredentials.userId === user?.id && sshCredentials.keys !== null;
Expand Down Expand Up @@ -1220,13 +1222,20 @@ export default function QuickAccessWizard({
async function saveTypedCredentials() {
if (!user?.id) return storedUser;
const payload = {};
if (gitToken.trim()) payload.gitToken = gitToken.trim();
let savedGit = false;
if (gitToken.trim()) {
const endpoint = `/api/users/${encodeURIComponent(user.id)}/git-http-credentials`;
const credentials = await api(endpoint);
const existing = credentials.find(credential => credential.host === "github.com");
await write(endpoint, { ...(existing ? {id:existing.id} : {}), host:"github.com", platform:"github", name:"GitHub", username:"x-access-token", token:gitToken.trim() }, "PUT");
savedGit = true;
}
if (codeBuddyApiKey.trim())
payload.codeBuddyApiKey = codeBuddyApiKey.trim();
// A key is always saved with the environment it was issued for.
if (codeBuddyApiKey.trim() || codeBuddyEnv !== storedCodeBuddyEnvRaw)
payload.codeBuddyInternetEnvironment = codeBuddyEnv;
if (!Object.keys(payload).length) return storedUser;
if (!Object.keys(payload).length && !savedGit) return storedUser;
const saved = await write(
`/api/users/${encodeURIComponent(user.id)}/credentials`,
payload,
Expand Down Expand Up @@ -1320,7 +1329,7 @@ export default function QuickAccessWizard({
}
if (bindRepoNow && repoUrl.trim() && !parsedRepo) {
setError(
"请输入 GitHub 仓库链接或 Git SSH 克隆地址。CNB 只支持 HTTPS + 访问令牌。",
"请输入 Git HTTPS 仓库链接或 Git SSH 克隆地址。",
);
return;
}
Expand Down Expand Up @@ -1379,7 +1388,7 @@ export default function QuickAccessWizard({
const existingRepo = (repositories || []).find(
(repo) =>
repo.projectId === targetProject.id &&
(parsedRepo.provider === "ssh"
(["ssh", "https"].includes(parsedRepo.provider)
? repo.cloneUrl === parsedRepo.cloneUrl
: repo.gongfengProjectId === parsedRepo.project ||
repo.webUrl === parsedRepo.webUrl),
Expand Down Expand Up @@ -1509,7 +1518,7 @@ export default function QuickAccessWizard({
repository: boundRepo,
workflow: provisionedWorkflow || activeWorkflow,
rolesCount: roles.length,
gitReady: Boolean(boundRepo?.provider === "ssh" ? hasSSHKey(parseGongfengRepo(boundRepo.cloneUrl)) : latestUser?.gitTokenConfigured),
gitReady: Boolean(boundRepo?.provider === "ssh" ? hasSSHKey(parseGongfengRepo(boundRepo.cloneUrl)) : latestUser?.gitHubCredentialConfigured),
codeBuddyReady: Boolean(
latestUser?.codeBuddyApiKeyConfigured ||
storedUser?.codeBuddyApiKeyConfigured,
Expand Down Expand Up @@ -1826,10 +1835,11 @@ export default function QuickAccessWizard({
</header>
<div className="qa-cred-body">
<button type="button" className="qa-btn qa-btn-primary qa-btn-sm" onClick={() => openCredentialSettings("gitToken")}>
{storedUser?.gitTokenConfigured ? "管理 GitHub 授权" : "连接 GitHub"}
{storedUser?.gitHubCredentialConfigured ? "管理 GitHub 授权" : "连接 GitHub"}
</button>
<p className="qa-hint">在个人配置中完成授权,返回后继续;无需手动复制令牌。</p>
<p className="qa-hint">GitLab 等 SSH 仓库:<button type="button" className="qa-link-btn" onClick={() => openCredentialSettings("gitSshKey")}>{hasSSHKeys ? "管理 Git SSH 密钥" : "配置 Git SSH 密钥"}</button></p>
<p className="qa-hint">工作区访问 GitLab、GitHub Enterprise 等 HTTPS 主机:<button type="button" className="qa-link-btn" onClick={() => openCredentialSettings("gitHttpCredentials")}>{storedUser?.gitHttpCredentialsConfigured ? "管理 Git 访问令牌" : "配置 Git 访问令牌"}</button></p>
<details>
<summary>使用访问令牌(高级)</summary>
<div className="qa-input-row">
Expand All @@ -1839,7 +1849,7 @@ export default function QuickAccessWizard({
value={gitToken}
onChange={(e) => setGitToken(e.target.value)}
placeholder={
storedUser?.gitTokenConfigured
storedUser?.gitHubCredentialConfigured
? "已配置,留空保持不变"
: "GitHub personal access token(授予 Contents 与 Pull requests 读写权限)"
}
Expand All @@ -1853,7 +1863,7 @@ export default function QuickAccessWizard({
disabled={
!verifyingGit &&
!gitToken.trim() &&
!storedUser?.gitTokenConfigured
!storedUser?.gitHubCredentialConfigured
}
onClick={verifyGit}
>
Expand Down Expand Up @@ -2100,7 +2110,7 @@ export default function QuickAccessWizard({
? "旧项目可直接追加新仓库,复用已有流程与角色;留空则沿用现有仓库"
: "沿用项目现有仓库与流程"
: bindRepoNow
? "粘贴 GitHub 链接或 Git SSH 地址,自动设为项目默认仓库"
? "粘贴 Git HTTPS 链接或 Git SSH 地址,自动设为项目默认仓库"
: "已跳过,可在派发需求或项目配置中再绑定"}
</span>
</div>
Expand Down Expand Up @@ -2157,7 +2167,7 @@ export default function QuickAccessWizard({
{projectMode === "existing" &&
projectRepos.length
? "新增仓库地址(可选)"
: "GitHub 链接或 Git SSH 地址"}
: "Git HTTPS 链接或 Git SSH 地址"}
</span>
<input
className="qa-input qa-mono"
Expand Down Expand Up @@ -2204,7 +2214,7 @@ export default function QuickAccessWizard({
</p>
) : (
<p key="help" className="qa-hint">
支持 GitHub 链接或 Git SSH 地址,例如 <code>git@gitlab.com:group/repo.git</code>。
支持 Git HTTPS 链接或 Git SSH 地址,例如 <code>git@gitlab.com:group/repo.git</code>。
</p>
)}
{selectedSSHRepo?.provider === "ssh" && sshKeysLoaded && !sshReady ? (
Expand Down
8 changes: 8 additions & 0 deletions chatbot/src/credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const CREDENTIALS = {
claudeCodeApiKey: "Claude Code API Key",
gitToken: "GitHub Git Token",
gitSshKey: "Git SSH 密钥",
gitHttpCredentials: "Git 访问令牌",
};

// A CodeBuddy key only works on the edition that issued it, and the CLI
Expand Down Expand Up @@ -93,6 +94,13 @@ export const CREDENTIAL_GUIDES = {
"回到这里重试",
],
},
gitHttpCredentials: {
steps: [
"在代码托管平台创建仓库级、最小权限的个人访问令牌",
"到「个人配置 → Git 访问令牌」为该 HTTPS 主机添加令牌,并开启「提供给工作区」",
"回到这里重试",
],
},
gitToken: {
url: "/#/settings",
link: "连接 GitHub",
Expand Down
14 changes: 7 additions & 7 deletions chatbot/tests/quick-access-wizard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ const { project, user, apiMock, writeMock, mockState } = vi.hoisted(() => {
};
const user = {
id: 1, loginName: "tester", chineseName: "测试",
gitTokenConfigured: true, codeBuddyApiKeyConfigured: true,
gitHubCredentialConfigured: true, codeBuddyApiKeyConfigured: true,
};
const apiMock = vi.fn(async (path) => {
if (path === "/api/users" && mockState.users) return mockState.users();
if (path === "/api/users")
return [mockState.unconfigured ? {
id: 1, loginName: "tester", chineseName: "测试",
gitTokenConfigured: false, codeBuddyApiKeyConfigured: false,
gitHubCredentialConfigured: false, codeBuddyApiKeyConfigured: false,
} : user];
if (path === "/api/projects") return [project];
if (path === "/api/repositories") return [];
Expand Down Expand Up @@ -79,9 +79,9 @@ describe("QuickAccessWizard", () => {
webUrl: "https://github.com/acme/widgets",
cloneUrl: "https://github.com/acme/widgets.git",
});
// GitHub SSH-style addresses stay GitHub repositories (token + automatic PRs).
// Preserve explicit SSH transport for GitHub as for other hosts.
for (const address of ["git@github.com:acme/widgets.git", "ssh://git@github.com/acme/widgets.git"]) {
expect(parseGongfengRepo(address)).toMatchObject({ provider: "github", project: "github:acme/widgets" });
expect(parseGongfengRepo(address)).toMatchObject({ provider: "ssh", host: "github.com:22" });
}
expect(parseGongfengRepo("ssh://git@github.com:2222/acme/widgets.git")?.provider).toBe("ssh");
expect(parseGongfengRepo("git clone ssh://git@gitlab.example.org:2222/team/sub/app.git")).toMatchObject({
Expand All @@ -93,7 +93,7 @@ describe("QuickAccessWizard", () => {
expect(parseGongfengRepo("https://github.com/acme")).toBeNull();
expect(parseGongfengRepo("git@git.example.com:team/repo.git")?.provider).toBe("ssh");
expect(parseGongfengRepo("https://git.example.com/team/repo/-/tree/main")?.name).toBe("repo");
expect(parseGongfengRepo("https://example.com/team/repo")).toBeNull();
expect(parseGongfengRepo("https://example.com/team/repo")).toMatchObject({provider:"https",cloneUrl:"https://example.com/team/repo"});
expect(parseGongfengRepo("")).toBeNull();
});

Expand Down Expand Up @@ -212,8 +212,8 @@ describe("QuickAccessWizard", () => {
);
await userAction.click(screen.getByRole("button", { name: "校验" }));
await waitFor(() => expect(writeMock).toHaveBeenCalledWith(
"/api/users/1/credentials",
expect.objectContaining({ gitToken: "token-value" }),
"/api/users/1/git-http-credentials",
expect.objectContaining({ host:"github.com", token: "token-value" }),
"PUT",
));
mockState.unconfigured = false;
Expand Down
3 changes: 3 additions & 0 deletions cmd/agentflow-runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func main() {
if runtime.RunMCPCallCLI(os.Args[1:]) {
return
}
if runtime.RunGitHelperCLI(os.Args[1:]) {
return
}
server := flag.String("server", "", "LoopForge server URL, e.g. https://workflow.example.com (or AGENTFLOW_SERVER_URL)")
token := flag.String("token", "", "runner bootstrap token (or AGENTFLOW_RUNNER_BOOTSTRAP_TOKEN)")
name := flag.String("name", "", "runner display name (default: hostname)")
Expand Down
3 changes: 3 additions & 0 deletions cmd/agentflow/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func main() {
if runtime.RunMCPCallCLI(os.Args[1:]) {
return
}
if runtime.RunGitHelperCLI(os.Args[1:]) {
return
}
addr := flag.String("addr", "", "HTTP listen address; overrides AGENTFLOW_HTTP_PORT")
workspaces := flag.String("workspaces", "", "sandbox workspace root")
workerConcurrency := flag.Int("worker-concurrency", 8, "maximum concurrent node sandboxes for this worker")
Expand Down
8 changes: 3 additions & 5 deletions docs/api/collaboration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

### `GET /api/projects`

返回 `Project[]`,`200`。项目含 `id`、`key`、`name`、`description`、`color`、`workflowId`、`defaultRepositoryId`、`members`、`clarification`、TAPD 配置及时间戳。响应永不返回 `gitToken`、`codeBuddyApiKey` 明文,只以 `gitTokenConfigured`、`codeBuddyApiKeyConfigured` 表示是否已配置。
返回 `Project[]`,`200`。项目含 `id`、`key`、`name`、`description`、`color`、`workflowId`、`defaultRepositoryId`、`members`、`clarification`、TAPD 配置及时间戳。Git 凭据按用户和主机保存在个人配置中,不属于项目。

```bash
curl -u "$AGENTFLOW_USER:$AGENTFLOW_PASS" "$AGENTFLOW_URL/api/projects"
Expand All @@ -27,8 +27,6 @@ curl -u "$AGENTFLOW_USER:$AGENTFLOW_PASS" "$AGENTFLOW_URL/api/projects"
"key":"PLATFORM",
"defaultRepositoryId":"repo-platform",
"workflowId":"wf-dev",
"gitToken":"new-token",
"gitTokenClear":false,
"codeBuddyApiKey":"",
"codeBuddyApiKeyClear":false,
"codeBuddyInternetEnvironmentClear":false,
Expand All @@ -51,15 +49,15 @@ curl -u "$AGENTFLOW_USER:$AGENTFLOW_PASS" -X PUT \

### `GET /api/repositories`

返回脱敏的 `Repository[]`,`200`;`gitToken` 被清空,以 `gitTokenConfigured` 表示状态。
返回 `Repository[]`,`200`。仓库不保存 Git 凭据。

### `GET /api/repositories/{id}`

返回一个脱敏后的 `Repository`;不存在返回 `404 {"error":"repository not found"}`。

### `POST|PUT /api/repositories`

新建或按 `id` 更新。`projectId`、`name`、`gongfengProjectId` 必填;`provider` 默认且只能是 `gongfeng`;`defaultBranch` 默认 `main`;`id` 为空时服务生成。更新时空 token 保留旧值,`gitTokenClear=true` 清除。成功 `200` 返回脱敏后的仓库;校验失败 `400`。
新建或按 `id` 更新。`projectId` 必填,可用 `repoUrl` 粘贴仓库地址。平台识别 GitHub 和部署适配器;其他 HTTPS 地址使用 `https`,显式 SSH 地址使用 `ssh`,不转换传输协议。`name` 可从地址推断,`defaultBranch` 默认 `main`,`id` 为空时服务生成。凭据通过 `/api/users/{id}/git-http-credentials` 或 `/api/users/{id}/git-ssh-keys` 管理。HTTPS 使用标准 Git credential helper;SSH 密钥可克隆和推送,创建 PR/MR 仍需要托管平台的访问令牌,由 Agent 节点完成。成功 `200` 返回仓库;校验失败 `400`。

```bash
curl -u "$AGENTFLOW_USER:$AGENTFLOW_PASS" -X POST \
Expand Down
15 changes: 4 additions & 11 deletions docs/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ paths:
put:
tags: [Users]
operationId: updateOwnCredentials
summary: Update credentials for the current authenticated user
summary: Update model credentials for the current authenticated user
description: Git access tokens are managed through /api/users/{id}/git-http-credentials.
parameters:
- name: id
in: path
Expand All @@ -674,8 +675,6 @@ paths:
schema:
type: object
properties:
gitToken: {type: string, writeOnly: true}
gitTokenClear: {type: boolean}
codeBuddyApiKey: {type: string, writeOnly: true}
codeBuddyApiKeyClear: {type: boolean}
codeBuddyInternetEnvironment: {type: string, description: "Edition that issued the CodeBuddy key: empty for International, \"internal\" for China, \"ioa\" for iOA (\"public\" and \"China\" are also accepted). Any other value is rejected with 400."}
Expand Down Expand Up @@ -4361,7 +4360,7 @@ components:
deptId: {type: integer}
deptName: {type: string}
avatarUrl: {type: string}
gitTokenConfigured: {type: boolean, readOnly: true}
gitHubCredentialConfigured: {type: boolean, readOnly: true}
codeBuddyApiKeyConfigured: {type: boolean, readOnly: true}
codexApiKeyConfigured: {type: boolean, readOnly: true}
codexBaseUrl: {type: string}
Expand Down Expand Up @@ -4401,7 +4400,7 @@ components:
type: string
provider:
type: string
description: GitHub for public repositories; inferred from the repository URL
description: "Inferred from the repository URL: github, gongfeng, https, or ssh. Unknown HTTPS hosts use Git transport without a hosting API adapter."
example: github
name:
type: string
Expand All @@ -4416,12 +4415,6 @@ components:
type: string
localPath:
type: string
gitToken:
type: string
writeOnly: true
gitTokenConfigured:
type: boolean
readOnly: true
pipelineProjectId:
type: integer
pipelineDefId:
Expand Down
2 changes: 2 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ docker compose exec -T mysql sh -c 'MYSQL_PWD="$MYSQL_PASSWORD" mysql -u loopfor

After it, a run of these SOPs commits and pushes its work branch and opens an MR/PR before 交付汇总, so the Git credentials of the run's responsible user need push access. The installer and `./start.sh pull` do not run it. It rewrites a template only while its node graph and 交付汇总 position are the shipped original, and the 交付汇总 prompt only while unedited; it is safe to repeat. Project SOPs adopted from these templates are copies and are not changed.

After migrating personal Git credentials, apply `038_generic_sop_host_credentials.sql` to update the original authentication instruction in the three built-in MR roles. The roles can use a hosting CLI, a configured MCP, or the host's API with a token obtained through `git credential fill`.

## GitHub credentials

Users can choose **Connect GitHub** in personal credentials or while adding a repository, copy the displayed PIN, and approve it on GitHub. The platform saves the grant to that signed-in user's existing Git credential slot. The repository picker lists repositories owned by the account, shared with it, or accessible through its organizations, supports pagination and search over loaded repositories, and copies the selected repository's real default branch into the form. PAT entry remains available.
Expand Down
2 changes: 1 addition & 1 deletion e2e/api/00-smoke.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ test('GET /api/deployment-metrics is not served', async () => {
test('current user resolves through the token and model credentials are explicit', async () => {
const users = list(await get('/api/users'));
assert.ok(users.length > 0);
const withCreds = users.filter(u => u.codeBuddyApiKeyConfigured || u.gitTokenConfigured);
const withCreds = users.filter(u => u.codeBuddyApiKeyConfigured || u.gitHubCredentialConfigured);
if(cfg.model) assert.ok(withCreds.length > 0, 'no user has any credential configured; model-backed scenarios cannot run');
});

Expand Down
Loading
Loading