Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 明确 GitHub Issue 发布方式与公开署名 (#819)

DavidShenXD1bfc70093b3b
diff --git a/apps/desktop/src/main/github-issue/__tests__/githubIssueSubmitService.test.ts b/apps/desktop/src/main/github-issue/__tests__/githubIssueSubmitService.test.ts
index 734ef6eba1..d7cd4aa74e 100644
--- a/apps/desktop/src/main/github-issue/__tests__/githubIssueSubmitService.test.ts
+++ b/apps/desktop/src/main/github-issue/__tests__/githubIssueSubmitService.test.ts
@@ -27,6 +27,7 @@ function makeDeps(over: Partial<GithubIssueSubmitServiceDeps> = {}) {
title: REQ.title,
body: REQ.body,
type: REQ.type,
+ publicName: 'Carol',
uiLanguage: 'zh-CN',
}),
);
@@ -70,6 +71,7 @@ describe('submitGithubIssueWithConfirm', () => {
title: '用户改过的标题',
body: '用户改过的正文',
type: 'feature',
+ publicName: '公开昵称',
uiLanguage: 'ja',
}));
const { deps, postIssue } = makeDeps({ confirm });
@@ -85,6 +87,7 @@ describe('submitGithubIssueWithConfirm', () => {
region: 'cn',
},
PLATFORM_IDENTITY,
+ 'Carol',
);
expect(postIssue).toHaveBeenCalledTimes(1);
expect(postIssue.mock.calls[0]![0]).toEqual(PLATFORM_IDENTITY);
@@ -92,7 +95,7 @@ describe('submitGithubIssueWithConfirm', () => {
expect(posted.title).toBe('用户改过的标题');
expect(posted.type).toBe('feature');
expect(posted.appVersion).toBe('0.0.112');
- expect(posted.userName).toBe('Carol');
+ expect(posted.userName).toBe('公开昵称');
expect(posted.description).toContain('用户改过的正文');
expect(posted.description).toContain('**版本区域**: CN');
expect(posted.description).toContain('**OS**: darwin arm64 (25.5.0)');
@@ -146,6 +149,7 @@ describe('submitGithubIssueWithConfirm', () => {
title: REQ.title,
body: REQ.body,
type: REQ.type,
+ publicName: 'Carol',
})),
});
const res = await submitGithubIssueWithConfirm(deps, REQ);
@@ -153,29 +157,68 @@ describe('submitGithubIssueWithConfirm', () => {
expect(postIssue.mock.calls[0]![1]().description).toContain('**界面语言**: en');
});
- it('membership 没有展示名时省略 userName,由 server 回退到 membership id', async () => {
- const { deps, postIssue } = makeDeps({ getSubmitterName: () => undefined });
+ it('membership 没有展示名时不提供建议值,仍使用用户确认的匿名署名', async () => {
+ const confirm = vi.fn<GithubIssueSubmitServiceDeps['confirm']>(
+ async (): Promise<IssueConfirmDecision> => ({
+ confirmed: true,
+ title: REQ.title,
+ body: REQ.body,
+ type: REQ.type,
+ publicName: '匿名',
+ uiLanguage: 'zh-CN',
+ }),
+ );
+ const { deps, postIssue } = makeDeps({ getSubmitterName: () => undefined, confirm });
const res = await submitGithubIssueWithConfirm(deps, REQ);
expect(res).toMatchObject({ ok: true });
- expect(postIssue.mock.calls[0]![1]()).not.toHaveProperty('userName');
+ expect(confirm.mock.calls[0]![4]).toBeUndefined();
+ expect(postIssue.mock.calls[0]![1]().userName).toBe('匿名');
});
- it('网络重试重建 body 时重新读取当前 membership 展示名', async () => {
+ it('网络重试重建 body 时锁定用户确认的公开署名,不重新读取 membership 展示名', async () => {
const getSubmitterName = vi
.fn<() => string | undefined>()
.mockReturnValueOnce('Account A')
.mockReturnValueOnce('Account B');
+ const confirm = vi.fn<GithubIssueSubmitServiceDeps['confirm']>(
+ async (): Promise<IssueConfirmDecision> => ({
+ confirmed: true,
+ title: REQ.title,
+ body: REQ.body,
+ type: REQ.type,
+ publicName: '用户确认的昵称',
+ uiLanguage: 'zh-CN',
+ }),
+ );
const postIssue = vi.fn<GithubIssueSubmitServiceDeps['postIssue']>(
async (_identity, bodyFactory) => {
- expect(bodyFactory().userName).toBe('Account A');
- expect(bodyFactory().userName).toBe('Account B');
+ expect(bodyFactory().userName).toBe('用户确认的昵称');
+ expect(bodyFactory().userName).toBe('用户确认的昵称');
return { githubIssue: { number: 80, url: 'https://example.com/issues/80' } };
},
);
- const { deps } = makeDeps({ getSubmitterName, postIssue });
+ const { deps } = makeDeps({ getSubmitterName, confirm, postIssue });
const res = await submitGithubIssueWithConfirm(deps, REQ);
expect(res).toMatchObject({ ok: true });
- expect(getSubmitterName).toHaveBeenCalledTimes(2);
+ expect(confirm.mock.calls[0]![4]).toBe('Account A');
+ expect(getSubmitterName).toHaveBeenCalledTimes(1);
+ });
+
+ it('平台代发没有确认有效公开署名时不提交', async () => {
+ for (const publicName of [undefined, '', 'line 1\nline 2']) {
+ const { deps, postIssue } = makeDeps({
+ confirm: vi.fn(async () => ({
+ confirmed: true as const,
+ title: REQ.title,
+ body: REQ.body,
+ type: REQ.type,
+ publicName,
+ })),
+ });
+ const res = await submitGithubIssueWithConfirm(deps, REQ);
+ expect(res).toMatchObject({ ok: false, errorCode: 'USER_CANCELLED' });
+ expect(postIssue).not.toHaveBeenCalled();
+ }
});
it('clamp: 超长 body 被裁但 env 块完整保留;超长 title 裁到 200', async () => {
@@ -187,6 +230,7 @@ describe('submitGithubIssueWithConfirm', () => {
title: longTitle,
body: longBody,
type: 'bug' as const,
+ publicName: 'Carol',
uiLanguage: 'zh-CN',
})),
});
@@ -219,7 +263,9 @@ describe('submitGithubIssueWithConfirm', () => {
const res = await submitGithubIssueWithConfirm(deps, REQ);
expect(res).toMatchObject({ ok: true });
expect(confirm.mock.calls[0]![3]).toEqual(identity);
+ expect(confirm.mock.calls[0]![4]).toBeUndefined();
expect(postIssue.mock.calls[0]![0]).toEqual(identity);
+ expect(postIssue.mock.calls[0]![1]()).not.toHaveProperty('userName');
});
it('身份解析失败时不弹确认卡、不提交', async () => {
diff --git a/apps/desktop/src/main/github-issue/__tests__/issueConfirmBridge.test.ts b/apps/desktop/src/main/github-issue/__tests__/issueConfirmBridge.test.ts
index 653cbd2fcb..c636e804f0 100644
--- a/apps/desktop/src/main/github-issue/__tests__/issueConfirmBridge.test.ts
+++ b/apps/desktop/src/main/github-issue/__tests__/issueConfirmBridge.test.ts
@@ -82,6 +82,66 @@ describe('IssueConfirmBridge', () => {
});
});
+ it('平台代发把建议署名传给卡片,并要求响应带有效公开署名', async () => {
+ const broadcast = vi.fn();
+ const warn = vi.fn();
+ const bridge = new IssueConfirmBridge({ broadcast, logger: { warn } });
+ const platformIdentity = { kind: 'platform', login: 'cindy-issue' } as const;
+ const promise = bridge.request('sess-1', DRAFT, ENV, platformIdentity, '当前昵称');
+ const requestId = lastRequestId(broadcast);
+ expect(broadcast).toHaveBeenCalledWith(
+ MAKER_PUSH.INTERACTION_REQUEST,
+ expect.objectContaining({
+ request: expect.objectContaining({
+ submissionIdentity: platformIdentity,
+ suggestedPublicName: '当前昵称',
+ }),
+ }),
+ );
+
+ expect(
+ bridge.resolve(requestId, {
+ confirmed: true,
+ title: DRAFT.title,
+ body: DRAFT.body,
+ type: DRAFT.type,
+ publicName: ' 匿名 ',
+ }),
+ ).toBe(true);
+ await expect(promise).resolves.toMatchObject({
+ confirmed: true,
+ publicName: '匿名',
+ });
+ expect(warn).not.toHaveBeenCalled();
+ });
+
+ it('平台代发缺少署名或携带换行时按取消兜底', async () => {
+ for (const publicName of [undefined, '', '第一行\n第二行']) {
+ const broadcast = vi.fn();
+ const warn = vi.fn();
+ const bridge = new IssueConfirmBridge({ broadcast, logger: { warn } });
+ const promise = bridge.request(
+ 'sess-1',
+ DRAFT,
+ ENV,
+ { kind: 'platform', login: 'cindy-issue' },
+ '当前昵称',
+ );
+ const requestId = lastRequestId(broadcast);
+ expect(
+ bridge.resolve(requestId, {
+ confirmed: true,
+ title: DRAFT.title,
+ body: DRAFT.body,
+ type: DRAFT.type,
+ publicName,
+ }),
+ ).toBe(true);
+ await expect(promise).resolves.toEqual({ confirmed: false, reason: 'cancelled' });
+ expect(warn).toHaveBeenCalled();
+ }
+ });
+
it('resolve 取消 decision → cancelled;未知 requestId → 返 false', async () => {
const broadcast = vi.fn();
const bridge = new IssueConfirmBridge({ broadcast });
diff --git a/apps/desktop/src/main/github-issue/githubIssueSubmitService.ts b/apps/desktop/src/main/github-issue/githubIssueSubmitService.ts
index 30f74c2017..bbcee2fffc 100644
--- a/apps/desktop/src/main/github-issue/githubIssueSubmitService.ts
+++ b/apps/desktop/src/main/github-issue/githubIssueSubmitService.ts
@@ -13,6 +13,7 @@
import type { CindyRegion } from '@cindy/maker-shared/brand-identity';
import { ISSUE_REGION_CODE } from '../../shared/issueRegionCode.js';
+import { normalizeIssuePublicName } from '../../shared/issuePublicName.js';
import type {
IssueConfirmDecision,
IssueDraft,
@@ -68,6 +69,7 @@ export interface GithubIssueSubmitServiceDeps {
draft: IssueDraft,
env: IssueEnvInfo,
submissionIdentity: IssueSubmissionIdentity,
+ suggestedPublicName?: string,
) => Promise<IssueConfirmDecision>;
/** 每次发起确认前现查;已绑定但凭证失效时应抛 AUTH_NOT_READY,不能冒充未绑定。 */
resolveSubmissionIdentity: (workingDir: string) => Promise<IssueSubmissionIdentity>;
@@ -107,11 +109,16 @@ export async function submitGithubIssueWithConfirm(
return mapSubmitError(err);
}
+ const suggestedPublicName =
+ submissionIdentity.kind === 'platform'
+ ? (normalizeIssuePublicName(deps.getSubmitterName()) ?? undefined)
+ : undefined;
const decision = await deps.confirm(
req.sessionId,
{ title: req.title, body: req.body, type: req.type },
env,
submissionIdentity,
+ suggestedPublicName,
);
if (!decision.confirmed) {
@@ -129,6 +136,16 @@ export async function submitGithubIssueWithConfirm(
};
}
+ const confirmedPublicName =
+ submissionIdentity.kind === 'platform' ? normalizeIssuePublicName(decision.publicName) : null;
+ if (submissionIdentity.kind === 'platform' && !confirmedPublicName) {
+ return {
+ ok: false,
+ errorCode: 'USER_CANCELLED',
+ message: '公开署名未确认,本次 issue 未提交。请重新发起并确认署名。',
+ };
+ }
+
// 用户确认版优先 —— agent 传入值在这里被丢弃,代码层保证。
const finalTitle = decision.title.slice(0, SERVER_TITLE_MAX);
const editedByUser =
@@ -151,16 +168,13 @@ export async function submitGithubIssueWithConfirm(
const description = decision.body.slice(0, Math.max(0, bodyBudget)) + envBlock;
try {
- const result = await deps.postIssue(submissionIdentity, () => {
- const submitterName = deps.getSubmitterName()?.trim();
- return {
- title: finalTitle,
- description,
- type: decision.type,
- appVersion: env.appVersion,
- ...(submitterName ? { userName: submitterName } : {}),
- };
- });
+ const result = await deps.postIssue(submissionIdentity, () => ({
+ title: finalTitle,
+ description,
+ type: decision.type,
+ appVersion: env.appVersion,
+ ...(confirmedPublicName ? { userName: confirmedPublicName } : {}),
+ }));
return {
ok: true,
issueNumber: result.githubIssue.number,
diff --git a/apps/desktop/src/main/github-issue/index.ts b/apps/desktop/src/main/github-issue/index.ts
index f7fb252830..78cc7fb4d2 100644
--- a/apps/desktop/src/main/github-issue/index.ts
+++ b/apps/desktop/src/main/github-issue/index.ts
@@ -71,8 +71,8 @@ export async function submitGithubIssueForSession(
};
return submitGithubIssueWithConfirm(
{
- confirm: (sessionId, draft, env, submissionIdentity) =>
- bridge.request(sessionId, draft, env, submissionIdentity),
+ confirm: (sessionId, draft, env, submissionIdentity, suggestedPublicName) =>
+ bridge.request(sessionId, draft, env, submissionIdentity, suggestedPublicName),
resolveSubmissionIdentity: (workdir) =>
resolveGithubIssueSubmissionIdentity(githubUserSubmitterDeps, workdir),
postIssue: (submissionIdentity, bodyFactory) => {
diff --git a/apps/desktop/src/main/github-issue/issueConfirmBridge.ts b/apps/desktop/src/main/github-issue/issueConfirmBridge.ts
index 7ab5b8976b..ad53085640 100644
--- a/apps/desktop/src/main/github-issue/issueConfirmBridge.ts
+++ b/apps/desktop/src/main/github-issue/issueConfirmBridge.ts
@@ -21,6 +21,7 @@ import { randomUUID } from 'node:crypto';
import type { CindyRegion } from '@cindy/maker-shared/brand-identity';
+import { normalizeIssuePublicName } from '../../shared/issuePublicName.js';
import { MAKER_PUSH } from '../maker-ipc/channels';
export interface IssueDraft {
@@ -53,6 +54,8 @@ export type IssueConfirmDecision =
title: string;
body: string;
type: 'bug' | 'feature';
+ /** 平台代发时由用户确认的公开署名;GitHub 用户直发时不存在。 */
+ publicName?: string;
/** renderer 当前界面语言(i18n.language);main 侧 OS locale 仅作 fallback。 */
uiLanguage?: string;
}
@@ -72,6 +75,7 @@ const DEFAULT_TIMEOUT_MS = 10 * 60 * 1000;
interface PendingConfirmEntry {
sessionId: string;
+ requiresPublicName: boolean;
resolve: (decision: IssueConfirmDecision) => void;
timeoutId: ReturnType<typeof setTimeout>;
}
@@ -87,6 +91,7 @@ export class IssueConfirmBridge {
draft: IssueDraft,
env: IssueEnvInfo,
submissionIdentity: IssueSubmissionIdentity,
+ suggestedPublicName?: string,
): Promise<IssueConfirmDecision> {
const requestId = randomUUID();
return new Promise<IssueConfirmDecision>((resolve) => {
@@ -94,10 +99,22 @@ export class IssueConfirmBridge {
const timeoutId = setTimeout(() => {
this.settle(requestId, { confirmed: false, reason: 'timeout' }, 'timeout');
}, timeoutMs);
- this.pending.set(requestId, { sessionId, resolve, timeoutId });
+ this.pending.set(requestId, {
+ sessionId,
+ requiresPublicName: submissionIdentity.kind === 'platform',
+ resolve,
+ timeoutId,
+ });
this.deps.broadcast(MAKER_PUSH.INTERACTION_REQUEST, {
sessionId,
- request: { kind: 'issue_confirm', requestId, draft, env, submissionIdentity },
+ request: {
+ kind: 'issue_confirm',
+ requestId,
+ draft,
+ env,
+ submissionIdentity,
+ suggestedPublicName,
+ },
});
});
}
@@ -109,7 +126,7 @@ export class IssueConfirmBridge {
resolve(requestId: string, rawDecision: unknown): boolean {
const entry = this.pending.get(requestId);
if (!entry) return false;
- let decision = parseDecision(rawDecision);
+ let decision = parseDecision(rawDecision, entry.requiresPublicName);
if (!decision) {
// shape 非法按取消兜底,避免 tool handler 永久挂起。
this.deps.logger?.warn('issue-confirm: invalid decision shape, fallback to cancelled', {
@@ -169,7 +186,7 @@ export class IssueConfirmBridge {
}
}
-function parseDecision(raw: unknown): IssueConfirmDecision | null {
+function parseDecision(raw: unknown, requiresPublicName: boolean): IssueConfirmDecision | null {
if (!raw || typeof raw !== 'object') return null;
const obj = raw as Record<string, unknown>;
if (obj.confirmed === false) {
@@ -183,11 +200,14 @@ function parseDecision(raw: unknown): IssueConfirmDecision | null {
obj.body.trim().length > 0 &&
(obj.type === 'bug' || obj.type === 'feature')
) {
+ const publicName = requiresPublicName ? normalizeIssuePublicName(obj.publicName) : undefined;
+ if (requiresPublicName && !publicName) return null;
return {
confirmed: true,
title: obj.title.trim(),
body: obj.body.trim(),
type: obj.type,
+ ...(publicName ? { publicName } : {}),
uiLanguage: typeof obj.uiLanguage === 'string' ? obj.uiLanguage : undefined,
};
}
diff --git a/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts b/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts
index d2519661c0..c70c14463a 100644
--- a/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts
+++ b/apps/desktop/src/renderer/__tests__/deviceLinkInteractionScenarios.test.ts
@@ -315,7 +315,8 @@ describe('device-link 远程交互往返 — issue_confirm draft', () => {
arch: 'arm64',
osVersion: '15.0',
},
- submissionIdentity: { kind: 'github-user', login: 'tester' },
+ submissionIdentity: { kind: 'platform', login: 'cindy-issue' },
+ suggestedPublicName: '当前昵称',
};
it('逐键保存不通知 makerChatStore 全局订阅,响应后清除草稿', async () => {
@@ -323,6 +324,10 @@ describe('device-link 远程交互往返 — issue_confirm draft', () => {
host.hostInteraction(s, issueRequest);
await flush();
expect(makerChatStore.getSnapshot(s).pendingIssueConfirm?.requestId).toBe('issue-draft-1');
+ expect(makerChatStore.getSnapshot(s).pendingIssueConfirm).toMatchObject({
+ submissionIdentity: { kind: 'platform', login: 'cindy-issue' },
+ suggestedPublicName: '当前昵称',
+ });
const globalListener = vi.fn();
const unsubscribe = makerChatStore.subscribeAll(globalListener);
@@ -330,12 +335,14 @@ describe('device-link 远程交互往返 — issue_confirm draft', () => {
title: '编辑后的标题',
body: '编辑后的正文',
type: 'feature',
+ publicName: '匿名',
});
expect(getIssueConfirmDraft(s, 'issue-draft-1')).toMatchObject({
title: '编辑后的标题',
body: '编辑后的正文',
type: 'feature',
+ publicName: '匿名',
});
expect(globalListener).not.toHaveBeenCalled();
diff --git a/apps/desktop/src/renderer/__tests__/issueConfirmPayload.test.ts b/apps/desktop/src/renderer/__tests__/issueConfirmPayload.test.ts
index 59c8f0fe2a..3690aa910f 100644
--- a/apps/desktop/src/renderer/__tests__/issueConfirmPayload.test.ts
+++ b/apps/desktop/src/renderer/__tests__/issueConfirmPayload.test.ts
@@ -1,6 +1,10 @@
import { describe, expect, it } from 'vitest';
-import { parseIssueEnvRegion, parseIssueSubmissionIdentity } from '@/lib/issueConfirmPayload';
+import {
+ parseIssueEnvRegion,
+ parseIssueSuggestedPublicName,
+ parseIssueSubmissionIdentity,
+} from '@/lib/issueConfirmPayload';
describe('parseIssueSubmissionIdentity', () => {
it('保留 GitHub 用户和平台的实际 login', () => {
@@ -37,3 +41,19 @@ describe('parseIssueEnvRegion', () => {
expect(parseIssueEnvRegion(1)).toBeUndefined();
});
});
+
+describe('parseIssueSuggestedPublicName', () => {
+ it('trims a valid single-line public name', () => {
+ expect(parseIssueSuggestedPublicName(' Cindy User ')).toBe('Cindy User');
+ });
+
+ it('drops empty, over-long, control-character and line-separator values', () => {
+ expect(parseIssueSuggestedPublicName('')).toBeUndefined();
+ expect(parseIssueSuggestedPublicName('x'.repeat(101))).toBeUndefined();
+ expect(parseIssueSuggestedPublicName('line 1\nline 2')).toBeUndefined();
+ expect(parseIssueSuggestedPublicName('line 1\u0085line 2')).toBeUndefined();
+ expect(parseIssueSuggestedPublicName('line 1\u009fline 2')).toBeUndefined();
+ expect(parseIssueSuggestedPublicName('line 1\u2028line 2')).toBeUndefined();
+ expect(parseIssueSuggestedPublicName('line 1\u2029line 2')).toBeUndefined();
+ });
+});
diff --git a/apps/desktop/src/renderer/features/cc-agent/IssueConfirmCard.tsx b/apps/desktop/src/renderer/features/cc-agent/IssueConfirmCard.tsx
index 0eb4f8defb..209f92744e 100644
--- a/apps/desktop/src/renderer/features/cc-agent/IssueConfirmCard.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/IssueConfirmCard.tsx
@@ -24,6 +24,7 @@ import {
import { cn } from '@/lib/utils';
import type { PendingIssueConfirm } from '@/lib/makerChatStore';
import { shouldLabelIssueRegion } from '../../../shared/issueRegionCode';
+import { ISSUE_PUBLIC_NAME_MAX, normalizeIssuePublicName } from '../../../shared/issuePublicName';
interface IssueConfirmCardProps {
sessionId: string;
@@ -35,6 +36,7 @@ interface IssueConfirmCardProps {
title: string;
body: string;
type: 'bug' | 'feature';
+ publicName?: string;
uiLanguage: string;
}
| { confirmed: false },
@@ -51,17 +53,36 @@ export function IssueConfirmCard({ sessionId, pending, onRespond }: IssueConfirm
const { t, i18n } = useTranslation();
const titleInputId = useId();
const bodyInputId = useId();
+ const publicNameInputId = useId();
const [draft, setDraft] = useState<IssueConfirmDraft>(
- () => getIssueConfirmDraft(sessionId, pending.requestId) ?? pending.draft,
+ () =>
+ getIssueConfirmDraft(sessionId, pending.requestId) ?? {
+ ...pending.draft,
+ ...(pending.submissionIdentity.kind === 'platform'
+ ? {
+ publicName: pending.suggestedPublicName ?? t('issueAgent.confirm.anonymous'),
+ }
+ : {}),
+ },
);
- const { title, body, type } = draft;
+ const { title, body, type, publicName = '' } = draft;
- const canSubmit = title.trim().length > 0 && body.trim().length > 0;
+ const confirmedPublicName =
+ pending.submissionIdentity.kind === 'platform' ? normalizeIssuePublicName(publicName) : null;
+ const canSubmit =
+ title.trim().length > 0 &&
+ body.trim().length > 0 &&
+ (pending.submissionIdentity.kind !== 'platform' || confirmedPublicName !== null);
const updateDraft = useCallback(
(patch: Partial<IssueConfirmDraft>) => {
const next = { ...draft, ...patch };
- if (next.title === draft.title && next.body === draft.body && next.type === draft.type) {
+ if (
+ next.title === draft.title &&
+ next.body === draft.body &&
+ next.type === draft.type &&
+ next.publicName === draft.publicName
+ ) {
return;
}
// Save synchronously with the input event so an immediate session switch
@@ -93,9 +114,10 @@ export function IssueConfirmCard({ sessionId, pending, onRespond }: IssueConfirm
title: title.trim(),
body: body.trim(),
type,
+ ...(confirmedPublicName ? { publicName: confirmedPublicName } : {}),
uiLanguage: i18n.language,
});
- }, [canSubmit, onRespond, title, body, type, i18n.language]);
+ }, [canSubmit, confirmedPublicName, onRespond, title, body, type, i18n.language]);
const handleCancel = useCallback(() => {
onRespond({ confirmed: false });
@@ -192,16 +214,74 @@ export function IssueConfirmCard({ sessionId, pending, onRespond }: IssueConfirm
)}
/>
+ {/* 发布方式由 Main 预先选定;确认阶段只展示实际通道,不提供不可用切换。 */}
+ <div
+ className={cn(
+ 'mt-3 rounded-[8px] border p-3',
+ 'border-[var(--perm-code-border)] bg-[var(--perm-code-bg)]',
+ )}
+ >
+ <p className="select-none text-12 font-medium text-[var(--status-bar-meta)]">
+ {t('issueAgent.confirm.submissionMethodLabel')}
+ </p>
+ <p className="mt-1 text-13 leading-snug text-[var(--chat-input-text)]">
+ {pending.submissionIdentity.kind === 'github-user'
+ ? t('issueAgent.confirm.identityGithubUser', {
+ login: pending.submissionIdentity.login,
+ })
+ : t('issueAgent.confirm.identityPlatform', {
+ login: pending.submissionIdentity.login,
+ })}
+ </p>
+ <p className="mt-1 text-12 leading-snug text-[var(--status-bar-meta)]">
+ {pending.submissionIdentity.kind === 'github-user'
+ ? t('issueAgent.confirm.identityGithubUserHint')
+ : t('issueAgent.confirm.identityPlatformHint')}
+ </p>
+
+ {pending.submissionIdentity.kind === 'platform' && (
+ <>
+ <label
+ htmlFor={publicNameInputId}
+ className="mt-3 block select-none text-12 font-medium text-[var(--status-bar-meta)]"
+ >
+ {t('issueAgent.confirm.publicNameLabel')}
+ </label>
+ <div className="mt-1 flex flex-wrap items-center gap-2">
+ <input
+ id={publicNameInputId}
+ type="text"
+ value={publicName}
+ maxLength={ISSUE_PUBLIC_NAME_MAX}
+ onChange={(event) => updateDraft({ publicName: event.target.value })}
+ className={cn(
+ 'min-w-0 flex-[1_1_220px] rounded-full border px-3 py-2',
+ 'border-[var(--chat-input-border)] bg-[var(--chat-input-bg)]',
+ 'text-13 leading-tight text-[var(--chat-input-text)]',
+ 'focus:outline-none focus:ring-1 focus:ring-[var(--focus-ring)]',
+ )}
+ />
+ <button
+ type="button"
+ onClick={() => updateDraft({ publicName: t('issueAgent.confirm.anonymous') })}
+ className={cn(
+ 'shrink-0 rounded-full border px-3 py-2',
+ 'border-[var(--chat-input-border)] bg-transparent',
+ 'select-none text-13 font-medium text-[var(--chat-input-text)]',
+ 'transition-colors hover:bg-[var(--chat-input-bg)]',
+ )}
+ >
+ {t('issueAgent.confirm.useAnonymous')}
+ </button>
+ </div>
+ <p className="mt-1 text-12 leading-snug text-[var(--status-bar-meta)]">
+ {t('issueAgent.confirm.publicNameHint')}
+ </p>
+ </>
+ )}
+ </div>
+
{/* 只读环境信息(main 侧自动附进 issue body) */}
- <p className="mt-2 text-12 leading-tight text-[var(--status-bar-meta)]">
- {pending.submissionIdentity.kind === 'github-user'
- ? t('issueAgent.confirm.identityGithubUser', {
- login: pending.submissionIdentity.login,
- })
- : t('issueAgent.confirm.identityPlatform', {
- login: pending.submissionIdentity.login,
- })}
- </p>
{regionCode && (
<p className="mt-1 text-12 leading-tight text-[var(--status-bar-meta)]">
{t('issueAgent.confirm.regionLine', { region: regionCode })}
diff --git a/apps/desktop/src/renderer/features/cc-agent/__tests__/IssueConfirmCard.test.tsx b/apps/desktop/src/renderer/features/cc-agent/__tests__/IssueConfirmCard.test.tsx
index 04f82681df..ba75c96cd2 100644
--- a/apps/desktop/src/renderer/features/cc-agent/__tests__/IssueConfirmCard.test.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/__tests__/IssueConfirmCard.test.tsx
@@ -34,6 +34,15 @@ const initialPending: PendingIssueConfirm = {
},
};
+const platformPending: PendingIssueConfirm = {
+ ...initialPending,
+ submissionIdentity: {
+ kind: 'platform',
+ login: 'cindy-issue',
+ },
+ suggestedPublicName: '当前昵称',
+};
+
function Harness() {
const [visible, setVisible] = useState(true);
@@ -135,4 +144,94 @@ describe('IssueConfirmCard draft persistence', () => {
'会话 A 的编辑',
);
});
+
+ it('restores the platform public name after a session-switch remount', () => {
+ function PlatformHarness() {
+ const [visible, setVisible] = useState(true);
+ return (
+ <>
+ <button type="button" onClick={() => setVisible((current) => !current)}>
+ switch platform session
+ </button>
+ {visible ? (
+ <IssueConfirmCard sessionId="session-a" pending={platformPending} onRespond={vi.fn()} />
+ ) : null}
+ </>
+ );
+ }
+
+ render(<PlatformHarness />);
+ fireEvent.change(screen.getByLabelText('issueAgent.confirm.publicNameLabel'), {
+ target: { value: '编辑后的昵称' },
+ });
+ fireEvent.click(screen.getByRole('button', { name: 'switch platform session' }));
+ fireEvent.click(screen.getByRole('button', { name: 'switch platform session' }));
+ expect(
+ (screen.getByLabelText('issueAgent.confirm.publicNameLabel') as HTMLInputElement).value,
+ ).toBe('编辑后的昵称');
+ });
+});
+
+describe('IssueConfirmCard submission identity', () => {
+ it('GitHub direct publishing only shows the selected account', () => {
+ render(<IssueConfirmCard sessionId="session-a" pending={initialPending} onRespond={vi.fn()} />);
+ expect(screen.getByText('issueAgent.confirm.identityGithubUser')).not.toBeNull();
+ expect(screen.getByText('issueAgent.confirm.identityGithubUserHint')).not.toBeNull();
+ expect(screen.queryByLabelText('issueAgent.confirm.publicNameLabel')).toBeNull();
+ });
+
+ it('platform publishing submits the edited public name', () => {
+ const onRespond = vi.fn();
+ render(
+ <IssueConfirmCard sessionId="session-a" pending={platformPending} onRespond={onRespond} />,
+ );
+ const input = screen.getByLabelText('issueAgent.confirm.publicNameLabel') as HTMLInputElement;
+ expect(input.value).toBe('当前昵称');
+ fireEvent.change(input, { target: { value: ' 公开昵称 ' } });
+ fireEvent.click(screen.getByRole('button', { name: /issueAgent\.confirm\.submit/ }));
+ expect(onRespond).toHaveBeenCalledWith(
+ expect.objectContaining({
+ confirmed: true,
+ publicName: '公开昵称',
+ }),
+ );
+ });
+
+ it('platform publishing can switch to the localized anonymous attribution', () => {
+ const onRespond = vi.fn();
+ render(
+ <IssueConfirmCard
+ sessionId="session-a"
+ pending={{ ...platformPending, requestId: 'issue-request-anonymous' }}
+ onRespond={onRespond}
+ />,
+ );
+ fireEvent.click(screen.getByRole('button', { name: 'issueAgent.confirm.useAnonymous' }));
+ expect(
+ (screen.getByLabelText('issueAgent.confirm.publicNameLabel') as HTMLInputElement).value,
+ ).toBe('issueAgent.confirm.anonymous');
+ fireEvent.click(screen.getByRole('button', { name: /issueAgent\.confirm\.submit/ }));
+ expect(onRespond).toHaveBeenCalledWith(
+ expect.objectContaining({
+ confirmed: true,
+ publicName: 'issueAgent.confirm.anonymous',
+ }),
+ );
+ });
+
+ it('platform publishing rejects empty public names and constrains the input', () => {
+ render(
+ <IssueConfirmCard
+ sessionId="session-a"
+ pending={{ ...platformPending, requestId: 'issue-request-invalid' }}
+ onRespond={vi.fn()}
+ />,
+ );
+ const input = screen.getByLabelText('issueAgent.confirm.publicNameLabel');
+ const submit = screen.getByRole('button', { name: /issueAgent\.confirm\.submit/ });
+ fireEvent.change(input, { target: { value: '' } });
+ expect((submit as HTMLButtonElement).disabled).toBe(true);
+ expect((input as HTMLInputElement).type).toBe('text');
+ expect((input as HTMLInputElement).maxLength).toBe(100);
+ });
});
diff --git a/apps/desktop/src/renderer/hooks/useCCAgentChat.ts b/apps/desktop/src/renderer/hooks/useCCAgentChat.ts
index ad3cab77d9..f805cfb5d2 100644
--- a/apps/desktop/src/renderer/hooks/useCCAgentChat.ts
+++ b/apps/desktop/src/renderer/hooks/useCCAgentChat.ts
@@ -228,6 +228,7 @@ interface UseCCAgentChatReturn {
title: string;
body: string;
type: 'bug' | 'feature';
+ publicName?: string;
uiLanguage: string;
}
| { confirmed: false },
@@ -550,6 +551,7 @@ export function useCCAgentChat(
title: string;
body: string;
type: 'bug' | 'feature';
+ publicName?: string;
uiLanguage: string;
}
| { confirmed: false },
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 1d4f98eb37..d3e346c603 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -6387,13 +6387,20 @@
"typeFeature": "Feature",
"titleLabel": "Title",
"bodyLabel": "Body (Markdown)",
- "identityGithubUser": "Submitting identity: GitHub user @{{login}} (you)",
- "identityPlatform": "Submitting identity: Cindy platform (GitHub App {{login}})",
+ "submissionMethodLabel": "Publishing Method",
+ "identityGithubUser": "Publish directly through GitHub account @{{login}}",
+ "identityGithubUserHint": "You will be the GitHub author and can edit or close this Issue on GitHub",
+ "identityPlatform": "Publish through Cindy (GitHub App {{login}})",
+ "identityPlatformHint": "You will not be the GitHub author and cannot edit or close this Issue yourself",
+ "publicNameLabel": "Public Attribution",
+ "publicNameHint": "This attribution will appear publicly in the Issue body",
+ "anonymous": "Anonymous",
+ "useAnonymous": "Use Anonymous Attribution",
"envLine": "Attached automatically on submit: client {{appVersion}} · {{platform}} {{arch}} · UI language {{uiLanguage}}",
"regionLine": "Build region: {{region}}",
"regionCodeCn": "CN",
"regionCodeDev": "Dev",
- "submit": "Submit",
+ "submit": "Submit Feedback",
"cancel": "Cancel"
},
"redirect": {
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index a801a6a4f6..e07e49c67d 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -6377,13 +6377,20 @@
"typeFeature": "機能要望",
"titleLabel": "タイトル",
"bodyLabel": "本文(Markdown)",
- "identityGithubUser": "送信者:GitHub ユーザー @{{login}}(本人)",
- "identityPlatform": "送信者:Cindy プラットフォームによる代理送信(GitHub App {{login}})",
+ "submissionMethodLabel": "公開方法",
+ "identityGithubUser": "GitHub アカウント @{{login}} から直接公開",
+ "identityGithubUserHint": "GitHub 上の Issue 作成者となり、自分で編集またはクローズできます",
+ "identityPlatform": "Cindy が代理で公開(GitHub App {{login}})",
+ "identityPlatformHint": "GitHub 上の Issue 作成者にはならず、自分で編集またはクローズできません",
+ "publicNameLabel": "公開署名",
+ "publicNameHint": "この署名は Issue 本文に公開表示されます",
+ "anonymous": "匿名",
+ "useAnonymous": "匿名の署名を使用",
"envLine": "送信時に自動で付加されます:クライアント {{appVersion}} · {{platform}} {{arch}} · 表示言語 {{uiLanguage}}",
"regionLine": "リージョン:{{region}}",
"regionCodeCn": "CN",
"regionCodeDev": "Dev",
- "submit": "送信",
+ "submit": "フィードバックを送信",
"cancel": "キャンセル"
},
"redirect": {
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 2283e1a5f0..c784d712fa 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -6377,13 +6377,20 @@
"typeFeature": "기능 제안",
"titleLabel": "제목",
"bodyLabel": "본문(Markdown)",
- "identityGithubUser": "제출 계정: GitHub 사용자 @{{login}}(본인)",
- "identityPlatform": "제출 계정: Cindy 플랫폼 대리 제출(GitHub App {{login}})",
+ "submissionMethodLabel": "게시 방식",
+ "identityGithubUser": "GitHub 계정 @{{login}}에서 직접 게시",
+ "identityGithubUserHint": "GitHub의 Issue 작성자가 되며 직접 수정하거나 닫을 수 있습니다",
+ "identityPlatform": "Cindy에서 대신 게시(GitHub App {{login}})",
+ "identityPlatformHint": "GitHub의 Issue 작성자가 아니므로 직접 수정하거나 닫을 수 없습니다",
+ "publicNameLabel": "공개 서명",
+ "publicNameHint": "이 서명은 Issue 본문에 공개적으로 표시됩니다",
+ "anonymous": "익명",
+ "useAnonymous": "익명 서명 사용",
"envLine": "제출 시 자동으로 첨부됩니다: 클라이언트 {{appVersion}} · {{platform}} {{arch}} · 표시 언어 {{uiLanguage}}",
"regionLine": "지역: {{region}}",
"regionCodeCn": "CN",
"regionCodeDev": "Dev",
- "submit": "제출",
+ "submit": "피드백 제출",
"cancel": "취소"
},
"redirect": {
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 2d2f7363f7..b26428c4ec 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -6377,13 +6377,20 @@
"typeFeature": "功能建议",
"titleLabel": "标题",
"bodyLabel": "正文(Markdown)",
- "identityGithubUser": "提交身份:GitHub 用户 @{{login}}(本人)",
- "identityPlatform": "提交身份:Cindy 平台代提交(GitHub App {{login}})",
+ "submissionMethodLabel": "发布方式",
+ "identityGithubUser": "通过 GitHub 账号 @{{login}} 直接发布",
+ "identityGithubUserHint": "你将成为该 Issue 的 GitHub 作者,可以在 GitHub 编辑或关闭",
+ "identityPlatform": "由 Cindy 平台代发(GitHub App {{login}})",
+ "identityPlatformHint": "你不是该 Issue 的 GitHub 作者,提交后无法自行编辑或关闭",
+ "publicNameLabel": "公开署名",
+ "publicNameHint": "该署名会公开显示在 Issue 正文中",
+ "anonymous": "匿名",
+ "useAnonymous": "使用匿名署名",
"envLine": "提交时将自动附加:客户端 {{appVersion}} · {{platform}} {{arch}} · 界面语言 {{uiLanguage}}",
"regionLine": "版本区域:{{region}}",
"regionCodeCn": "CN",
"regionCodeDev": "Dev",
- "submit": "提交",
+ "submit": "提交反馈",
"cancel": "取消"
},
"redirect": {
diff --git a/apps/desktop/src/renderer/lib/issueConfirmDraftStore.ts b/apps/desktop/src/renderer/lib/issueConfirmDraftStore.ts
index ca7c452b75..2b989d5b4d 100644
--- a/apps/desktop/src/renderer/lib/issueConfirmDraftStore.ts
+++ b/apps/desktop/src/renderer/lib/issueConfirmDraftStore.ts
@@ -1,8 +1,8 @@
/**
* In-memory drafts for the submit_github_issue confirmation card.
*
- * This input state is intentionally separate from makerChatStore: title/body
- * changes happen on every keystroke and must not invalidate running-status
+ * This input state is intentionally separate from makerChatStore: title/body/
+ * public-name changes happen on every keystroke and must not invalidate running-status
* snapshots or notify session/global chat subscribers. Keys include both the
* session and request so parallel sessions and consecutive requests cannot
* share edits. Renderer restart intentionally drops all entries.
@@ -12,6 +12,8 @@ export interface IssueConfirmDraft {
title: string;
body: string;
type: 'bug' | 'feature';
+ /** 平台代发时用户在确认卡片里编辑的公开署名。 */
+ publicName?: string;
}
const draftsBySession = new Map<string, Map<string, IssueConfirmDraft>>();
diff --git a/apps/desktop/src/renderer/lib/issueConfirmPayload.ts b/apps/desktop/src/renderer/lib/issueConfirmPayload.ts
index 0e7e55616c..cbece85cb9 100644
--- a/apps/desktop/src/renderer/lib/issueConfirmPayload.ts
+++ b/apps/desktop/src/renderer/lib/issueConfirmPayload.ts
@@ -1,4 +1,5 @@
import type { CindyRegion } from '@cindy/maker-shared/brand-identity';
+import { normalizeIssuePublicName } from '../../shared/issuePublicName';
/**
* issue_confirm IPC 里的构建区域。非法或缺失一律返回 undefined —— 确认卡片宁可
@@ -30,3 +31,8 @@ export function parseIssueSubmissionIdentity(raw: unknown): IssueSubmissionIdent
}
return { kind: obj.kind, login: obj.login.trim() };
}
+
+/** Main 提供的平台代发建议署名;非法值按缺失处理,由卡片回退为“匿名”。 */
+export function parseIssueSuggestedPublicName(raw: unknown): string | undefined {
+ return normalizeIssuePublicName(raw) ?? undefined;
+}
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 49cf10737e..6f123675ae 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -90,6 +90,7 @@ import { getMakerMemoryEnabled } from '@/lib/memorySettingsStore';
import { buildUserMessageAttachmentPayload } from '@/lib/messageAttachmentPayload';
import {
parseIssueEnvRegion,
+ parseIssueSuggestedPublicName,
parseIssueSubmissionIdentity,
type IssueSubmissionIdentity,
} from '@/lib/issueConfirmPayload';
@@ -593,6 +594,8 @@ export interface PendingIssueConfirm {
};
/** main 已经选定、确认后不会自动切换的实际 GitHub 作者身份。 */
submissionIdentity: IssueSubmissionIdentity;
+ /** 平台代发的建议公开署名;缺失时卡片使用本地化“匿名”。 */
+ suggestedPublicName?: string;
}
/**
@@ -3873,6 +3876,10 @@ function initGlobalListeners(): void {
| undefined;
const submissionIdentity = parseIssueSubmissionIdentity(request.submissionIdentity);
if (!draft || !rawEnv || !submissionIdentity) return;
+ const suggestedPublicName =
+ submissionIdentity.kind === 'platform'
+ ? parseIssueSuggestedPublicName(request.suggestedPublicName)
+ : undefined;
// region 过一遍白名单:非法值宁可不展示区域,也不能把 CN 版说成默认版。
const env = { ...rawEnv, region: parseIssueEnvRegion(rawEnv.region) };
setState(sessionId, (s) => ({
@@ -3882,6 +3889,7 @@ function initGlobalListeners(): void {
draft,
env,
submissionIdentity,
+ suggestedPublicName,
},
}));
return;
@@ -7855,13 +7863,20 @@ function respondToPermission(sessionId: string, result: CCAgentPermissionResult)
/**
* issue_confirm: 把确认卡片结果回给 main(IssueConfirmBridge)并清 pendingIssueConfirm。
- * confirmed=true 时携带卡片当前的 title/body/type(用户编辑版,main 以此为准)
- * 和 renderer 界面语言(uiLanguage,main 附进 issue body 的环境块)。
+ * confirmed=true 时携带卡片当前的 title/body/type(用户编辑版,main 以此为准)、
+ * 平台代发公开署名(publicName)和 renderer 界面语言(uiLanguage)。
*/
function respondToIssueConfirm(
sessionId: string,
result:
- | { confirmed: true; title: string; body: string; type: 'bug' | 'feature'; uiLanguage: string }
+ | {
+ confirmed: true;
+ title: string;
+ body: string;
+ type: 'bug' | 'feature';
+ publicName?: string;
+ uiLanguage: string;
+ }
| { confirmed: false },
): void {
if (!sessionId) return;
diff --git a/apps/desktop/src/shared/issuePublicName.ts b/apps/desktop/src/shared/issuePublicName.ts
new file mode 100644
index 0000000000..288fa7d074
--- /dev/null
+++ b/apps/desktop/src/shared/issuePublicName.ts
@@ -0,0 +1,28 @@
+/**
+ * 平台代发 GitHub Issue 时公开署名的跨进程契约。
+ *
+ * github-server 会把 userName 原样写进 Markdown 正文,因此这里同时限制长度与
+ * 单行纯文本形状。Renderer 用它控制提交状态,Main 在 IPC 边界再次校验。
+ */
+export const ISSUE_PUBLIC_NAME_MAX = 100;
+
+export function normalizeIssuePublicName(raw: unknown): string | null {
+ if (typeof raw !== 'string') return null;
+ const value = raw.trim();
+ if (value.length === 0 || value.length > ISSUE_PUBLIC_NAME_MAX) {
+ return null;
+ }
+ for (const character of value) {
+ const codePoint = character.codePointAt(0);
+ if (
+ codePoint === undefined ||
+ codePoint <= 0x1f ||
+ (codePoint >= 0x7f && codePoint <= 0x9f) ||
+ codePoint === 0x2028 ||
+ codePoint === 0x2029
+ ) {
+ return null;
+ }
+ }
+ return value;
+}