opencode-gh-search 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tom Uijtdehaag
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,110 @@
1
- # Temporary Holding Version
1
+ # opencode-gh-search
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An [OpenCode](https://opencode.ai) plugin for Desktop and the TUI that adds live search for GitHub pull requests (`/pr`) and issues (`/issue`). Pick one and it is attached to your prompt as context.
4
+
5
+ In the TUI, the picked item's URL is typed into the prompt: TUI plugins can't add attachment chips yet. If the prompt can't be reached, it is copied to the clipboard instead.
6
+
7
+ - **Partial matching** on titles and numbers (`depen`, `#74`). GitHub's own search only matches whole words.
8
+ - **GitHub-style filters:** `author:`, `is:`, `label:`, `assignee:`, and for PRs `base:`, `head:`, `review:` and `review-requested:`. `@me` means you (`review-requested:@me`). Partial values count (`author:tom`, `is:merg`), and `-` excludes, e.g. `/pr @api is:open -author:dependabot login`. The search box shows them by example.
9
+ - **Multiple repos.** Run it from a folder that holds repos (up to three levels deep) and it searches all of them, or narrow with `@` and a short repo name: `/pr @api login` searches `acme-api` only.
10
+ - **Sorted** open → draft → merged → closed, newest first, with GitHub's state labels.
11
+ - **Stacks.** Open PRs based on another open PR's branch show their position, e.g. `2/3`.
12
+ - **Fast.** Each repo's PRs and issues are kept in a local index (`~/.cache/opencode-gh-search/`) that updates incrementally in the background, so searching takes milliseconds.
13
+
14
+ ## Requirements
15
+
16
+ - OpenCode Desktop or CLI 2.2 or later (the GUI plugin API is experimental and may change)
17
+ - [`gh`](https://cli.github.com) logged in (`gh auth login`); the plugin uses its token
18
+ ## Install
19
+
20
+ ```sh
21
+ opencode plugin add opencode-gh-search
22
+ ```
23
+
24
+ This adds it to your global config, which Desktop needs to load plugin UIs. To stay on a stable version instead of following updates, pin it (exact versions are never auto-updated):
25
+
26
+ ```sh
27
+ opencode plugin add opencode-gh-search@0.1.0
28
+ ```
29
+
30
+ Check for and apply updates with `opencode plugin check` and `opencode plugin update opencode-gh-search`.
31
+
32
+ ### From source
33
+
34
+ Needs Node.js and npm.
35
+
36
+ ```sh
37
+ git clone https://github.com/TomUijtdehaag/opencode-gh-search.git
38
+ cd opencode-gh-search
39
+ npm install
40
+ npm run build
41
+ ```
42
+
43
+ Add the folder to your global `~/.config/opencode/opencode.json`:
44
+
45
+ ```jsonc
46
+ {
47
+ "plugins": ["/absolute/path/to/opencode-gh-search"]
48
+ }
49
+ ```
50
+
51
+ ## Release
52
+
53
+ Versions follow [semver](https://semver.org) and are immutable once published. To release:
54
+
55
+ ```sh
56
+ npm version patch # or minor / major: bumps package.json, commits, and tags v<version>
57
+ git push --follow-tags
58
+ ```
59
+
60
+ The tag triggers `.github/workflows/publish.yml`, which typechecks, builds, publishes to npm with provenance through [trusted publishing](https://docs.npmjs.com/trusted-publishers) (no npm token), and creates the GitHub release.
61
+
62
+ ## Settings
63
+
64
+ Pass options through the plugin entry:
65
+
66
+ ```jsonc
67
+ {
68
+ "plugins": [
69
+ {
70
+ "package": "/absolute/path/to/opencode-gh-search",
71
+ "options": {
72
+ // Leave bot reviews (e.g. Copilot) out of the review status. Default true.
73
+ "ignoreBotReviews": true,
74
+ // More reviewer logins to leave out. Default none.
75
+ "ignoreReviewers": ["some-ci-account"]
76
+ }
77
+ }
78
+ ]
79
+ }
80
+ ```
81
+
82
+ ## Usage
83
+
84
+ `/issue` works the same as `/pr`.
85
+
86
+ | Where | Command | Searches |
87
+ | --- | --- | --- |
88
+ | inside a repo | `/pr login` | that repo |
89
+ | folder with repos | `/pr login` | every repo in the folder |
90
+ | folder with repos | `/pr @api login` | repos matching `api` (exact, then `*-api`, then containing) |
91
+ | anywhere | `/pr #42` | numbers containing 42 |
92
+ | anywhere | `/issue is:open label:bug` | open issues labelled `bug` |
93
+
94
+ Arrow keys to select, Enter to attach, scroll for more. The attachment gives the model the URL; it can fetch details with `gh`.
95
+
96
+ ## Development
97
+
98
+ | File | Runs in | Does |
99
+ | --- | --- | --- |
100
+ | `src/rpc.ts` | everywhere | the contract: types, kinds, filters, matching, row text |
101
+ | `src/index.ts` | OpenCode server | repo discovery, GitHub sync, local index, search |
102
+ | `src/search.ts` | both UIs | the dialog's search state: debounce, paging, re-polling while indexing |
103
+ | `src/gui.tsx` | Desktop window | dialog and chip |
104
+ | `src/tui.tsx` | terminal UI | dialog and prompt insert |
105
+
106
+ [SPEC.md](SPEC.md) describes the behaviour both UIs must share. Run `npm run dev` to rebuild the GUI on change; Desktop reloads it automatically. The server reloads `src/index.ts` on change but not the files it imports: after changing `src/rpc.ts`, run `opencode service restart`.
107
+
108
+ ## License
109
+
110
+ MIT. Includes GitHub [Octicons](https://github.com/primer/octicons) (MIT).
@@ -0,0 +1,67 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("solid-js/web"),M=require("solid-js"),U=require("@opencode/plugin/gui"),ie=require("@opencode/plugin/rpc"),Y={pr:{command:"pr",title:"Pull requests",noun:"pull request",plural:"pull requests",states:{open:"Open",draft:"Draft",merged:"Merged",closed:"Closed"}},issue:{command:"issue",title:"Issues",noun:"issue",plural:"issues",states:{open:"Open",closed:"Closed"}}},P=(e,t)=>!!e&&e.toLowerCase().includes(t),j=(e,t)=>!!e&&e.toLowerCase()===t.toLowerCase(),ae=(e,t,o)=>t==="@me"?j(e,o.login):P(e,t);function re(e,t){if(!t.login||!e.reviewers)return"";if(e.reviewers.some(h=>j(h,t.login)))return"you";const o=e.repo.split("/")[0];return e.reviewers.some(h=>t.teams.some(r=>j(r,`${o}/${h}`)))?"team":""}const se={author:{kinds:["pr","issue"],example:"author:tom",test:(e,t,o)=>ae(e.author,t,o)},is:{kinds:["pr","issue"],example:"is:open",test:(e,t)=>"open".startsWith(t)&&e.state==="draft"||e.state.startsWith(t)},label:{kinds:["pr","issue"],example:"label:bug",test:(e,t)=>e.labels.some(o=>P(o,t))},assignee:{kinds:["pr","issue"],example:"assignee:tom",test:(e,t,o)=>e.assignees.some(h=>ae(h,t,o))},base:{kinds:["pr"],example:"base:main",test:(e,t)=>P(e.base,t)},head:{kinds:["pr"],example:"head:feat",test:(e,t)=>P(e.branch,t)},review:{kinds:["pr"],example:"review:approved",test:(e,t)=>!!e.review&&(e.review.startsWith(t)||e.review.startsWith(`review_${t}`))},"review-requested":{kinds:["pr"],example:"review-requested:tom",test:(e,t,o)=>t==="@me"?!!re(e,o):!!e.reviewers?.some(h=>P(h,t))}},oe={state:"is"};function le(e){return["@repo","text","#12",...Object.values(se).filter(o=>o.kinds.includes(e)).map(o=>o.example),"-exclude"].join(" ")}function ce(e,t){return e.toLowerCase().split(/\s+/).filter(Boolean).map(o=>{const h=o.length>1&&o.startsWith("-"),r=h?o.slice(1):o,[d,...l]=r.split(":"),i=oe[d]??d,p=l.join(":");return p&&se[i]?.kinds.includes(t)?{key:i,value:p,negate:h}:{key:"text",value:r,negate:h}})}function de(e,t,o){const h=ce(t.trim().replace(/^@\S*\s*/,""),o).filter(i=>i.key==="text"&&!i.negate&&!i.value.startsWith("#")).map(i=>i.value),r=e.toLowerCase(),d=new Array(e.length).fill(!1);for(const i of h)for(let p=r.indexOf(i);p!==-1;p=r.indexOf(i,p+i.length))d.fill(!0,p,p+i.length);const l=[];for(let i=0;i<e.length;i++){const p=l[l.length-1];p&&p.hit===d[i]?p.text+=e[i]:l.push({text:e[i],hit:d[i]})}return l}const he=new Intl.RelativeTimeFormat(void 0,{numeric:"auto"}),ge=[["year",365*24*3600],["month",720*3600],["week",168*3600],["day",24*3600],["hour",3600],["minute",60]];function J(e){const t=(Date.parse(e)-Date.now())/1e3;for(const[o,h]of ge)if(Math.abs(t)>=h)return he.format(Math.round(t/h),o);return"just now"}function ue(e){return e.mergedAt?`merged ${J(e.mergedAt)}`:e.closedAt?`closed ${J(e.closedAt)}`:e.createdAt?`opened ${J(e.createdAt)}`:""}function ne(e,t){return j(e.author,t.login)}function pe(e,t){if(e.state!=="open"&&e.state!=="draft")return;const o=Object.entries(e.reviews??{}),h=o.find(([d])=>j(d,t.login))?.[1],r=ne(e,t);if(re(e,t)==="you")return{label:"Review requested",tone:"attention"};if(e.review==="changes_requested")return{label:"Changes requested",tone:"danger"};if(e.mergeable)return{label:"Ready to merge",tone:"success"};if(h==="approved")return{label:"You approved",tone:"success"};if(e.review==="approved")return{label:"Approved",tone:"success"};if(r&&o.some(([d,l])=>!j(d,t.login)&&l==="commented"))return{label:"Reviewed",tone:"attention"};if(!r&&h==="commented")return{label:"You reviewed",tone:""}}function Q(e,t){const o=d=>d.filter(Boolean).join(" · "),h=o([`#${e.number}`,t?e.repo.split("/").pop()??"":""]),r=ue(e);return e.author?{before:`${h} · `,author:e.author,after:r?` ${r}`:""}:{before:o([h,r]),author:"",after:""}}function fe(e,t){return t.error?t.error:t.searching?"Searching…":t.indexing?`No ${e} yet, still indexing…`:`No ${e}`}function me(e,t){return e.length===1?e[0]:e.length>1?`${e.length} repositories`:t?"No repositories":"Searching…"}const H={type:"string"},ve=ie.Rpc.define({id:"gh-search",methods:{resolve:{input:{type:"object",properties:{directory:H,input:H},required:["directory","input"],additionalProperties:!1},output:{type:"object"}},search:{input:{type:"object",properties:{kind:{type:"string",enum:["pr","issue"]},dirs:{type:"array",items:H},query:H,size:{type:"integer",minimum:1,maximum:100},cursor:{type:"object"}},required:["kind","dirs","query","size"],additionalProperties:!1},output:{type:"object"},errors:{gh_failed:{type:"object",properties:{message:H},required:["message"],additionalProperties:!1}}}},events:{}}),we=150,xe=1500;function be(e){const{createSignal:t,onCleanup:o}=e.solid,h=e.client.rpc(ve),[r,d]=t(e.initial),[l,i]=t([]),[p,T]=t([]),[s,_]=t(0),[q,N]=t(!1),[L,f]=t(!1),[$,S]=t(!1),[R,m]=t(""),[z,V]=t({login:"",teams:[]});let A,y,w=0,I,O;o(()=>{clearTimeout(I),clearTimeout(O)});const n=(u,g)=>h.search({kind:e.kind,...A,size:u,...g?{cursor:g}:{}});async function C(u){const g=++w;N(!0),f(!1),m("");try{const v=await h.resolve({directory:e.directory,input:u});if(g!==w)return;if(y=void 0,A={dirs:v.repos.map(B=>B.dir),query:v.query},v.repos.length===0){T([]),i([]),S(!1),m(`No repository matches ${u.trim().split(/\s+/)[0]}`);return}const k=await n(e.batch);if(g!==w)return;y=k.next,T(k.repos),i(k.items),S(k.indexing),V(k.viewer),m(k.error??""),_(0),E(g),e.onReset?.()}catch(v){if(g!==w)return;i([]),m(v instanceof Error?v.message:String(v))}finally{g===w&&N(!1)}}async function b(){if(!A||!y||L())return;const u=w;f(!0);try{const g=await n(e.batch,y);if(u!==w)return;y=g.next,i(v=>[...v,...g.items]),S(g.indexing),m(g.error??"")}catch(g){u===w&&m(g instanceof Error?g.message:String(g))}finally{u===w&&f(!1)}u===w&&e.onMore?.()}function E(u){clearTimeout(O),$()&&(O=setTimeout(async()=>{if(!(u!==w||!A)){try{const g=await n(Math.max(l().length,e.batch));if(u!==w)return;y=g.next,i(g.items),S(g.indexing),m(g.error??""),_(v=>Math.min(v,Math.max(g.items.length-1,0)))}catch{}E(u)}},xe))}function Z(u){d(u),clearTimeout(I),I=setTimeout(()=>{C(u)},we)}function K(u,g){const v=l().length;if(!v)return;const k=Math.max(0,Math.min(s()+u,v-1));_(k),k>=v-g&&b()}return C(e.initial),{text:r,input:Z,rows:l,repos:p,selected:s,setSelected:_,move:K,more:b,searching:q,loadingMore:L,indexing:$,error:R,viewer:z,hasMore:()=>!!y,many:()=>p().length>1,current:()=>l()[s()]}}var ye=a.template("<div data-slot=list-empty-state><div data-slot=list-message>"),ke=a.template("<span>Loading more…"),$e=a.template("<span>Indexing <!>…"),Ce=a.template("<span>"),Me=a.template("<div data-component=list data-gh-search><div data-slot=list-search-wrapper><div data-slot=list-search><div data-slot=list-search-container><input data-slot=list-search-input type=text autocomplete=off></div></div></div><div data-slot=list-scroll><div data-slot=list-group><div data-slot=list-items></div><div class=gh-search-more>"),Se=a.template('<div data-slot=list-item><span class=gh-search-state-cell><span class=gh-search-state></span></span><span class=gh-search-main><span class=gh-search-line><span class=gh-search-title></span></span><span class="gh-search-line gh-search-line-meta"><span class=gh-search-meta><span>'),_e=a.template("<mark class=gh-search-hit>"),Ae=a.template("<span class=gh-search-status>"),Ze=a.template('<span class="gh-search-weak gh-search-stack gh-search-meta">· <span style=display:contents></span>/');const F=48,qe={open:'<svg version="1.1" width="12" height="12" viewBox="0 0 16 16" class="octicon octicon-git-pull-request" aria-hidden="true" data-component="Octicon"><path d="M1.5 3.25a2.25 2.25 0 1 1 3 2.122v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.25 2.25 0 0 1 1.5 3.25Zm5.677-.177L9.573.677A.25.25 0 0 1 10 .854V2.5h1A2.5 2.5 0 0 1 13.5 5v5.628a2.251 2.251 0 1 1-1.5 0V5a1 1 0 0 0-1-1h-1v1.646a.25.25 0 0 1-.427.177L7.177 3.427a.25.25 0 0 1 0-.354ZM3.75 2.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm0 9.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm8.25.75a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Z"></path></svg>',draft:'<svg version="1.1" width="12" height="12" viewBox="0 0 16 16" class="octicon octicon-git-pull-request-draft" aria-hidden="true" data-component="Octicon"><path d="M3.25 1A2.25 2.25 0 0 1 4 5.372v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.251 2.251 0 0 1 3.25 1Zm9.5 14a2.25 2.25 0 1 1 0-4.5 2.25 2.25 0 0 1 0 4.5ZM2.5 3.25a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0ZM3.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm9.5 0a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5ZM14 7.5a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0Zm0-4.25a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0Z"></path></svg>',merged:'<svg version="1.1" width="12" height="12" viewBox="0 0 16 16" class="octicon octicon-git-merge" aria-hidden="true" data-component="Octicon"><path d="M5.45 5.154A4.25 4.25 0 0 0 9.25 7.5h1.378a2.251 2.251 0 1 1 0 1.5H9.25A5.734 5.734 0 0 1 5 7.123v3.505a2.25 2.25 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.95-.218ZM4.25 13.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm8.5-4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5ZM5 3.25a.75.75 0 1 0 0 .005V3.25Z"></path></svg>',closed:'<svg version="1.1" width="12" height="12" viewBox="0 0 16 16" class="octicon octicon-git-pull-request-closed" aria-hidden="true" data-component="Octicon"><path d="M3.25 1A2.25 2.25 0 0 1 4 5.372v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.251 2.251 0 0 1 3.25 1Zm9.5 5.5a.75.75 0 0 1 .75.75v3.378a2.251 2.251 0 1 1-1.5 0V7.25a.75.75 0 0 1 .75-.75Zm-2.03-5.273a.75.75 0 0 1 1.06 0l.97.97.97-.97a.748.748 0 0 1 1.265.332.75.75 0 0 1-.205.729l-.97.97.97.97a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-.97-.97-.97.97a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l.97-.97-.97-.97a.75.75 0 0 1 0-1.06ZM2.5 3.25a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0ZM3.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm9.5 0a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z"></path></svg>'},Le={open:'<svg version="1.1" width="12" height="12" viewBox="0 0 16 16" class="octicon octicon-issue-opened" aria-hidden="true"><path d="M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Z"></path></svg>',closed:'<svg version="1.1" width="12" height="12" viewBox="0 0 16 16" class="octicon octicon-issue-closed" aria-hidden="true"><path d="M11.28 6.78a.75.75 0 0 0-1.06-1.06L7.25 8.69 5.78 7.22a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.06 0l3.5-3.5Z M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0Zm-1.5 0a6.5 6.5 0 1 0-13 0 6.5 6.5 0 0 0 13 0Z"></path></svg>'},ze={pr:qe,issue:Le},Ie=20,Oe=`
2
+ [data-gh-search] [data-slot=list-search-input] {
3
+ flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 0;
4
+ color: var(--text-strong); font-family: var(--font-family-sans); font-size: var(--font-size-base, 14px);
5
+ line-height: 20px;
6
+ }
7
+ [data-gh-search] [data-slot=list-search-input]::placeholder { color: var(--text-weak); }
8
+ [data-gh-search] [data-slot=list-item] { display: flex; gap: 8px; cursor: default; position: relative; }
9
+ [data-gh-search] .gh-search-title,
10
+ [data-gh-search] .gh-search-weak { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
11
+ [data-gh-search] .gh-search-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
12
+ [data-gh-search] .gh-search-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
13
+ /* The stack's leading "· " already spaces it from the date; a full gap would read as a double space. */
14
+ [data-gh-search] .gh-search-line-meta { gap: 4px; }
15
+ [data-gh-search] .gh-search-title { flex: 1; }
16
+ [data-gh-search] .gh-search-meta {
17
+ color: var(--text-weak); font-size: var(--font-size-small, 12px); font-weight: var(--font-weight-regular);
18
+ line-height: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
19
+ }
20
+ [data-gh-search] .gh-search-weak { color: var(--text-weak); font-weight: var(--font-weight-regular); flex-shrink: 0; }
21
+ /* The state as GitHub's lists show it: just the octicon, in the state's colour. */
22
+ [data-gh-search] .gh-search-state-cell { flex-shrink: 0; width: 16px; display: flex; padding-top: 2px; }
23
+ [data-gh-search] .gh-search-stack { display: inline-flex; align-items: center; gap: 3px; }
24
+ [data-gh-search] .gh-search-stack svg { width: 12px; height: 12px; fill: currentColor; flex-shrink: 0; }
25
+ [data-gh-search] .gh-search-state { display: inline-flex; }
26
+ /* Review status: GitHub's Primer Label (outlined, no fill), with its light and dark colours. */
27
+ [data-gh-search] .gh-search-status {
28
+ flex-shrink: 0; display: inline-flex; align-items: center; height: 18px; padding: 0 7px; box-sizing: border-box;
29
+ border: 1px solid var(--gh-border); border-radius: 2em; color: var(--gh-fg);
30
+ font-size: 12px; font-weight: 500; line-height: 1; white-space: nowrap;
31
+ --gh-fg: #59636e; --gh-border: #d1d9e0;
32
+ }
33
+ [data-gh-search] .gh-search-status[data-tone=attention] { --gh-fg: #9a6700; --gh-border: #9a6700; }
34
+ [data-gh-search] .gh-search-status[data-tone=danger] { --gh-fg: #d1242f; --gh-border: #cf222e; }
35
+ [data-gh-search] .gh-search-status[data-tone=success] { --gh-fg: #1a7f37; --gh-border: #1a7f37; }
36
+ [data-gh-search][data-mode=dark] .gh-search-status { --gh-fg: #9198a1; --gh-border: #3d444d; }
37
+ [data-gh-search][data-mode=dark] .gh-search-status[data-tone=attention] { --gh-fg: #d29922; --gh-border: #9e6a03; }
38
+ [data-gh-search][data-mode=dark] .gh-search-status[data-tone=danger] { --gh-fg: #f85149; --gh-border: #da3633; }
39
+ [data-gh-search][data-mode=dark] .gh-search-status[data-tone=success] { --gh-fg: #3fb950; --gh-border: #238636; }
40
+ [data-gh-search] .gh-search-me { color: var(--text-strong); font-weight: var(--font-weight-medium, 500); }
41
+ /* Search hits: GitHub's search highlight (attention-muted background), since titles are already bold. */
42
+ [data-gh-search] .gh-search-hit { background: #fff8c5; color: inherit; border-radius: 2px; }
43
+ [data-gh-search][data-mode=dark] .gh-search-hit { background: rgba(187, 128, 9, 0.15); }
44
+ [data-gh-search] .gh-search-state svg { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; }
45
+ [data-gh-search] .gh-search-state[data-state=open] { color: #1a7f37; }
46
+ [data-gh-search] .gh-search-state[data-state=draft] { color: #59636e; }
47
+ [data-gh-search] .gh-search-state[data-state=merged] { color: #8250df; }
48
+ [data-gh-search] .gh-search-state[data-state=closed] { color: #d1242f; }
49
+ [data-gh-search] .gh-search-state[data-kind=issue][data-state=closed] { color: #8250df; }
50
+ [data-gh-search][data-mode=dark] .gh-search-state[data-state=open] { color: #3fb950; }
51
+ [data-gh-search][data-mode=dark] .gh-search-state[data-state=draft] { color: #9198a1; }
52
+ [data-gh-search][data-mode=dark] .gh-search-state[data-state=merged] { color: #ab7df8; }
53
+ [data-gh-search][data-mode=dark] .gh-search-state[data-state=closed] { color: #f85149; }
54
+ [data-gh-search][data-mode=dark] .gh-search-state[data-kind=issue][data-state=closed] { color: #ab7df8; }
55
+ /* Pinned to the dialog body (position: relative) so only the results scroll and the search stays on top. */
56
+ [data-gh-search][data-component=list] {
57
+ position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px; overflow: hidden;
58
+ padding: 4px 16px 12px; box-sizing: border-box;
59
+ }
60
+ [data-gh-search] [data-slot=list-search-wrapper] { flex-shrink: 0; }
61
+ [data-gh-search] [data-slot=list-scroll] { flex: 1 1 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
62
+ [data-gh-search] [data-slot=list-item] { height: ${F}px; box-sizing: border-box; }
63
+ [data-gh-search] .gh-search-more {
64
+ display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 1px; padding: 4px 0 12px;
65
+ color: var(--text-weak); font-size: var(--font-size-small, 12px);
66
+ }
67
+ `,je=U.Plugin.define({setup(e){const t=e.ui;e.add(U.Style,Oe),e.add(U.LinkHandler,{match:r=>r.origin===e.id,open:r=>e.system.openExternal(r.href)});function o(r){const d=r.repo,l=e.screen.current()?.composer;l&&(l.attach({type:"note",origin:e.id,commentID:crypto.randomUUID(),label:`${d.split("/").pop()}#${r.number}`,subtitle:r.title,icon:"github",subject:r.url,comment:"",href:r.url}),l.focus())}function h(r){const d=Y[r.kind];let l,i,p;const T=()=>queueMicrotask(()=>{!l||!i||i.getBoundingClientRect().top<=l.getBoundingClientRect().bottom+F*4&&s.more()}),s=be({solid:{createSignal:M.createSignal,onCleanup:M.onCleanup},client:e.client,kind:r.kind,directory:r.directory,initial:r.initial,batch:Ie,onReset:()=>{l?.scrollTo({top:0}),T()},onMore:T});M.onCleanup(()=>p?.disconnect());function _(f){f&&(r.dialog.close(),o(f))}function q(f){s.setSelected(f),l?.querySelectorAll("[data-slot=list-item]")[f]?.scrollIntoView({block:"nearest"})}function N(f){const $=s.rows().length,S=Math.max(1,Math.floor((l?.clientHeight??0)/F)-1),m={ArrowDown:()=>$&&q(Math.min(s.selected()+1,$-1)),ArrowUp:()=>$&&q(Math.max(s.selected()-1,0)),PageDown:()=>$&&q(Math.min(s.selected()+S,$-1)),PageUp:()=>$&&q(Math.max(s.selected()-S,0)),Enter:()=>_(s.current())}[f.key];m&&(f.preventDefault(),m())}let L;return requestAnimationFrame(()=>{L?.focus(),l&&i&&(p=new IntersectionObserver(f=>f[0]?.isIntersecting&&void s.more(),{root:l,rootMargin:`${F*4}px`}),p.observe(i))}),a.createComponent(t.Dialog,{get title(){return d.title},get description(){return me(s.repos(),s.error())},size:"large",get children(){var f=Me(),$=f.firstChild,S=$.firstChild,R=S.firstChild,m=R.firstChild,z=$.nextSibling,V=z.firstChild,A=V.firstChild,y=A.nextSibling;f.$$keydown=N,a.insert(R,a.createComponent(M.Show,{get when(){return s.searching()},get fallback(){return a.createComponent(t.Icon,{name:"magnifying-glass",size:"small"})},get children(){return a.createComponent(t.Loader,{size:"small"})}}),m),m.$$input=n=>s.input(n.currentTarget.value);var w=L;typeof w=="function"?a.use(w,m):L=m,a.setAttribute(m,"spellcheck",!1);var I=l;typeof I=="function"?a.use(I,z):l=z,a.insert(z,a.createComponent(M.Show,{get when(){return s.rows().length===0},get children(){var n=ye(),C=n.firstChild;return a.insert(C,()=>fe(d.plural,{error:s.error(),searching:s.searching(),indexing:s.indexing()})),n}}),V),a.insert(A,a.createComponent(M.For,{get each(){return s.rows()},children:(n,C)=>(()=>{var b=Se(),E=b.firstChild,Z=E.firstChild,K=E.nextSibling,u=K.firstChild,g=u.firstChild,v=u.nextSibling,k=v.firstChild,B=k.firstChild;return b.$$mousemove=()=>s.setSelected(C()),b.$$click=()=>_(n),a.insert(g,a.createComponent(M.For,{get each(){return de(n.title,s.text(),r.kind)},children:c=>c.hit?(()=>{var x=_e();return a.insert(x,()=>c.text),x})():c.text})),a.insert(u,a.createComponent(M.Show,{get when(){return pe(n,s.viewer())},children:c=>(()=>{var x=Ae();return a.insert(x,()=>c().label),a.effect(()=>a.setAttribute(x,"data-tone",c().tone||void 0)),x})()}),null),a.insert(k,()=>Q(n,s.many()).before,B),a.insert(B,()=>Q(n,s.many()).author),a.insert(k,()=>Q(n,s.many()).after,null),a.insert(v,a.createComponent(M.Show,{get when(){return n.stack},children:c=>(()=>{var x=Ze(),G=x.firstChild,D=G.nextSibling,W=D.nextSibling;return D.innerHTML='<svg version="1.1" width="12" height="12" viewBox="0 0 16 16" class="octicon octicon-stack" aria-hidden="true" data-component="Octicon"><path d="M7.122.392a1.75 1.75 0 0 1 1.756 0l5.003 2.902c.83.481.83 1.68 0 2.162L8.878 8.358a1.75 1.75 0 0 1-1.756 0L2.119 5.456a1.251 1.251 0 0 1 0-2.162ZM8.125 1.69a.248.248 0 0 0-.25 0l-4.63 2.685 4.63 2.685a.248.248 0 0 0 .25 0l4.63-2.685ZM1.601 7.789a.75.75 0 0 1 1.025-.273l5.249 3.044a.248.248 0 0 0 .25 0l5.249-3.044a.75.75 0 0 1 .752 1.298l-5.248 3.044a1.75 1.75 0 0 1-1.756 0L1.874 8.814A.75.75 0 0 1 1.6 7.789Zm0 3.5a.75.75 0 0 1 1.025-.273l5.249 3.044a.248.248 0 0 0 .25 0l5.249-3.044a.75.75 0 0 1 .752 1.298l-5.248 3.044a1.75 1.75 0 0 1-1.756 0l-5.248-3.044a.75.75 0 0 1-.273-1.025Z"></path></svg>',a.insert(x,()=>c().position,W),a.insert(x,()=>c().size,null),a.effect(()=>a.setAttribute(x,"title",`Stack ${c().position} of ${c().size}`+(c().parent?`, on top of #${c().parent}`:""))),x})()}),null),a.effect(c=>{var x=C()===s.selected(),G=n.kind,D=n.state,W=d.states[n.state]??n.state,X=d.states[n.state]??n.state,ee=ze[n.kind][n.state]??"",te=!!ne(n,s.viewer());return x!==c.e&&a.setAttribute(b,"data-active",c.e=x),G!==c.t&&a.setAttribute(Z,"data-kind",c.t=G),D!==c.a&&a.setAttribute(Z,"data-state",c.a=D),W!==c.o&&a.setAttribute(Z,"title",c.o=W),X!==c.i&&a.setAttribute(Z,"aria-label",c.i=X),ee!==c.n&&(Z.innerHTML=c.n=ee),te!==c.s&&B.classList.toggle("gh-search-me",c.s=te),c},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),b})()}));var O=i;return typeof O=="function"?a.use(O,y):i=y,a.insert(y,a.createComponent(M.Show,{get when(){return s.loadingMore()},get children(){return[a.createComponent(t.Loader,{size:"small"}),ke()]}}),null),a.insert(y,a.createComponent(M.Show,{get when(){return a.memo(()=>!s.loadingMore())()&&s.indexing()},get children(){return[a.createComponent(t.Loader,{size:"small"}),(()=>{var n=$e(),C=n.firstChild,b=C.nextSibling;return b.nextSibling,a.insert(n,()=>d.plural,b),n})()]}}),null),a.insert(y,a.createComponent(M.Show,{get when(){return a.memo(()=>!!(!s.loadingMore()&&s.error()))()&&s.rows().length>0},get children(){var n=Ce();return a.insert(n,()=>s.error()),n}}),null),a.effect(n=>{var C=e.appearance.mode(),b=le(r.kind);return C!==n.e&&a.setAttribute(f,"data-mode",n.e=C),b!==n.t&&a.setAttribute(m,"placeholder",n.t=b),n},{e:void 0,t:void 0}),a.effect(()=>m.value=s.text()),f}})}for(const r of Object.keys(Y)){const d=Y[r];e.add(U.Command,()=>({id:r,title:`Attach a GitHub ${d.noun}`,description:`/${d.command} [@repo] [query]`,keywords:`github ${d.noun} ${d.command}`,group:"GitHub",section:"prompt",slash:{name:d.command,arguments:!0},enabled:!!e.sessions.current(),run:l=>{const i=e.sessions.current();i&&e.dialogs.open(p=>a.createComponent(h,{kind:r,get directory(){return i.directory},initial:l??"",dialog:p}))}}))}}});a.delegateEvents(["keydown","input","click","mousemove"]);exports.default=je;
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "opencode-gh-search",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "type": "module",
4
+ "exports": {
5
+ ".": "./src/index.ts",
6
+ "./rpc": "./src/rpc.ts",
7
+ "./tui": "./src/tui.tsx",
8
+ "./gui-experimental": "./dist/gui-experimental.cjs"
9
+ },
10
+ "files": [
11
+ "src",
12
+ "dist"
13
+ ],
14
+ "scripts": {
15
+ "build": "vite build",
16
+ "prepublishOnly": "npm run typecheck && npm run build",
17
+ "dev": "vite build --watch",
18
+ "typecheck": "tsc --noEmit"
19
+ },
20
+ "dependencies": {
21
+ "@opencode/plugin": "2.2.7"
22
+ },
23
+ "devDependencies": {
24
+ "@opentui/core": "^0.8.1",
25
+ "@opentui/solid": "^0.8.1",
26
+ "@types/node": "^22.0.0",
27
+ "solid-js": "^1.9.0",
28
+ "typescript": "^5.6.0",
29
+ "vite": "^7.0.0",
30
+ "vite-plugin-solid": "^2.11.0"
31
+ },
32
+ "version": "0.1.0",
33
+ "description": "OpenCode plugin: /pr and /issue live search for GitHub pull requests and issues across repos, attached as context",
34
+ "license": "MIT",
35
+ "author": "Tom Uijtdehaag",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/TomUijtdehaag/opencode-gh-search.git"
39
+ },
40
+ "keywords": [
41
+ "opencode",
42
+ "opencode-plugin",
43
+ "github",
44
+ "pull-request",
45
+ "issue"
46
+ ]
47
+ }
package/src/gui.tsx ADDED
@@ -0,0 +1,325 @@
1
+ import { createSignal, For, onCleanup, Show } from "solid-js"
2
+ import { Command, LinkHandler, Plugin, Style, type DialogHandle } from "@opencode/plugin/gui"
3
+ import { KINDS, empty, highlight, meta, mine, status, placeholder, scope, type Item, type Kind } from "./rpc"
4
+ import { createSearch } from "./search"
5
+
6
+ const ROW_HEIGHT = 48
7
+
8
+ const STACK_ICON = "<svg version=\"1.1\" width=\"12\" height=\"12\" viewBox=\"0 0 16 16\" class=\"octicon octicon-stack\" aria-hidden=\"true\" data-component=\"Octicon\"><path d=\"M7.122.392a1.75 1.75 0 0 1 1.756 0l5.003 2.902c.83.481.83 1.68 0 2.162L8.878 8.358a1.75 1.75 0 0 1-1.756 0L2.119 5.456a1.251 1.251 0 0 1 0-2.162ZM8.125 1.69a.248.248 0 0 0-.25 0l-4.63 2.685 4.63 2.685a.248.248 0 0 0 .25 0l4.63-2.685ZM1.601 7.789a.75.75 0 0 1 1.025-.273l5.249 3.044a.248.248 0 0 0 .25 0l5.249-3.044a.75.75 0 0 1 .752 1.298l-5.248 3.044a1.75 1.75 0 0 1-1.756 0L1.874 8.814A.75.75 0 0 1 1.6 7.789Zm0 3.5a.75.75 0 0 1 1.025-.273l5.249 3.044a.248.248 0 0 0 .25 0l5.249-3.044a.75.75 0 0 1 .752 1.298l-5.248 3.044a1.75 1.75 0 0 1-1.756 0l-5.248-3.044a.75.75 0 0 1-.273-1.025Z\"></path></svg>"
9
+
10
+ // GitHub octicons (MIT), inlined so the bundle stays small.
11
+ const PR_ICONS: Record<string, string> = {
12
+ open: "<svg version=\"1.1\" width=\"12\" height=\"12\" viewBox=\"0 0 16 16\" class=\"octicon octicon-git-pull-request\" aria-hidden=\"true\" data-component=\"Octicon\"><path d=\"M1.5 3.25a2.25 2.25 0 1 1 3 2.122v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.25 2.25 0 0 1 1.5 3.25Zm5.677-.177L9.573.677A.25.25 0 0 1 10 .854V2.5h1A2.5 2.5 0 0 1 13.5 5v5.628a2.251 2.251 0 1 1-1.5 0V5a1 1 0 0 0-1-1h-1v1.646a.25.25 0 0 1-.427.177L7.177 3.427a.25.25 0 0 1 0-.354ZM3.75 2.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm0 9.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm8.25.75a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Z\"></path></svg>",
13
+ draft: "<svg version=\"1.1\" width=\"12\" height=\"12\" viewBox=\"0 0 16 16\" class=\"octicon octicon-git-pull-request-draft\" aria-hidden=\"true\" data-component=\"Octicon\"><path d=\"M3.25 1A2.25 2.25 0 0 1 4 5.372v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.251 2.251 0 0 1 3.25 1Zm9.5 14a2.25 2.25 0 1 1 0-4.5 2.25 2.25 0 0 1 0 4.5ZM2.5 3.25a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0ZM3.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm9.5 0a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5ZM14 7.5a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0Zm0-4.25a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0Z\"></path></svg>",
14
+ merged: "<svg version=\"1.1\" width=\"12\" height=\"12\" viewBox=\"0 0 16 16\" class=\"octicon octicon-git-merge\" aria-hidden=\"true\" data-component=\"Octicon\"><path d=\"M5.45 5.154A4.25 4.25 0 0 0 9.25 7.5h1.378a2.251 2.251 0 1 1 0 1.5H9.25A5.734 5.734 0 0 1 5 7.123v3.505a2.25 2.25 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.95-.218ZM4.25 13.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm8.5-4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5ZM5 3.25a.75.75 0 1 0 0 .005V3.25Z\"></path></svg>",
15
+ closed: "<svg version=\"1.1\" width=\"12\" height=\"12\" viewBox=\"0 0 16 16\" class=\"octicon octicon-git-pull-request-closed\" aria-hidden=\"true\" data-component=\"Octicon\"><path d=\"M3.25 1A2.25 2.25 0 0 1 4 5.372v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.251 2.251 0 0 1 3.25 1Zm9.5 5.5a.75.75 0 0 1 .75.75v3.378a2.251 2.251 0 1 1-1.5 0V7.25a.75.75 0 0 1 .75-.75Zm-2.03-5.273a.75.75 0 0 1 1.06 0l.97.97.97-.97a.748.748 0 0 1 1.265.332.75.75 0 0 1-.205.729l-.97.97.97.97a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-.97-.97-.97.97a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l.97-.97-.97-.97a.75.75 0 0 1 0-1.06ZM2.5 3.25a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0ZM3.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm9.5 0a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z\"></path></svg>",
16
+ }
17
+ const ISSUE_ICONS: Record<string, string> = {
18
+ open: "<svg version=\"1.1\" width=\"12\" height=\"12\" viewBox=\"0 0 16 16\" class=\"octicon octicon-issue-opened\" aria-hidden=\"true\"><path d=\"M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Z\"></path></svg>",
19
+ closed: "<svg version=\"1.1\" width=\"12\" height=\"12\" viewBox=\"0 0 16 16\" class=\"octicon octicon-issue-closed\" aria-hidden=\"true\"><path d=\"M11.28 6.78a.75.75 0 0 0-1.06-1.06L7.25 8.69 5.78 7.22a.75.75 0 0 0-1.06 1.06l2 2a.75.75 0 0 0 1.06 0l3.5-3.5Z M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0Zm-1.5 0a6.5 6.5 0 1 0-13 0 6.5 6.5 0 0 0 13 0Z\"></path></svg>",
20
+ }
21
+ const ICONS: Record<Kind, Record<string, string>> = { pr: PR_ICONS, issue: ISSUE_ICONS }
22
+ const BATCH = 20
23
+
24
+
25
+ // The app's list markup (`data-component=list`) gives rows, search field and selection the host's styling.
26
+ // Only the state badge and pager are ours; GitHub's state colors are the one deliberate non-theme color.
27
+ const css = `
28
+ [data-gh-search] [data-slot=list-search-input] {
29
+ flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 0;
30
+ color: var(--text-strong); font-family: var(--font-family-sans); font-size: var(--font-size-base, 14px);
31
+ line-height: 20px;
32
+ }
33
+ [data-gh-search] [data-slot=list-search-input]::placeholder { color: var(--text-weak); }
34
+ [data-gh-search] [data-slot=list-item] { display: flex; gap: 8px; cursor: default; position: relative; }
35
+ [data-gh-search] .gh-search-title,
36
+ [data-gh-search] .gh-search-weak { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
37
+ [data-gh-search] .gh-search-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
38
+ [data-gh-search] .gh-search-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
39
+ /* The stack's leading "· " already spaces it from the date; a full gap would read as a double space. */
40
+ [data-gh-search] .gh-search-line-meta { gap: 4px; }
41
+ [data-gh-search] .gh-search-title { flex: 1; }
42
+ [data-gh-search] .gh-search-meta {
43
+ color: var(--text-weak); font-size: var(--font-size-small, 12px); font-weight: var(--font-weight-regular);
44
+ line-height: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
45
+ }
46
+ [data-gh-search] .gh-search-weak { color: var(--text-weak); font-weight: var(--font-weight-regular); flex-shrink: 0; }
47
+ /* The state as GitHub's lists show it: just the octicon, in the state's colour. */
48
+ [data-gh-search] .gh-search-state-cell { flex-shrink: 0; width: 16px; display: flex; padding-top: 2px; }
49
+ [data-gh-search] .gh-search-stack { display: inline-flex; align-items: center; gap: 3px; }
50
+ [data-gh-search] .gh-search-stack svg { width: 12px; height: 12px; fill: currentColor; flex-shrink: 0; }
51
+ [data-gh-search] .gh-search-state { display: inline-flex; }
52
+ /* Review status: GitHub's Primer Label (outlined, no fill), with its light and dark colours. */
53
+ [data-gh-search] .gh-search-status {
54
+ flex-shrink: 0; display: inline-flex; align-items: center; height: 18px; padding: 0 7px; box-sizing: border-box;
55
+ border: 1px solid var(--gh-border); border-radius: 2em; color: var(--gh-fg);
56
+ font-size: 12px; font-weight: 500; line-height: 1; white-space: nowrap;
57
+ --gh-fg: #59636e; --gh-border: #d1d9e0;
58
+ }
59
+ [data-gh-search] .gh-search-status[data-tone=attention] { --gh-fg: #9a6700; --gh-border: #9a6700; }
60
+ [data-gh-search] .gh-search-status[data-tone=danger] { --gh-fg: #d1242f; --gh-border: #cf222e; }
61
+ [data-gh-search] .gh-search-status[data-tone=success] { --gh-fg: #1a7f37; --gh-border: #1a7f37; }
62
+ [data-gh-search][data-mode=dark] .gh-search-status { --gh-fg: #9198a1; --gh-border: #3d444d; }
63
+ [data-gh-search][data-mode=dark] .gh-search-status[data-tone=attention] { --gh-fg: #d29922; --gh-border: #9e6a03; }
64
+ [data-gh-search][data-mode=dark] .gh-search-status[data-tone=danger] { --gh-fg: #f85149; --gh-border: #da3633; }
65
+ [data-gh-search][data-mode=dark] .gh-search-status[data-tone=success] { --gh-fg: #3fb950; --gh-border: #238636; }
66
+ [data-gh-search] .gh-search-me { color: var(--text-strong); font-weight: var(--font-weight-medium, 500); }
67
+ /* Search hits: GitHub's search highlight (attention-muted background), since titles are already bold. */
68
+ [data-gh-search] .gh-search-hit { background: #fff8c5; color: inherit; border-radius: 2px; }
69
+ [data-gh-search][data-mode=dark] .gh-search-hit { background: rgba(187, 128, 9, 0.15); }
70
+ [data-gh-search] .gh-search-state svg { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; }
71
+ [data-gh-search] .gh-search-state[data-state=open] { color: #1a7f37; }
72
+ [data-gh-search] .gh-search-state[data-state=draft] { color: #59636e; }
73
+ [data-gh-search] .gh-search-state[data-state=merged] { color: #8250df; }
74
+ [data-gh-search] .gh-search-state[data-state=closed] { color: #d1242f; }
75
+ [data-gh-search] .gh-search-state[data-kind=issue][data-state=closed] { color: #8250df; }
76
+ [data-gh-search][data-mode=dark] .gh-search-state[data-state=open] { color: #3fb950; }
77
+ [data-gh-search][data-mode=dark] .gh-search-state[data-state=draft] { color: #9198a1; }
78
+ [data-gh-search][data-mode=dark] .gh-search-state[data-state=merged] { color: #ab7df8; }
79
+ [data-gh-search][data-mode=dark] .gh-search-state[data-state=closed] { color: #f85149; }
80
+ [data-gh-search][data-mode=dark] .gh-search-state[data-kind=issue][data-state=closed] { color: #ab7df8; }
81
+ /* Pinned to the dialog body (position: relative) so only the results scroll and the search stays on top. */
82
+ [data-gh-search][data-component=list] {
83
+ position: absolute; inset: 0; display: flex; flex-direction: column; gap: 8px; overflow: hidden;
84
+ padding: 4px 16px 12px; box-sizing: border-box;
85
+ }
86
+ [data-gh-search] [data-slot=list-search-wrapper] { flex-shrink: 0; }
87
+ [data-gh-search] [data-slot=list-scroll] { flex: 1 1 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
88
+ [data-gh-search] [data-slot=list-item] { height: ${ROW_HEIGHT}px; box-sizing: border-box; }
89
+ [data-gh-search] .gh-search-more {
90
+ display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 1px; padding: 4px 0 12px;
91
+ color: var(--text-weak); font-size: var(--font-size-small, 12px);
92
+ }
93
+ `
94
+
95
+
96
+ export default Plugin.define({
97
+ setup(ctx) {
98
+ const ui = ctx.ui
99
+ ctx.add(Style, css)
100
+
101
+ ctx.add(LinkHandler, {
102
+ match: (link) => link.origin === ctx.id,
103
+ open: (link) => ctx.system.openExternal(link.href),
104
+ })
105
+
106
+ function attach(item: Item) {
107
+ const repo = item.repo
108
+ const composer = ctx.screen.current()?.composer
109
+ if (!composer) return
110
+ composer.attach({
111
+ type: "note",
112
+ origin: ctx.id,
113
+ commentID: crypto.randomUUID(),
114
+ label: `${repo.split("/").pop()}#${item.number}`,
115
+ subtitle: item.title,
116
+ icon: "github",
117
+ subject: item.url,
118
+ comment: "",
119
+ href: item.url,
120
+ })
121
+ composer.focus()
122
+ }
123
+
124
+ function Search(props: { kind: Kind; directory: string; initial: string; dialog: DialogHandle }) {
125
+ const kind = KINDS[props.kind]
126
+ let scroll: HTMLDivElement | undefined
127
+ let sentinel: HTMLDivElement | undefined
128
+ let observer: IntersectionObserver | undefined
129
+ // A short first batch may not fill the list yet; keep loading while the end is still visible.
130
+ const checkEnd = () =>
131
+ queueMicrotask(() => {
132
+ if (!scroll || !sentinel) return
133
+ if (sentinel.getBoundingClientRect().top <= scroll.getBoundingClientRect().bottom + ROW_HEIGHT * 4) void s.more()
134
+ })
135
+ const s = createSearch({
136
+ solid: { createSignal, onCleanup },
137
+ client: ctx.client,
138
+ kind: props.kind,
139
+ directory: props.directory,
140
+ initial: props.initial,
141
+ batch: BATCH,
142
+ onReset: () => {
143
+ scroll?.scrollTo({ top: 0 })
144
+ checkEnd()
145
+ },
146
+ onMore: checkEnd,
147
+ })
148
+ onCleanup(() => observer?.disconnect())
149
+
150
+ function pick(item: Item | undefined) {
151
+ if (!item) return
152
+ props.dialog.close()
153
+ attach(item)
154
+ }
155
+
156
+ function select(index: number) {
157
+ s.setSelected(index)
158
+ scroll?.querySelectorAll("[data-slot=list-item]")[index]?.scrollIntoView({ block: "nearest" })
159
+ }
160
+
161
+ function onKeyDown(event: KeyboardEvent) {
162
+ const count = s.rows().length
163
+ const page = Math.max(1, Math.floor((scroll?.clientHeight ?? 0) / ROW_HEIGHT) - 1)
164
+ const keys: Record<string, () => void> = {
165
+ ArrowDown: () => count && select(Math.min(s.selected() + 1, count - 1)),
166
+ ArrowUp: () => count && select(Math.max(s.selected() - 1, 0)),
167
+ PageDown: () => count && select(Math.min(s.selected() + page, count - 1)),
168
+ PageUp: () => count && select(Math.max(s.selected() - page, 0)),
169
+ Enter: () => pick(s.current()),
170
+ }
171
+ const action = keys[event.key]
172
+ if (!action) return
173
+ event.preventDefault()
174
+ action()
175
+ }
176
+
177
+ let input: HTMLInputElement | undefined
178
+ requestAnimationFrame(() => {
179
+ input?.focus()
180
+ if (scroll && sentinel) {
181
+ observer = new IntersectionObserver((entries) => entries[0]?.isIntersecting && void s.more(), {
182
+ root: scroll,
183
+ rootMargin: `${ROW_HEIGHT * 4}px`,
184
+ })
185
+ observer.observe(sentinel)
186
+ }
187
+ })
188
+
189
+ return (
190
+ <ui.Dialog title={kind.title} description={scope(s.repos(), s.error())} size="large">
191
+ <div data-component="list" data-gh-search data-mode={ctx.appearance.mode()} onKeyDown={onKeyDown}>
192
+ <div data-slot="list-search-wrapper">
193
+ <div data-slot="list-search">
194
+ <div data-slot="list-search-container">
195
+ <Show when={s.searching()} fallback={<ui.Icon name="magnifying-glass" size="small" />}>
196
+ <ui.Loader size="small" />
197
+ </Show>
198
+ <input
199
+ ref={input}
200
+ data-slot="list-search-input"
201
+ type="text"
202
+ placeholder={placeholder(props.kind)}
203
+ value={s.text()}
204
+ onInput={(event) => s.input(event.currentTarget.value)}
205
+ spellcheck={false}
206
+ autocomplete="off"
207
+ />
208
+ </div>
209
+ </div>
210
+ </div>
211
+ <div data-slot="list-scroll" ref={scroll}>
212
+ <Show when={s.rows().length === 0}>
213
+ <div data-slot="list-empty-state">
214
+ <div data-slot="list-message">
215
+ {empty(kind.plural, { error: s.error(), searching: s.searching(), indexing: s.indexing() })}
216
+ </div>
217
+ </div>
218
+ </Show>
219
+ <div data-slot="list-group">
220
+ <div data-slot="list-items">
221
+ <For each={s.rows()}>
222
+ {(item, index) => (
223
+ <div
224
+ data-slot="list-item"
225
+ data-active={index() === s.selected()}
226
+ onClick={() => pick(item)}
227
+ onMouseMove={() => s.setSelected(index())}
228
+ >
229
+ <span class="gh-search-state-cell">
230
+ <span
231
+ class="gh-search-state"
232
+ data-kind={item.kind}
233
+ data-state={item.state}
234
+ title={kind.states[item.state] ?? item.state}
235
+ aria-label={kind.states[item.state] ?? item.state}
236
+ innerHTML={ICONS[item.kind][item.state] ?? ""}
237
+ />
238
+ </span>
239
+ <span class="gh-search-main">
240
+ <span class="gh-search-line">
241
+ <span class="gh-search-title">
242
+ <For each={highlight(item.title, s.text(), props.kind)}>
243
+ {(part) => (part.hit ? <mark class="gh-search-hit">{part.text}</mark> : part.text)}
244
+ </For>
245
+ </span>
246
+ <Show when={status(item, s.viewer())}>
247
+ {(st) => (
248
+ <span class="gh-search-status" data-tone={st().tone || undefined}>
249
+ {st().label}
250
+ </span>
251
+ )}
252
+ </Show>
253
+ </span>
254
+ <span class="gh-search-line gh-search-line-meta">
255
+ <span class="gh-search-meta">
256
+ {meta(item, s.many()).before}
257
+ <span classList={{ "gh-search-me": mine(item, s.viewer()) }}>{meta(item, s.many()).author}</span>
258
+ {meta(item, s.many()).after}
259
+ </span>
260
+ <Show when={item.stack}>
261
+ {(stack) => (
262
+ <span
263
+ class="gh-search-weak gh-search-stack gh-search-meta"
264
+ title={
265
+ `Stack ${stack().position} of ${stack().size}` +
266
+ (stack().parent ? `, on top of #${stack().parent}` : "")
267
+ }
268
+ >
269
+ {"· "}
270
+ <span innerHTML={STACK_ICON} style={{ display: "contents" }} />
271
+ {stack().position}/{stack().size}
272
+ </span>
273
+ )}
274
+ </Show>
275
+ </span>
276
+ </span>
277
+ </div>
278
+ )}
279
+ </For>
280
+ </div>
281
+ <div ref={sentinel} class="gh-search-more">
282
+ <Show when={s.loadingMore()}>
283
+ <ui.Loader size="small" />
284
+ <span>Loading more…</span>
285
+ </Show>
286
+ <Show when={!s.loadingMore() && s.indexing()}>
287
+ <ui.Loader size="small" />
288
+ <span>Indexing {kind.plural}…</span>
289
+ </Show>
290
+ <Show when={!s.loadingMore() && s.error() && s.rows().length > 0}>
291
+ <span>{s.error()}</span>
292
+ </Show>
293
+ </div>
294
+ </div>
295
+ </div>
296
+ </div>
297
+ </ui.Dialog>
298
+ )
299
+ }
300
+
301
+ for (const id of Object.keys(KINDS) as Kind[]) {
302
+ const kind = KINDS[id]
303
+ ctx.add(
304
+ Command,
305
+ (): Command => ({
306
+ id,
307
+ title: `Attach a GitHub ${kind.noun}`,
308
+ description: `/${kind.command} [@repo] [query]`,
309
+ keywords: `github ${kind.noun} ${kind.command}`,
310
+ group: "GitHub",
311
+ section: "prompt",
312
+ slash: { name: kind.command, arguments: true },
313
+ enabled: !!ctx.sessions.current(),
314
+ run: (input) => {
315
+ const session = ctx.sessions.current()
316
+ if (!session) return
317
+ ctx.dialogs.open((dialog) => (
318
+ <Search kind={id} directory={session.directory} initial={input ?? ""} dialog={dialog} />
319
+ ))
320
+ },
321
+ }),
322
+ )
323
+ }
324
+ },
325
+ })