diff --git a/AGENTS.md b/AGENTS.md index 16d4b17..be857a5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -44,12 +44,14 @@ Use `.env.local` for local secrets. Keep `.env.local` and any real token-bearing - Runtime API calls are centralized in `src/api.ts`. - Side panel state is centralized in the vanilla Zustand store at `src/store.ts`. - The extension opens as a Chrome side panel. It is not a draggable in-page window. -- The side panel has icon menu sections for Add URL, URLs, Gitea repos, Workspaces, Agents, Issues, and Add Issue. +- The side panel has icon menu sections for Add URL, URLs, Gitea repos, Workspaces, Prompts, Issues, Add Issue, and Agents. Agents must stay as the far-right menu item. - Add URL is enabled only when the active tab's base URL is not already in the URLs list. The user must pick either a workspace or a Gitea repo; the app infers the linked counterpart from local context. - URLs can be deleted from the URLs list. User-added URLs are removed from storage; generated known URLs are hidden through the stored deleted-base list. - The Agents view lists available agent files and must allow adding, editing, and deleting persisted agents from `chrome.storage.local`. At least one agent must remain available. - The default `GLOBAL AGENT` is backed by `AGENTS.md` and contains agnostic handoff rules with template variables such as `{{git}}`, `{{workspace}}`, `{{url}}`, `{{baseUrl}}`, `{{profile}}`, and `{{issue}}`. It must tell downstream agents to close the Gitea issue after the implementation has been pushed, and to leave a Gitea issue comment when delivery is blocked, partial, or risky. -- Add Issue is enabled only when the active tab's base URL is already in the URLs list and has a linked Gitea repo. The issue form must show the target repo, the active URL the extension believes it is attached to, let the user select an agent file and issue labels, capture visible-tab screenshots, accept multiple accumulated Gitea-friendly file attachments, and include `Chrome profile: Silma` plus the selected agent in created issue bodies. +- The Prompts view manages workspace-scoped default prompts persisted in `chrome.storage.local` under `silmaAide.prompts`. Prompt records must include a name, workspace path, and content. +- Add Issue is enabled only when the active tab's base URL is already in the URLs list and has a linked Gitea repo. The issue form must show the target repo, the active URL the extension believes it is attached to, let the user select a workspace prompt above Content, let the user select an agent file and issue labels, capture visible-tab screenshots, accept multiple accumulated Gitea-friendly file attachments, and include `Chrome profile: Silma` plus the selected agent in created issue bodies. +- The Add Issue default prompt dropdown must only show prompts attached to the active URL's workspace path. Selecting a prompt copies its content into the editable Content field for human adjustment. - Clicking a captured screenshot must open an expanded preview with Close, Remove, and Crop controls. The crop area should be a simple draggable/resizable box without a shaded crop fill, and the preview panel should use the available viewport without horizontal scrolling. - Label options for issue creation and editing are `Change Request`, `Idea`, `Tabitha`, `Orson`, `Belisarius`, `Ozymandias`, and `Ready`. - Newly created issues must default to the `Change Request` label unless the user changes the selected labels. @@ -63,6 +65,7 @@ Use `.env.local` for local secrets. Keep `.env.local` and any real token-bearing - Text-entry updates in Add Issue, selected issue edits, 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. +- Gitea API errors should include the failed operation and, for network-level failures, the configured Gitea API base URL plus actionable checks for env, extension host permissions, network/VPN access, token scope, and attachment size. ## Chrome Extension Management diff --git a/README.md b/README.md index 4893706..6cafaa0 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, 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. The default global agent tells downstream agents to close the Gitea issue after pushing the implementation and to comment when delivery is blocked, partial, or risky. 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. Issues lists recent issues by creation time, defaults to open issues for the current repo, can expand to all loaded repos, has Open/Closed status checkboxes plus an empty-by-default label filter, and lets a selected issue open directly in Gitea, log a placeholder Send to Codex payload, edit subject/content/labels against that issue's repo with content-version readback verification, view attachments and comments, upload more screenshots/files directly to the issue, and add a comment with screenshots and file attachments. Clicking the selected issue row again or the detail close control collapses the detail panel. 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, Prompts, Issues, Add Issue, and Agents, with Agents pinned to the far right. 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 Prompts view manages workspace-scoped default prompts in `chrome.storage.local`; Add Issue shows matching prompts above Content and copies the selected prompt into the editable content field. 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. The default global agent tells downstream agents to close the Gitea issue after pushing the implementation and to comment when delivery is blocked, partial, or risky. 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. Issues lists recent issues by creation time, defaults to open issues for the current repo, can expand to all loaded repos, has Open/Closed status checkboxes plus an empty-by-default label filter, and lets a selected issue open directly in Gitea, log a placeholder Send to Codex payload, edit subject/content/labels against that issue's repo with content-version readback verification, view attachments and comments, upload more screenshots/files directly to the issue, and add a comment with screenshots and file attachments. Clicking the selected issue row again or the detail close control collapses the detail panel. Rows can be deleted, and existing issue attachments can be deleted. Gitea API errors include the failed operation and network-level failures identify the configured API base plus common checks. 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 3b9ba49..58d531a 100644 --- a/docs/extension-management.md +++ b/docs/extension-management.md @@ -39,6 +39,7 @@ Required variables: - Add Issue is enabled only when the active tab's base URL is already in the URLs list and that URL is linked to a Gitea repo. - The Add Issue view must show the Gitea repo that will receive the issue and the active URL the extension believes it is attached to. +- The Add Issue form must show a Default prompt dropdown immediately above Content. It should only list prompts whose workspace path matches the active known URL and should copy the selected prompt content into the editable Content field. - The Add Issue form must let the user select the agent file for handoff. Agents are managed in the Agents view, persisted in `chrome.storage.local`, and the initial agent is `GLOBAL AGENT` backed by `AGENTS.md`. - The default `GLOBAL AGENT` rules must instruct downstream agents to close the Gitea issue after pushing the implementation and to leave a Gitea issue comment when delivery is blocked, partial, or risky. - The Add Issue view intentionally omits the redundant view header title/description. @@ -68,7 +69,18 @@ Required variables: - 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, Issues comments, or Agents editor fields must not blur the focused control. +- Typing in Add Issue, selected issue edit fields, Issues comments, Agents editor fields, or Prompts editor fields must not blur the focused control. + +## Prompt Management + +- The Prompts menu item is workspace-scoped and stores prompt records in `silmaAide.prompts`. +- The Prompts view must allow adding, editing, and deleting prompts with a name, workspace path, and content. +- Agents must remain the far-right toolbar item when new menu items are added. + +## Gitea Error Reporting + +- Gitea API failures should surface the specific operation that failed, such as issue creation, label loading, attachment upload, comment creation, or repo loading. +- Network-level Gitea failures should include the configured Gitea API base URL and mention checks for `VITE_GITEA_BASE_URL`, Chrome extension host permissions, network/VPN access, token scope, and attachment size. ## URL Management diff --git a/index.html b/index.html index 9557c03..f74e586 100644 --- a/index.html +++ b/index.html @@ -26,9 +26,9 @@ Workspaces - +
diff --git a/llm.txt b/llm.txt index 766431a..da107d9 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, 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. The default global agent tells downstream agents to close the Gitea issue after pushing the implementation and to leave a Gitea issue comment when delivery is blocked, partial, or risky. 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. 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 status multiselect filtering, has an empty-by-default label filter, and shows selected issue subject/content/label edit fields that save against the selected issue repo with Gitea content-version readback verification, a direct Open in Gitea link, a placeholder Send to Codex console log action, attachments, comment chains, direct selected-issue screenshot/file attachment uploads, and a comment form with text, screenshots, and file attachments. Clicking the selected issue row again or the detail close control collapses the detail panel. 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, 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, Prompts, Issues, Add Issue, and Agents; Agents must stay at the far right. 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 Prompts view manages workspace-scoped default prompts in `chrome.storage.local` under `silmaAide.prompts`; Add Issue shows prompts matching the active URL workspace above Content and copies the selected prompt into the editable Content field for human adjustment. 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. The default global agent tells downstream agents to close the Gitea issue after pushing the implementation and to leave a Gitea issue comment when delivery is blocked, partial, or risky. 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. 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 status multiselect filtering, has an empty-by-default label filter, and shows selected issue subject/content/label edit fields that save against the selected issue repo with Gitea content-version readback verification, a direct Open in Gitea link, a placeholder Send to Codex console log action, attachments, comment chains, direct selected-issue screenshot/file attachment uploads, and a comment form with text, screenshots, and file attachments. Clicking the selected issue row again or the detail close control collapses the detail panel. 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, Issues comment, Agents editor controls, or Prompts editor controls. Gitea API errors include the failed operation and network-level failures identify the configured API base with env, permissions, network/VPN, token scope, and attachment-size checks. 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 6238a03..37b1362 100644 --- a/manifest.llm.json +++ b/manifest.llm.json @@ -43,7 +43,7 @@ "enabled": true }, { - "name": "Agents", + "name": "Prompts", "enabled": true }, { @@ -53,15 +53,22 @@ { "name": "Add Issue", "enabled": "when active tab base URL is known and linked to a Gitea repo" + }, + { + "name": "Agents", + "enabled": true, + "position": "far right" } ], "repo_ordering": "Gitea repos are ordered by latest default-branch commit timestamp.", "agents_behavior": "The Agents view manages persisted agent files. The initial agent is GLOBAL AGENT backed by AGENTS.md, and agent markdown supports {{git}}, {{repo}}, {{workspace}}, {{url}}, {{baseUrl}}, {{profile}}, and {{issue}} template variables. The default global agent tells downstream agents to close the Gitea issue after pushing the implementation and to leave a Gitea issue comment when delivery is blocked, partial, or risky; persisted built-in global agents should pick up these required completion rules without replacing unrelated custom text.", + "prompts_behavior": "The Prompts view manages workspace-scoped prompt records persisted in chrome.storage.local under silmaAide.prompts. Each prompt has a name, workspace path, and content. Add Issue shows prompts matching the active known URL's workspace path immediately above Content, and selecting one copies prompt content into the editable Content field for human adjustment.", "add_url_behavior": "The user must pick either a workspace or a Gitea repo. The app infers the linked counterpart from local context and stores the URL link in chrome.storage.local.", "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.", + "add_issue_behavior": "The form shows the target repo and active URL for the active known URL, lets the user select a workspace prompt, 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": "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. Status filtering uses Open and Closed checkboxes as a multiselect with Open checked by default. Label filtering defaults to empty and filters visible rows by a selected known label.", - "issue_comment_behavior": "Issues owns existing issue follow-up. Selecting an issue shows a direct Open in Gitea link, a placeholder Send to Codex button that logs the selected issue payload, editable issue subject/content/label fields that save against the selected issue repo with Gitea content-version readback verification and 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. Clicking the selected issue row again or the detail close control collapses the detail panel. 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, Issues comment, or Agents editor controls.", + "issue_comment_behavior": "Issues owns existing issue follow-up. Selecting an issue shows a direct Open in Gitea link, a placeholder Send to Codex button that logs the selected issue payload, editable issue subject/content/label fields that save against the selected issue repo with Gitea content-version readback verification and 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. Clicking the selected issue row again or the detail close control collapses the detail panel. 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, Issues comment, Agents editor controls, or Prompts editor controls.", + "gitea_error_behavior": "Gitea API failures should include the failed operation. Network-level failures identify the configured Gitea API base URL and point to checks for VITE_GITEA_BASE_URL, Chrome extension host permissions, network/VPN access, token scope, and attachment size.", "known_urls": [ { "url": "http://100.66.226.22:23030/", diff --git a/public/local-context.json b/public/local-context.json index b43c896..34e0e74 100644 --- a/public/local-context.json +++ b/public/local-context.json @@ -26,18 +26,6 @@ } ] }, - { - "name": "aarete-unified", - "path": "/Users/Tabitha/.openclaw/workspace_Father/aarete-unified", - "linkedRepos": [ - { - "worktreePath": "/Users/Tabitha/.openclaw/workspace_Father/aarete-unified", - "worktreeRelativePath": "aarete-unified", - "fullName": "jacob-mathison/aarete-doczyai-unified", - "webUrl": "http://gitea.orson.tealthrone/jacob-mathison/aarete-doczyai-unified" - } - ] - }, { "name": "banner-and-pyre", "path": "/Users/Tabitha/.openclaw/workspace_Father/banner-and-pyre", @@ -98,11 +86,6 @@ } ] }, - { - "name": "tuono", - "path": "/Users/Tabitha/.openclaw/workspace_Father/tuono", - "linkedRepos": [] - }, { "name": "workspace_Data", "path": "/Users/Tabitha/.openclaw/workspace_Father/workspace_Data", @@ -117,20 +100,6 @@ } ], "gitWorktrees": [ - { - "name": "aarete-unified", - "path": "/Users/Tabitha/.openclaw/workspace_Father/aarete-unified", - "relativePath": "aarete-unified", - "topWorkspaceName": "aarete-unified", - "branch": "main", - "giteaRepo": { - "fullName": "jacob-mathison/aarete-doczyai-unified", - "owner": "jacob-mathison", - "name": "aarete-doczyai-unified", - "webUrl": "http://gitea.orson.tealthrone/jacob-mathison/aarete-doczyai-unified", - "cloneUrl": "http://100.79.253.19:3000/jacob-mathison/aarete-doczyai-unified.git" - } - }, { "name": "automations", "path": "/Users/Tabitha/.openclaw/workspace_Father/aarete/automations", @@ -265,14 +234,6 @@ "cloneUrl": "http://100.79.253.19:3000/jacob-mathison/mp-silma-ai-aide.git" } }, - { - "name": "tuono", - "path": "/Users/Tabitha/.openclaw/workspace_Father/tuono", - "relativePath": "tuono", - "topWorkspaceName": "tuono", - "branch": "main", - "giteaRepo": null - }, { "name": "workspace_Data", "path": "/Users/Tabitha/.openclaw/workspace_Father/workspace_Data", diff --git a/src/api.ts b/src/api.ts index 33cd1c5..784e093 100644 --- a/src/api.ts +++ b/src/api.ts @@ -192,6 +192,7 @@ function getGiteaErrorMessage(error: unknown, fallback: string): string { const status = error.response?.status; const data = error.response?.data; + const apiBaseUrl = giteaConfig.baseUrl ? getApiBaseUrl(giteaConfig.baseUrl) : "the configured Gitea API"; const detail = typeof data === "string" ? data @@ -201,7 +202,12 @@ function getGiteaErrorMessage(error: unknown, fallback: string): string { ? data.error : error.message; - return status ? `${fallback} Gitea returned ${status}: ${detail}` : `${fallback} ${detail}`; + if (status) { + return `${fallback} Gitea returned ${status}: ${detail}`; + } + + const reason = error.code ? `${detail} (${error.code})` : detail; + return `${fallback} Could not reach ${apiBaseUrl}: ${reason}. Check VITE_GITEA_BASE_URL, Chrome extension host permissions, network/VPN access, token scope, and attachment size.`; } function getLabelName(label: unknown): string { @@ -218,8 +224,12 @@ function normalizeIssueText(value: string): string { export async function getCurrentGiteaUser(): Promise { const client = createGiteaClient(); - const response = await client.get("/user"); - return response.data; + try { + const response = await client.get("/user"); + return response.data; + } catch (error) { + throw new Error(getGiteaErrorMessage(error, "Could not load the current Gitea user.")); + } } export async function createGiteaIssue( @@ -230,21 +240,25 @@ export async function createGiteaIssue( labelIds: number[] = [] ): Promise { const client = createGiteaClient(); - const response = await client.post(`/repos/${owner}/${repo}/issues`, { - title, - body, - labels: labelIds - }); + try { + const response = await client.post(`/repos/${owner}/${repo}/issues`, { + title, + body, + labels: labelIds + }); - const number = response.data.number; - if (!number) { - throw new Error("Gitea did not return an issue number."); + const number = response.data.number; + if (!number) { + throw new Error("Gitea did not return an issue number."); + } + + return { + number, + webUrl: response.data.html_url || `${giteaConfig.baseUrl.replace(/\/+$/, "")}/${owner}/${repo}/issues/${number}` + }; + } catch (error) { + throw new Error(getGiteaErrorMessage(error, `Could not create a Gitea issue in ${owner}/${repo}.`)); } - - return { - number, - webUrl: response.data.html_url || `${giteaConfig.baseUrl.replace(/\/+$/, "")}/${owner}/${repo}/issues/${number}` - }; } export async function updateGiteaIssue( @@ -318,63 +332,71 @@ export async function getGiteaIssues( options: { limit?: number; sort?: "created" | "updated"; order?: "asc" | "desc"; state?: GiteaIssueStateFilter } = {} ): Promise { const client = createGiteaClient(); - const response = await client.get(`/repos/${owner}/${repo}/issues`, { - params: { - limit: options.limit ?? 25, - order: options.order ?? "desc", - page: 1, - sort: options.sort ?? "created", - state: options.state ?? "all", - type: "issues" - } - }); + try { + const response = await client.get(`/repos/${owner}/${repo}/issues`, { + params: { + limit: options.limit ?? 25, + order: options.order ?? "desc", + page: 1, + sort: options.sort ?? "created", + state: options.state ?? "all", + type: "issues" + } + }); - return response.data - .filter((issue) => issue.number !== undefined) - .map((issue) => toIssueSummary(issue, owner, repo, issue.number)); + return response.data + .filter((issue) => issue.number !== undefined) + .map((issue) => toIssueSummary(issue, owner, repo, issue.number)); + } catch (error) { + throw new Error(getGiteaErrorMessage(error, `Could not load Gitea issues for ${owner}/${repo}.`)); + } } export async function getGiteaIssueDetail(owner: string, repo: string, issueNumber: number): Promise { const client = createGiteaClient(); - const [issueResponse, commentsResponse, attachmentsResponse] = await Promise.all([ - client.get(`/repos/${owner}/${repo}/issues/${issueNumber}`), - client.get(`/repos/${owner}/${repo}/issues/${issueNumber}/comments`, { - params: { - limit: 100, - page: 1 - } - }), - client.get(`/repos/${owner}/${repo}/issues/${issueNumber}/assets`, { - params: { - limit: 100, - page: 1 - } - }) - ]); + try { + const [issueResponse, commentsResponse, attachmentsResponse] = await Promise.all([ + client.get(`/repos/${owner}/${repo}/issues/${issueNumber}`), + client.get(`/repos/${owner}/${repo}/issues/${issueNumber}/comments`, { + params: { + limit: 100, + page: 1 + } + }), + client.get(`/repos/${owner}/${repo}/issues/${issueNumber}/assets`, { + params: { + limit: 100, + page: 1 + } + }) + ]); - const issue = issueResponse.data; + const issue = issueResponse.data; - return { - issue: { - ...toIssueSummary(issue, owner, repo, issueNumber), - comments: issue.comments ?? commentsResponse.data.length - }, - comments: commentsResponse.data.map((comment) => ({ - id: comment.id ?? 0, - body: comment.body || "", - webUrl: comment.html_url || "", - createdAt: comment.created_at || "", - updatedAt: comment.updated_at || "", - author: comment.user?.login || "unknown" - })), - attachments: attachmentsResponse.data.map((attachment) => ({ - id: attachment.id ?? 0, - name: attachment.name || "attachment", - downloadUrl: attachment.browser_download_url || attachment.download_url || "", - size: attachment.size ?? 0, - createdAt: attachment.created_at || "" - })) - }; + return { + issue: { + ...toIssueSummary(issue, owner, repo, issueNumber), + comments: issue.comments ?? commentsResponse.data.length + }, + comments: commentsResponse.data.map((comment) => ({ + id: comment.id ?? 0, + body: comment.body || "", + webUrl: comment.html_url || "", + createdAt: comment.created_at || "", + updatedAt: comment.updated_at || "", + author: comment.user?.login || "unknown" + })), + attachments: attachmentsResponse.data.map((attachment) => ({ + id: attachment.id ?? 0, + name: attachment.name || "attachment", + downloadUrl: attachment.browser_download_url || attachment.download_url || "", + size: attachment.size ?? 0, + createdAt: attachment.created_at || "" + })) + }; + } catch (error) { + throw new Error(getGiteaErrorMessage(error, `Could not load Gitea issue #${issueNumber} in ${owner}/${repo}.`)); + } } export async function uploadGiteaIssueAttachment( @@ -388,18 +410,24 @@ export async function uploadGiteaIssueAttachment( const formData = new FormData(); formData.append("attachment", file, fileName); - const response = await client.post( - `/repos/${owner}/${repo}/issues/${issueNumber}/assets`, - formData - ); + try { + const response = await client.post( + `/repos/${owner}/${repo}/issues/${issueNumber}/assets`, + formData + ); - return { - id: response.data.id ?? 0, - name: response.data.name || fileName, - downloadUrl: response.data.browser_download_url || response.data.download_url || "", - size: response.data.size ?? file.size, - createdAt: response.data.created_at || "" - }; + return { + id: response.data.id ?? 0, + name: response.data.name || fileName, + downloadUrl: response.data.browser_download_url || response.data.download_url || "", + size: response.data.size ?? file.size, + createdAt: response.data.created_at || "" + }; + } catch (error) { + throw new Error( + getGiteaErrorMessage(error, `Could not upload ${fileName} to Gitea issue #${issueNumber} in ${owner}/${repo}.`) + ); + } } export async function deleteGiteaIssueAttachment( @@ -409,7 +437,13 @@ export async function deleteGiteaIssueAttachment( attachmentId: number ): Promise { const client = createGiteaClient(); - await client.delete(`/repos/${owner}/${repo}/issues/${issueNumber}/assets/${attachmentId}`); + try { + await client.delete(`/repos/${owner}/${repo}/issues/${issueNumber}/assets/${attachmentId}`); + } catch (error) { + throw new Error( + getGiteaErrorMessage(error, `Could not delete attachment ${attachmentId} from Gitea issue #${issueNumber}.`) + ); + } } export async function createGiteaIssueComment( @@ -419,24 +453,36 @@ export async function createGiteaIssueComment( body: string ): Promise { const client = createGiteaClient(); - await client.post(`/repos/${owner}/${repo}/issues/${issueNumber}/comments`, { - body - }); + try { + await client.post(`/repos/${owner}/${repo}/issues/${issueNumber}/comments`, { + body + }); + } catch (error) { + throw new Error(getGiteaErrorMessage(error, `Could not create a comment on Gitea issue #${issueNumber}.`)); + } } export async function deleteGiteaIssue(owner: string, repo: string, issueNumber: number): Promise { const client = createGiteaClient(); - await client.delete(`/repos/${owner}/${repo}/issues/${issueNumber}`); + try { + await client.delete(`/repos/${owner}/${repo}/issues/${issueNumber}`); + } catch (error) { + throw new Error(getGiteaErrorMessage(error, `Could not delete Gitea issue #${issueNumber} in ${owner}/${repo}.`)); + } } async function getGiteaLabels(owner: string, repo: string): Promise { const client = createGiteaClient(); - const response = await client.get(`/repos/${owner}/${repo}/labels`, { - params: { - limit: 100 - } - }); - return response.data; + try { + const response = await client.get(`/repos/${owner}/${repo}/labels`, { + params: { + limit: 100 + } + }); + return response.data; + } catch (error) { + throw new Error(getGiteaErrorMessage(error, `Could not load Gitea labels for ${owner}/${repo}.`)); + } } export async function ensureGiteaLabel(owner: string, repo: string, name: string, color = "0e8a16"): Promise { @@ -453,17 +499,19 @@ export async function ensureGiteaLabel(owner: string, repo: string, name: string color }); return response.data; - } catch { + } catch (error) { const refreshedLabels = await getGiteaLabels(owner, repo); const refreshed = refreshedLabels.find((label) => label.name.toLowerCase() === name.toLowerCase()); if (refreshed) { return refreshed; } - throw new Error(`Could not create or find the ${name} label.`); + throw new Error(getGiteaErrorMessage(error, `Could not create or find the ${name} label in ${owner}/${repo}.`)); } } export async function getReposOrderedByLastCommit(): Promise { + assertGiteaConfigured(); + const client = axios.create({ baseURL: getApiBaseUrl(giteaConfig.baseUrl), headers: { @@ -471,62 +519,64 @@ export async function getReposOrderedByLastCommit(): Promise } }); - assertGiteaConfigured(); - const repos: GiteaRepoResponse[] = []; let page = 1; - while (page <= 10) { - const response = await client.get("/user/repos", { - params: { - limit: 50, - page + try { + while (page <= 10) { + const response = await client.get("/user/repos", { + params: { + limit: 50, + page + } + }); + + repos.push(...response.data); + + if (response.data.length < 50) { + break; } - }); - repos.push(...response.data); - - if (response.data.length < 50) { - break; + page += 1; } - page += 1; + const repoDetails = await Promise.all( + repos.map(async (repo): Promise => { + const owner = repo.owner?.login || giteaConfig.repoOwner; + const defaultBranch = repo.default_branch || "main"; + const fullName = repo.full_name || `${owner}/${repo.name}`; + + let branch: GiteaBranchResponse | null = null; + try { + const branchResponse = await client.get( + `/repos/${owner}/${repo.name}/branches/${defaultBranch}` + ); + branch = branchResponse.data; + } catch { + branch = null; + } + + return { + name: repo.name, + fullName, + description: repo.description || "", + webUrl: repo.html_url || `${giteaConfig.baseUrl.replace(/\/+$/, "")}/${fullName}`, + cloneUrl: repo.clone_url || "", + defaultBranch, + isPrivate: Boolean(repo.private), + lastCommitAt: branch?.commit?.timestamp || repo.updated_at || "", + lastCommitSha: branch?.commit?.id || "", + lastCommitMessage: branch?.commit?.message?.split("\n")[0] || "No commit message available" + }; + }) + ); + + return repoDetails.sort((a, b) => { + const aTime = a.lastCommitAt ? Date.parse(a.lastCommitAt) : 0; + const bTime = b.lastCommitAt ? Date.parse(b.lastCommitAt) : 0; + return bTime - aTime || a.fullName.localeCompare(b.fullName); + }); + } catch (error) { + throw new Error(getGiteaErrorMessage(error, "Could not load Gitea repositories.")); } - - const repoDetails = await Promise.all( - repos.map(async (repo): Promise => { - const owner = repo.owner?.login || giteaConfig.repoOwner; - const defaultBranch = repo.default_branch || "main"; - const fullName = repo.full_name || `${owner}/${repo.name}`; - - let branch: GiteaBranchResponse | null = null; - try { - const branchResponse = await client.get( - `/repos/${owner}/${repo.name}/branches/${defaultBranch}` - ); - branch = branchResponse.data; - } catch { - branch = null; - } - - return { - name: repo.name, - fullName, - description: repo.description || "", - webUrl: repo.html_url || `${giteaConfig.baseUrl.replace(/\/+$/, "")}/${fullName}`, - cloneUrl: repo.clone_url || "", - defaultBranch, - isPrivate: Boolean(repo.private), - lastCommitAt: branch?.commit?.timestamp || repo.updated_at || "", - lastCommitSha: branch?.commit?.id || "", - lastCommitMessage: branch?.commit?.message?.split("\n")[0] || "No commit message available" - }; - }) - ); - - return repoDetails.sort((a, b) => { - const aTime = a.lastCommitAt ? Date.parse(a.lastCommitAt) : 0; - const bTime = b.lastCommitAt ? Date.parse(b.lastCommitAt) : 0; - return bTime - aTime || a.fullName.localeCompare(b.fullName); - }); } diff --git a/src/main.ts b/src/main.ts index b3612ef..3d3dbc8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,17 @@ -import { createIcons, Bot, CirclePlus, FolderGit2, GitBranch, Link, List, ListChecks, RefreshCw, Send, X } from "lucide"; +import { + createIcons, + Bot, + CirclePlus, + FileText, + FolderGit2, + GitBranch, + Link, + List, + ListChecks, + RefreshCw, + Send, + X +} from "lucide"; import "./styles.css"; import { appStore, @@ -11,7 +24,8 @@ import { type IssueLabelOption, type OpenIssue, type OpenIssuesStatusFilter, - type ScreenshotAttachment + type ScreenshotAttachment, + type WorkspacePrompt } from "./store"; import type { GiteaIssueAttachment, GiteaIssueComment, GiteaIssueSummary, GiteaRepoSummary } from "./api"; import type { KnownUrl, LocalContext, LocalWorkspace } from "./localContext"; @@ -29,6 +43,7 @@ const viewButtons = Array.from(document.querySelectorAll("[da const lucideIcons = { Bot, CirclePlus, + FileText, FolderGit2, GitBranch, Link, @@ -250,6 +265,76 @@ function renderAgents(agents: AgentProfile[]): string { `; } +function workspacePathOptions(context: LocalContext | null, selectedPath: string): string { + const workspaces = context?.workspaces ?? []; + + if (!workspaces.length) { + return selectedPath + ? `` + : ""; + } + + return workspaces + .map( + (workspace) => + `` + ) + .join(""); +} + +function renderPrompts(prompts: WorkspacePrompt[]): string { + const state = appStore.getState(); + const draft = state.promptDraft; + + return ` +
+ ${ + prompts.length + ? prompts + .map( + (prompt) => ` +
+
+

${escapeHtml(prompt.name)}

+ ${escapeHtml(prompt.workspacePath)} +
+
+ + +
+
+ ` + ) + .join("") + : `
No workspace prompts saved yet.
` + } +
+
+
+ + + +
+ + +
+
+
+ `; +} + function renderUrls(urls: KnownUrl[]): string { if (!urls.length) { return `
No known URLs registered.
`; @@ -404,6 +489,18 @@ function renderAgentOptions(agents: AgentProfile[], selectedAgentId: string): st .join(""); } +function renderIssuePromptOptions(prompts: WorkspacePrompt[], selectedPromptId: string): string { + return ` + + ${prompts + .map( + (prompt) => + `` + ) + .join("")} + `; +} + function renderLabelOptions(selectedLabels: IssueLabelOption[], target: "draft" | "edit"): string { return `
@@ -820,6 +917,8 @@ function renderAddIssue(): string { return `
${escapeHtml(knownUrl.label)} is linked to a workspace but not a Gitea repo.
`; } + const workspacePrompts = state.prompts.filter((prompt) => prompt.workspacePath === knownUrl.workspacePath); + return `
@@ -839,6 +938,13 @@ function renderAddIssue(): string { + +