diff --git a/AGENTS.md b/AGENTS.md index ed82f0e..fe7b387 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -56,9 +56,9 @@ Use `.env.local` for local secrets. Keep `.env.local` and any real token-bearing - When creating an issue, upload the selected rendered agent file as an issue asset along with screenshots and files. - The old Ready checkbox must not be shown because `Ready` is now one of the selectable labels. - Open Issues owns issue browsing and follow-up. It must list recent issues ordered by creation time, default to open issues for the active URL's linked repo, provide a checkbox to show issues across all loaded repos, and provide a status dropdown for Open, Closed, or Open + Closed. -- Selecting an Open Issues row must show a direct Open in Gitea link, editable issue subject/content fields, issue attachments, and comment chain, followed by a comment form that can add text, take additional screenshots, attach files, upload those files as issue assets, and submit a Gitea comment with attachment links. +- Selecting an Open Issues row must show a direct Open in Gitea link, editable issue subject/content/label fields, issue attachments, and comment chain, followed by direct issue attachment controls plus a comment form that can add text, take additional screenshots, attach files, upload those files as issue assets, and submit a Gitea comment with attachment links. - Saving selected issue edits must use the selected issue's repo identity from Open Issues and must never fall back to the active tab's repo. -- Existing issue rows must allow deleting the issue. Existing issue labels must be editable from the selected issue form. Existing issue attachments must be removable. Deletion must require user confirmation. +- Existing issue rows must allow deleting the issue. Existing issue labels must be editable from the selected issue form and saved through the Gitea issue labels endpoint. Existing issue attachments must be removable, and additional screenshots/files must be uploadable directly to the issue without creating a comment. Deletion must require user confirmation. - Text-entry updates in Add Issue, selected issue edits, Open Issues comments, and Agents must not re-render the focused form control or blur the user while they type. - Keep the Add Issue view dense; do not show the redundant view header title/description inside this view. - The extension requests `activeTab` and `` host permission so screenshots can be captured from the current Chrome tab even after the side panel has stayed open across tab changes. diff --git a/README.md b/README.md index 659c177..881910b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ The deployable extension output is `dist/`. Load `dist/` in Chrome as an unpacke Static assets, including the extension icon assets, live in `public/` and are copied into `dist/` during the build. -The app opens in the Chrome side panel. The top icon menu includes Add URL, URLs, Gitea repos, Workspaces, Agents, Open Issues, and Add Issue. Add URL is enabled only for an active tab base URL that is not already in the URLs list. URLs can be deleted from the list. The Agents view manages persisted agent files, starting with `GLOBAL AGENT` from `AGENTS.md`; agents can use variables such as `{{git}}`, `{{workspace}}`, and `{{url}}` in their markdown content. Add Issue is enabled when the active tab base URL is already linked to a Gitea repo; it shows the active URL being attached, creates an issue with the selected agent and selected labels, and uploads the rendered agent file plus accumulated screenshots and files as issue assets. Captured screenshots can be expanded, removed, or cropped with a wider no-horizontal-scroll crop panel. Open Issues lists recent issues by creation time, defaults to open issues for the current repo, can expand to all loaded repos, can filter Open/Closed/Open + Closed, and lets a selected issue open directly in Gitea, edit subject/content/labels against that issue's repo, view attachments and comments, and add a comment with screenshots and file attachments. Rows can be deleted, and existing issue attachments can be deleted. +The app opens in the Chrome side panel. The top icon menu includes Add URL, URLs, Gitea repos, Workspaces, Agents, Open Issues, and Add Issue. Add URL is enabled only for an active tab base URL that is not already in the URLs list. URLs can be deleted from the list. The Agents view manages persisted agent files, starting with `GLOBAL AGENT` from `AGENTS.md`; agents can use variables such as `{{git}}`, `{{workspace}}`, and `{{url}}` in their markdown content. Add Issue is enabled when the active tab base URL is already linked to a Gitea repo; it shows the active URL being attached, creates an issue with the selected agent and selected labels, and uploads the rendered agent file plus accumulated screenshots and files as issue assets. Captured screenshots can be expanded, removed, or cropped with a wider no-horizontal-scroll crop panel. Open Issues lists recent issues by creation time, defaults to open issues for the current repo, can expand to all loaded repos, can filter Open/Closed/Open + Closed, and lets a selected issue open directly in Gitea, edit subject/content/labels against that issue's repo, view attachments and comments, upload more screenshots/files directly to the issue, and add a comment with screenshots and file attachments. Rows can be deleted, and existing issue attachments can be deleted. Builds generate `public/local-context.json` from `/Users/Tabitha/.openclaw/workspace_Father`. That snapshot links known workspaces to local Gitea repos and is copied into `dist/` so the built extension is self-contained. diff --git a/docs/extension-management.md b/docs/extension-management.md index 6a9a526..6b73607 100644 --- a/docs/extension-management.md +++ b/docs/extension-management.md @@ -59,9 +59,10 @@ Required variables: - The `Only current repo` checkbox defaults to checked and limits the table to the active URL's linked Gitea repo. - Turning off `Only current repo` loads recent issues from all repos already loaded in the extension. - The status dropdown defaults to `Open` and supports `Open`, `Closed`, and `Open + Closed`. -- Selecting an issue shows a direct Open in Gitea link, editable issue subject/content/label fields, issue attachments, comment chain, and a comment form for text, additional screenshots, and file attachments. -- Saving selected issue edits must use the repo identity from the selected Open Issues row and must not fall back to the active tab's repo. +- Selecting an issue shows a direct Open in Gitea link, editable issue subject/content/label fields, issue attachments, direct attachment upload controls, comment chain, and a comment form for text, additional screenshots, and file attachments. +- Saving selected issue edits must use the repo identity from the selected Open Issues row, save labels through Gitea's issue labels endpoint, and must not fall back to the active tab's repo. - Issue comments should upload screenshots/files as issue assets first, then create a comment containing links to those attachments. +- Additional selected-issue screenshots/files can also be uploaded directly as issue assets without creating a comment. - Existing issue attachments can be deleted from the selected issue. - Existing issue rows can delete the issue. Issue labels are edited in the selected issue form. Deletion must require confirmation. - Typing in Add Issue, selected issue edit fields, Open Issues comments, or Agents editor fields must not blur the focused control. diff --git a/llm.txt b/llm.txt index 04998eb..fc7ea1d 100644 --- a/llm.txt +++ b/llm.txt @@ -19,7 +19,7 @@ Important files: Build with `npm run build`. The deployable output directory is `dist/`; load that folder in Chrome as an unpacked extension or point deployment tooling at it. Do not edit `dist/` directly. -UI behavior: the app renders as a Chrome side panel, not a draggable window. The menu items are Add URL, URLs, Gitea Repos, Workspaces, Agents, Open Issues, and Add Issue. Add URL is enabled only when the active tab base URL is not already known; the user must choose either a workspace or a Gitea repo, and the app infers the linked counterpart. URLs can be deleted from the list; user-added URLs are removed from storage, while generated known URLs are hidden through stored deleted bases. The Agents view manages persisted agent files and starts with `GLOBAL AGENT` backed by `AGENTS.md`; agent markdown can use `{{git}}`, `{{repo}}`, `{{workspace}}`, `{{url}}`, `{{baseUrl}}`, `{{profile}}`, and `{{issue}}` template variables. Add Issue is enabled only when the active tab base URL is known and linked to a Gitea repo. It shows the target repo and active URL, captures visible-tab screenshots with thumbnails, accepts accumulated file attachments, lets the user select an agent file and issue labels, creates the Gitea issue with the selected labels, and uploads the rendered agent file plus all screenshots/files. The label options are Change Request, Idea, Tabitha, Orson, Belisarius, Ozymandias, and Ready; new issues default to Change Request. Captured screenshots can be expanded, removed, or cropped with a wider no-horizontal-scroll draggable/resizable crop panel. Created issue bodies include `Chrome profile: Silma` and the selected agent. Open Issues lists recent issues by creation time, defaults to open issues for the active URL's linked repo through an `Only current repo` checkbox, can load recent issues across all loaded repos, supports Open/Closed/Open + Closed status filtering, and shows selected issue subject/content/label edit fields that save against the selected issue repo, a direct Open in Gitea link, attachments, comment chains, and a comment form with text, screenshots, and file attachments. Existing issue rows can be deleted after confirmation, and existing issue attachments can be deleted. Text-entry state updates must not blur focused Add Issue, selected issue edit, Open Issues comment, or Agents editor controls. Gitea repos are ordered by latest default-branch commit. Workspace and URL views show established links between local workspaces, known URLs, and Gitea repos. +UI behavior: the app renders as a Chrome side panel, not a draggable window. The menu items are Add URL, URLs, Gitea Repos, Workspaces, Agents, Open Issues, and Add Issue. Add URL is enabled only when the active tab base URL is not already known; the user must choose either a workspace or a Gitea repo, and the app infers the linked counterpart. URLs can be deleted from the list; user-added URLs are removed from storage, while generated known URLs are hidden through stored deleted bases. The Agents view manages persisted agent files and starts with `GLOBAL AGENT` backed by `AGENTS.md`; agent markdown can use `{{git}}`, `{{repo}}`, `{{workspace}}`, `{{url}}`, `{{baseUrl}}`, `{{profile}}`, and `{{issue}}` template variables. Add Issue is enabled only when the active tab base URL is known and linked to a Gitea repo. It shows the target repo and active URL, captures visible-tab screenshots with thumbnails, accepts accumulated file attachments, lets the user select an agent file and issue labels, creates the Gitea issue with the selected labels, and uploads the rendered agent file plus all screenshots/files. The label options are Change Request, Idea, Tabitha, Orson, Belisarius, Ozymandias, and Ready; new issues default to Change Request. Captured screenshots can be expanded, removed, or cropped with a wider no-horizontal-scroll draggable/resizable crop panel. Created issue bodies include `Chrome profile: Silma` and the selected agent. Open Issues lists recent issues by creation time, defaults to open issues for the active URL's linked repo through an `Only current repo` checkbox, can load recent issues across all loaded repos, supports Open/Closed/Open + Closed status filtering, and shows selected issue subject/content/label edit fields that save against the selected issue repo, a direct Open in Gitea link, attachments, comment chains, direct selected-issue screenshot/file attachment uploads, and a comment form with text, screenshots, and file attachments. Existing issue rows can be deleted after confirmation, and existing issue attachments can be deleted. Text-entry state updates must not blur focused Add Issue, selected issue edit, Open Issues comment, or Agents editor controls. Gitea repos are ordered by latest default-branch commit. Workspace and URL views show established links between local workspaces, known URLs, and Gitea repos. Extension management rule: use the Codex Chrome extension with the Chrome profile named `Silma`. Do not use `Profile 1`. diff --git a/manifest.llm.json b/manifest.llm.json index 97a9d6b..2935e1f 100644 --- a/manifest.llm.json +++ b/manifest.llm.json @@ -61,7 +61,7 @@ "delete_url_behavior": "URLs can be deleted from the list. User-added URLs are removed from chrome.storage.local; generated known URLs are hidden by storing their base URL in silmaAide.deletedUrlBases.", "add_issue_behavior": "The form shows the target repo and active URL for the active known URL, lets the user select an agent file and issue labels, captures visible-tab screenshots with thumbnails, accepts accumulated file attachments, creates a Gitea issue with the selected labels, and uploads the rendered agent file plus all screenshots/files as issue assets. Label options are Change Request, Idea, Tabitha, Orson, Belisarius, Ozymandias, and Ready; new issues default to Change Request. Captured screenshots can be expanded, removed, or cropped with a wider no-horizontal-scroll draggable/resizable crop panel. Issue bodies include Chrome profile: Silma and the selected agent. The view intentionally omits the redundant Add Issue header copy.", "open_issues_behavior": "Open Issues lists recent issues ordered by creation time. The Only current repo checkbox defaults to true and limits rows to the active URL's linked Gitea repo; disabling it loads recent issues from all repos already loaded by the extension. The status dropdown defaults to Open and supports Open, Closed, and Open + Closed.", - "issue_comment_behavior": "Open Issues owns existing issue follow-up. Selecting an issue shows a direct Open in Gitea link, editable issue subject/content/label fields that save against the selected issue repo, issue attachments, comment chain, and a comment form that accepts text, screenshots, and file attachments, uploads attachments as issue assets, and submits a Gitea issue comment with attachment links. Existing issue attachments can be deleted. Issue rows can delete the issue after confirmation. Draft text-entry updates must not blur focused Add Issue, selected issue edit, Open Issues comment, or Agents editor controls.", + "issue_comment_behavior": "Open Issues owns existing issue follow-up. Selecting an issue shows a direct Open in Gitea link, editable issue subject/content/label fields that save against the selected issue repo through Gitea's issue labels endpoint, issue attachments, direct attachment upload controls, comment chain, and a comment form that accepts text, screenshots, and file attachments, uploads attachments as issue assets, and submits a Gitea issue comment with attachment links. Existing issue attachments can be deleted, and additional selected-issue screenshots/files can be uploaded directly as issue assets without creating a comment. Issue rows can delete the issue after confirmation. Draft text-entry updates must not blur focused Add Issue, selected issue edit, Open Issues comment, or Agents editor controls.", "known_urls": [ { "url": "http://100.66.226.22:23030/", diff --git a/src/api.ts b/src/api.ts index b2ca571..5bd57ce 100644 --- a/src/api.ts +++ b/src/api.ts @@ -203,6 +203,14 @@ function getGiteaErrorMessage(error: unknown, fallback: string): string { return status ? `${fallback} Gitea returned ${status}: ${detail}` : `${fallback} ${detail}`; } +function getLabelName(label: unknown): string { + if (typeof label !== "object" || !label || typeof (label as { name?: unknown }).name !== "string") { + return ""; + } + + return (label as { name: string }).name; +} + export async function getCurrentGiteaUser(): Promise { const client = createGiteaClient(); const response = await client.get("/user"); @@ -253,13 +261,27 @@ export async function setGiteaIssueLabels( owner: string, repo: string, issueNumber: number, - labelIds: number[] -): Promise { + labelNames: string[] +): Promise { const client = createGiteaClient(); try { - await client.put(`/repos/${owner}/${repo}/issues/${issueNumber}/labels`, { - labels: labelIds + const response = await client.put(`/repos/${owner}/${repo}/issues/${issueNumber}/labels`, { + labels: labelNames }); + + if (Array.isArray(response.data)) { + return response.data.map(getLabelName).filter(Boolean); + } + + if ( + response.data && + typeof response.data === "object" && + Array.isArray((response.data as { labels?: unknown[] }).labels) + ) { + return (response.data as { labels: unknown[] }).labels.map(getLabelName).filter(Boolean); + } + + return labelNames; } catch (error) { throw new Error(getGiteaErrorMessage(error, "Could not update the Gitea issue labels.")); } diff --git a/src/main.ts b/src/main.ts index 5c847c3..b0daddc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -358,12 +358,17 @@ function renderAddUrl(): string { `; } -function renderFileList(files: File[], target: "issue" | "comment"): string { +function renderFileList(files: File[], target: "issue" | "comment" | "issue-attachment"): string { if (!files.length) { return `No files selected.`; } - const attribute = target === "issue" ? "data-delete-issue-file" : "data-delete-comment-file"; + const attribute = + target === "issue" + ? "data-delete-issue-file" + : target === "comment" + ? "data-delete-comment-file" + : "data-delete-issue-asset-file"; return `
@@ -466,13 +471,21 @@ function renderIssueComments(comments: GiteaIssueComment[]): string { `; } -function renderScreenshotList(screenshots: ScreenshotAttachment[], deleteAction: "issue" | "comment"): string { +function renderScreenshotList( + screenshots: ScreenshotAttachment[], + deleteAction: "issue" | "comment" | "issue-attachment" +): string { if (!screenshots.length) { return `No screenshots captured.`; } - const attribute = deleteAction === "issue" ? "data-delete-screenshot" : "data-delete-comment-screenshot"; - const previewTarget = deleteAction === "issue" ? "issue" : "comment"; + const attribute = + deleteAction === "issue" + ? "data-delete-screenshot" + : deleteAction === "comment" + ? "data-delete-comment-screenshot" + : "data-delete-issue-asset-screenshot"; + const previewTarget = deleteAction; return `
@@ -501,7 +514,12 @@ function getPreviewScreenshot(): ScreenshotAttachment | null { return null; } - const screenshots = preview.target === "issue" ? state.issueDraft.screenshots : state.issueCommentDraft.screenshots; + const screenshots = + preview.target === "issue" + ? state.issueDraft.screenshots + : preview.target === "comment" + ? state.issueCommentDraft.screenshots + : state.issueAttachmentDraft.screenshots; return screenshots.find((screenshot) => screenshot.id === preview.id) ?? null; } @@ -612,6 +630,32 @@ function renderIssueCommentForm(issue: GiteaIssueSummary): string { `; } +function renderIssueAttachmentForm(): string { + const state = appStore.getState(); + const draft = state.issueAttachmentDraft; + const canUpload = Boolean(draft.screenshots.length || draft.files.length) && !state.isUploadingIssueAttachments; + + return ` +
+
+ Add attachments + +
+ ${renderScreenshotList(draft.screenshots, "issue-attachment")} + + ${renderFileList(draft.files, "issue-attachment")} + +
+ `; +} + function renderSelectedIssueDetail(): string { const state = appStore.getState(); const detail = state.selectedIssueDetail; @@ -625,7 +669,9 @@ function renderSelectedIssueDetail(): string { } const draft = state.selectedIssueEditDraft; - const detailLabels = ISSUE_LABEL_OPTIONS.filter((label) => detail.issue.labels.includes(label)); + const detailLabels = ISSUE_LABEL_OPTIONS.filter((label) => + detail.issue.labels.some((issueLabel) => issueLabel.toLowerCase() === label.toLowerCase()) + ); const hasChanges = draft.subject !== detail.issue.title || draft.content !== detail.issue.body || @@ -662,6 +708,7 @@ function renderSelectedIssueDetail(): string { Attachments
${renderIssueAttachments(detail.attachments)} + ${renderIssueAttachmentForm()}
Comments @@ -946,7 +993,7 @@ function bindViewActions(): void { button.addEventListener("click", () => { const id = button.dataset.previewScreenshot; const target = button.dataset.previewTarget; - if (id && (target === "issue" || target === "comment")) { + if (id && (target === "issue" || target === "comment" || target === "issue-attachment")) { appStore.getState().openScreenshotPreview(target, id); } }); @@ -1020,6 +1067,38 @@ function bindViewActions(): void { }); }); + viewContent?.querySelector("#issue-asset-files")?.addEventListener("change", (event) => { + const input = event.target as HTMLInputElement; + appStore.getState().setIssueAttachmentFiles(Array.from(input.files ?? [])); + input.value = ""; + }); + + viewContent?.querySelector("#capture-issue-asset-screenshot")?.addEventListener("click", () => { + void appStore.getState().captureIssueAttachmentScreenshot(); + }); + + viewContent?.querySelectorAll("[data-delete-issue-asset-screenshot]").forEach((button) => { + button.addEventListener("click", () => { + const id = button.dataset.deleteIssueAssetScreenshot; + if (id) { + appStore.getState().deleteIssueAttachmentScreenshot(id); + } + }); + }); + + viewContent?.querySelectorAll("[data-delete-issue-asset-file]").forEach((button) => { + button.addEventListener("click", () => { + const index = Number(button.dataset.deleteIssueAssetFile); + if (Number.isInteger(index)) { + appStore.getState().deleteIssueAttachmentFile(index); + } + }); + }); + + viewContent?.querySelector("#upload-issue-assets")?.addEventListener("click", () => { + void appStore.getState().uploadSelectedIssueAttachments(); + }); + viewContent?.querySelector("#issue-comment-content")?.addEventListener("input", (event) => { appStore.getState().setIssueCommentDraft({ content: (event.target as HTMLTextAreaElement).value @@ -1264,7 +1343,9 @@ function syncFocusedFormControls(): void { } if (saveSelectedIssue && state.selectedIssueDetail) { - const detailLabels = ISSUE_LABEL_OPTIONS.filter((label) => state.selectedIssueDetail?.issue.labels.includes(label)); + const detailLabels = ISSUE_LABEL_OPTIONS.filter((label) => + state.selectedIssueDetail?.issue.labels.some((issueLabel) => issueLabel.toLowerCase() === label.toLowerCase()) + ); saveSelectedIssue.disabled = !state.selectedIssueEditDraft.subject.trim() || state.isUpdatingIssue || diff --git a/src/store.ts b/src/store.ts index fee87e3..e5720a2 100644 --- a/src/store.ts +++ b/src/store.ts @@ -26,7 +26,7 @@ import type { KnownUrl, LocalGiteaRepoLink, LocalWorkspace } from "./localContex export type StatusTone = "neutral" | "success" | "error"; export type AppView = "urls" | "repos" | "workspaces" | "agents" | "open-issues" | "add-url" | "add-issue"; export type AddUrlMode = "workspace" | "repo"; -export type ScreenshotTarget = "issue" | "comment"; +export type ScreenshotTarget = "issue" | "comment" | "issue-attachment"; export type OpenIssuesStateFilter = GiteaIssueStateFilter; export const CHROME_PROFILE_NAME = "Silma"; @@ -129,6 +129,11 @@ interface IssueCommentDraft { files: File[]; } +interface IssueAttachmentDraft { + screenshots: ScreenshotAttachment[]; + files: File[]; +} + interface IssueEditDraft { subject: string; content: string; @@ -161,6 +166,7 @@ interface AppState { addUrlDraft: AddUrlDraft; issueDraft: IssueDraft; issueCommentDraft: IssueCommentDraft; + issueAttachmentDraft: IssueAttachmentDraft; agents: AgentProfile[]; agentDraft: AgentProfile; editingAgentId: string | null; @@ -182,8 +188,10 @@ interface AppState { isTestingConnection: boolean; isCapturingScreenshot: boolean; isCapturingIssueCommentScreenshot: boolean; + isCapturingIssueAttachmentScreenshot: boolean; isCreatingIssue: boolean; isCreatingIssueComment: boolean; + isUploadingIssueAttachments: boolean; isUpdatingIssue: boolean; statusMessage: string; statusTone: StatusTone; @@ -198,6 +206,9 @@ interface AppState { setIssueCommentFiles: (files: File[]) => void; deleteIssueCommentFile: (index: number) => void; deleteIssueCommentScreenshot: (id: string) => void; + setIssueAttachmentFiles: (files: File[]) => void; + deleteIssueAttachmentFile: (index: number) => void; + deleteIssueAttachmentScreenshot: (id: string) => void; setAgentDraft: (draft: Partial) => void; startNewAgent: () => void; editAgent: (id: string) => void; @@ -219,6 +230,8 @@ interface AppState { deleteIssue: (issueNumber: number, repoFullName?: string) => Promise; deleteSelectedIssueAttachment: (attachmentId: number) => Promise; captureIssueCommentScreenshot: () => Promise; + captureIssueAttachmentScreenshot: () => Promise; + uploadSelectedIssueAttachments: () => Promise; createIssueComment: () => Promise; captureScreenshot: () => Promise; createIssue: () => Promise; @@ -559,9 +572,16 @@ function normalizeIssueLabels(labels: string[]): IssueLabelOption[] { return ISSUE_LABEL_OPTIONS.filter((option) => labels.some((label) => label.toLowerCase() === option.toLowerCase())); } -async function ensureIssueLabels(owner: string, repo: string, labels: IssueLabelOption[]): Promise { +async function ensureIssueLabels( + owner: string, + repo: string, + labels: IssueLabelOption[] +): Promise<{ ids: number[]; names: string[] }> { const ensuredLabels = await Promise.all(labels.map((label) => ensureGiteaLabel(owner, repo, label))); - return ensuredLabels.map((label) => label.id); + return { + ids: ensuredLabels.map((label) => label.id), + names: ensuredLabels.map((label) => label.name) + }; } function getAgentById(id: string, agents: AgentProfile[]): AgentProfile { @@ -722,6 +742,10 @@ export const appStore = createStore()((set, get) => ({ screenshots: [], files: [] }, + issueAttachmentDraft: { + screenshots: [], + files: [] + }, agents: AVAILABLE_AGENTS, agentDraft: AVAILABLE_AGENTS[0], editingAgentId: AVAILABLE_AGENTS[0].id, @@ -747,8 +771,10 @@ export const appStore = createStore()((set, get) => ({ isTestingConnection: false, isCapturingScreenshot: false, isCapturingIssueCommentScreenshot: false, + isCapturingIssueAttachmentScreenshot: false, isCreatingIssue: false, isCreatingIssueComment: false, + isUploadingIssueAttachments: false, isUpdatingIssue: false, statusMessage: "", statusTone: "neutral", @@ -823,6 +849,27 @@ export const appStore = createStore()((set, get) => ({ screenshots: state.issueCommentDraft.screenshots.filter((screenshot) => screenshot.id !== id) } })), + setIssueAttachmentFiles: (files) => + set((state) => ({ + issueAttachmentDraft: { + ...state.issueAttachmentDraft, + files: appendFiles(state.issueAttachmentDraft.files, files) + } + })), + deleteIssueAttachmentFile: (index) => + set((state) => ({ + issueAttachmentDraft: { + ...state.issueAttachmentDraft, + files: state.issueAttachmentDraft.files.filter((_file, fileIndex) => fileIndex !== index) + } + })), + deleteIssueAttachmentScreenshot: (id) => + set((state) => ({ + issueAttachmentDraft: { + ...state.issueAttachmentDraft, + screenshots: state.issueAttachmentDraft.screenshots.filter((screenshot) => screenshot.id !== id) + } + })), setAgentDraft: (draft) => set((state) => ({ agentDraft: { @@ -945,7 +992,12 @@ export const appStore = createStore()((set, get) => ({ return; } - const screenshots = preview.target === "issue" ? state.issueDraft.screenshots : state.issueCommentDraft.screenshots; + const screenshots = + preview.target === "issue" + ? state.issueDraft.screenshots + : preview.target === "comment" + ? state.issueCommentDraft.screenshots + : state.issueAttachmentDraft.screenshots; const screenshot = screenshots.find((item) => item.id === preview.id); if (!screenshot) { @@ -965,13 +1017,25 @@ export const appStore = createStore()((set, get) => ({ }, screenshotPreview: null } - : { - issueCommentDraft: { - ...current.issueCommentDraft, - screenshots: current.issueCommentDraft.screenshots.map((item) => (item.id === preview.id ? cropped : item)) - }, - screenshotPreview: null - } + : preview.target === "comment" + ? { + issueCommentDraft: { + ...current.issueCommentDraft, + screenshots: current.issueCommentDraft.screenshots.map((item) => + item.id === preview.id ? cropped : item + ) + }, + screenshotPreview: null + } + : { + issueAttachmentDraft: { + ...current.issueAttachmentDraft, + screenshots: current.issueAttachmentDraft.screenshots.map((item) => + item.id === preview.id ? cropped : item + ) + }, + screenshotPreview: null + } ); setStatus(set, `Cropped ${screenshot.name}.`, "success"); } catch (error) { @@ -988,8 +1052,10 @@ export const appStore = createStore()((set, get) => ({ if (preview.target === "issue") { appStore.getState().deleteIssueScreenshot(preview.id); - } else { + } else if (preview.target === "comment") { appStore.getState().deleteIssueCommentScreenshot(preview.id); + } else { + appStore.getState().deleteIssueAttachmentScreenshot(preview.id); } set({ screenshotPreview: null }); @@ -1012,6 +1078,10 @@ export const appStore = createStore()((set, get) => ({ content: "", screenshots: [], files: [] + }, + issueAttachmentDraft: { + screenshots: [], + files: [] } }), setOpenIssuesStateFilter: (stateFilter) => @@ -1032,6 +1102,10 @@ export const appStore = createStore()((set, get) => ({ content: "", screenshots: [], files: [] + }, + issueAttachmentDraft: { + screenshots: [], + files: [] } }), selectIssue: (issueNumber, repoFullName) => @@ -1066,6 +1140,10 @@ export const appStore = createStore()((set, get) => ({ content: "", screenshots: [], files: [] + }, + issueAttachmentDraft: { + screenshots: [], + files: [] } })), loadOpenIssues: async (force = false) => { @@ -1302,15 +1380,19 @@ export const appStore = createStore()((set, get) => ({ setStatus(set, `Saving issue #${issueNumber}...`, "neutral", { autoClear: false }); try { - const labelIds = await ensureIssueLabels(target.owner, target.repo, state.selectedIssueEditDraft.labels); + const selectedLabels = state.selectedIssueEditDraft.labels; + const ensuredLabels = await ensureIssueLabels(target.owner, target.repo, selectedLabels); const updatedIssue = await updateGiteaIssue(target.owner, target.repo, issueNumber, { title: subject, body: state.selectedIssueEditDraft.content }); - await setGiteaIssueLabels(target.owner, target.repo, issueNumber, labelIds); + const savedLabels = await setGiteaIssueLabels(target.owner, target.repo, issueNumber, ensuredLabels.names); + const normalizedSavedLabels = normalizeIssueLabels( + savedLabels.length || !selectedLabels.length ? savedLabels : ensuredLabels.names + ); const issueWithLabels = { ...updatedIssue, - labels: state.selectedIssueEditDraft.labels + labels: normalizedSavedLabels }; const updatedOpenIssue = toOpenIssue(issueWithLabels, target); @@ -1394,7 +1476,14 @@ export const appStore = createStore()((set, get) => ({ screenshots: [], files: [] } - : state.issueCommentDraft + : state.issueCommentDraft, + issueAttachmentDraft: + state.selectedIssueNumber === issueNumber && state.selectedIssueRepoFullName === target.fullName + ? { + screenshots: [], + files: [] + } + : state.issueAttachmentDraft })); await appStore.getState().loadOpenIssues(true); await appStore.getState().loadTargetIssues(true); @@ -1474,6 +1563,76 @@ export const appStore = createStore()((set, get) => ({ set({ isCapturingIssueCommentScreenshot: false }); } }, + captureIssueAttachmentScreenshot: async () => { + set({ isCapturingIssueAttachmentScreenshot: true }); + setStatus(set, "Capturing screenshot...", "neutral", { autoClear: false }); + + try { + const { dataUrl, blob } = await captureVisibleTab(); + const screenshot = createScreenshotAttachment(dataUrl, blob); + + set((state) => ({ + issueAttachmentDraft: { + ...state.issueAttachmentDraft, + screenshots: [...state.issueAttachmentDraft.screenshots, screenshot] + } + })); + setStatus(set, `Captured ${screenshot.name}.`, "success"); + } catch (error) { + const message = error instanceof Error ? error.message : "Could not capture a screenshot."; + setStatus(set, message, "error"); + } finally { + set({ isCapturingIssueAttachmentScreenshot: false }); + } + }, + uploadSelectedIssueAttachments: async () => { + const state = appStore.getState(); + const target = getIssueTarget(state); + const issueNumber = state.selectedIssueNumber; + const uploads = [ + ...state.issueAttachmentDraft.screenshots.map((screenshot) => ({ + name: screenshot.name, + blob: screenshot.blob + })), + ...state.issueAttachmentDraft.files.map((file) => ({ + name: file.name, + blob: file + })) + ]; + + if (!target || !issueNumber) { + setStatus(set, "Select an issue before uploading attachments.", "error"); + return; + } + + if (!uploads.length) { + setStatus(set, "Add a screenshot or file before uploading.", "error"); + return; + } + + set({ isUploadingIssueAttachments: true }); + setStatus(set, `Uploading attachments to issue #${issueNumber}...`, "neutral", { autoClear: false }); + + try { + for (const upload of uploads) { + await uploadGiteaIssueAttachment(target.owner, target.repo, issueNumber, upload.blob, upload.name); + } + + set({ + issueAttachmentDraft: { + screenshots: [], + files: [] + } + }); + await appStore.getState().loadSelectedIssueDetail(true); + setStatus(set, `Uploaded ${uploads.length} attachment${uploads.length === 1 ? "" : "s"}.`, "success"); + } catch (error) { + const message = error instanceof Error ? error.message : "Could not upload issue attachments."; + setStatus(set, message, "error"); + } finally { + set({ isUploadingIssueAttachments: false }); + } + }, createIssueComment: async () => { const state = appStore.getState(); const target = getIssueTarget(state); @@ -1562,7 +1721,7 @@ export const appStore = createStore()((set, get) => ({ setStatus(set, "Creating Gitea issue...", "neutral", { autoClear: false }); try { - const labelIds = await ensureIssueLabels(target.owner, target.repo, state.issueDraft.labels); + const { ids: labelIds } = await ensureIssueLabels(target.owner, target.repo, state.issueDraft.labels); const issue = await createGiteaIssue( target.owner, target.repo, diff --git a/src/styles.css b/src/styles.css index e841c40..5a1412a 100644 --- a/src/styles.css +++ b/src/styles.css @@ -727,6 +727,22 @@ input[readonly] { gap: 5px; } +.issue-asset-uploader { + margin-top: 8px; +} + +.issue-asset-uploader label { + display: grid; + gap: 5px; + min-width: 0; +} + +.issue-asset-uploader label > span { + color: #52616f; + font-size: 11px; + font-weight: 850; +} + .attachment-heading { display: flex; align-items: center;