Repository navigation
Add automation session modes and richer PR editing #1919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f0bbc4e
Enable safe task toggles in pull request descriptions
b6102f8
Add scoped repository completions to PR and MR editors
c4ec073
Resolve numeric PR and MR completion references directly
383e078
Validate completion query tokens before forge search
153eb47
Add fixed automation destinations and session modes
b75f415
Run repository completion regressions in Windows CI
8d6b2ff
Regenerate automation docs text and sitemap metadata
197a660
Fix automation draft navigation and shared run history
2a9736d
Preserve native editor keys without completion candidates
db66273
Keep fake GitHub reads from racing over fixture state
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| "use strict"; | ||
|
|
||
| /** Missing mode keeps legacy new-thread-per-run definitions unchanged. */ | ||
| function destinationFields(input, base = {}) { | ||
| const sessionMode = input.sessionMode === undefined | ||
| ? (base.sessionMode || "new-thread") : input.sessionMode; | ||
| if (!["new-thread", "continue", "fresh"].includes(sessionMode)) { | ||
| throw new Error("Invalid automation session mode"); | ||
| } | ||
| const raw = input.destinationThreadId === undefined | ||
| ? base.destinationThreadId : input.destinationThreadId; | ||
| const destinationThreadId = sessionMode === "new-thread" ? null : String(raw || "").trim(); | ||
| if (sessionMode !== "new-thread" && !destinationThreadId) { | ||
| throw new Error("Destination thread is required"); | ||
| } | ||
| return { sessionMode, destinationThreadId }; | ||
| } | ||
|
|
||
| /** Save validates identity and authority; execution additionally requires an idle target. */ | ||
| function destinationThread(store, auto, runner, staticOnly = false) { | ||
| const { sessionMode, destinationThreadId } = destinationFields(auto); | ||
| if (sessionMode === "new-thread") return null; | ||
| const t = store.getThread(destinationThreadId); | ||
| if (!t || t.projectId !== auto.projectId) { | ||
| throw new Error("Automation destination must exist in its project"); | ||
| } | ||
| if (t.archived || t.trashedAt || t.deletedAt || t.teleportedTo || | ||
| t.memoryConsolidate || t.ask || t.pendingFork) { | ||
| throw new Error("Automation destination is unavailable"); | ||
| } | ||
| if (!staticOnly && (runner?.isRunning?.(t.id) || | ||
| t.status === "working" || t.status === "quota-wait" || | ||
| t.quotaWaitUntil || t.quotaFailoverPending || t.pendingPlan || | ||
| t.pendingQuestion || t.pendingApproval || t.pendingSecret || t.awaitingInput || | ||
| t.runQueue || t.queued || t.interruptedAt || t.btw?.length || | ||
| runner?.getPendingPermission?.(t.id))) { | ||
| throw Object.assign( | ||
| new Error("Automation destination has unfinished work or pending input; run skipped"), | ||
| { code: "AUTOMATION_DESTINATION_BUSY" }, | ||
| ); | ||
| } | ||
| // Fixed destinations retain identity, but cannot lend their additional authority. | ||
| if (t.provider !== auto.provider || (t.model || null) !== (auto.model || null) || | ||
| t.providerInstance || t.agentProfileId || t.autoApprove || | ||
| (t.permissionMode && t.permissionMode !== "default") || | ||
| t.folderWriteGrants?.length || t.restartGrant || t.alwaysAllowKeys?.length || | ||
| t.alwaysAllowRules?.length || t.route || auto.tier) { | ||
| throw new Error("Automation destination must match provider/model with default permissions, no account override, grants, or routing"); | ||
| } | ||
| if (!staticOnly && t.freshContextPending && sessionMode !== "fresh") { | ||
| throw new Error("Automation destination is waiting for a user message after fresh context"); | ||
| } | ||
| return t; | ||
| } | ||
|
|
||
| module.exports = { destinationFields, destinationThread }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| "use strict"; | ||
| const { gitTryAsync, ghApiTryAsync, tailErr } = require('./worktrees.js'); | ||
| const { gitlabRemote, glabApi } = require('./gitlab.js'); | ||
| const { parseRepoSlug } = require('./prLinks.js'); | ||
|
|
||
| // Every request resolves origin anew. Never search all users or all accounts. | ||
| async function prCompletions(input) { | ||
| const cwd = String(input?.projectPath || ''); | ||
| const kind = input?.kind; | ||
| if (!cwd || !['@', '#', '!'].includes(kind)) return { ok: false, reason: 'Invalid completion request' }; | ||
| // Match the textarea token grammar at the trust boundary too. In particular, | ||
| // GitHub search qualifiers, spaces and quotes must never augment repo scope. | ||
| const query = input.query == null ? '' : input.query; | ||
| if (typeof query !== 'string' || !/^[\w.-]{0,100}$/.test(query)) { | ||
| return { ok: false, reason: 'Invalid completion query' }; | ||
| } | ||
| const page = Math.max(1, Math.min(10, Math.trunc(Number(input.page) || 1))); | ||
| const remote = await gitTryAsync(cwd, ['remote', 'get-url', 'origin']); | ||
| if (!remote.ok) return { ok: false, reason: 'Repository unavailable' }; | ||
| const origin = String(remote.stdout || '').trim(); | ||
| const gl = gitlabRemote(origin); | ||
| let rows; | ||
| let exact = null; | ||
| const numeric = kind !== "@" && page === 1 && /^[1-9]\d*$/.test(query) && Number.isSafeInteger(Number(query)); | ||
| if (gl) { | ||
| // Explicit cross-repo requests stay on the origin host and its authenticated account. | ||
| if (input.repo) gl.path = String(input.repo); | ||
| const endpoint = kind === '@' ? '/members/all' : kind === '!' ? '/merge_requests' : '/issues'; | ||
| const [result, direct] = await Promise.all([ | ||
| glabApi(cwd, gl, 'GET', `${endpoint}?per_page=20&page=${page}&${kind === '@' ? 'query' : 'search'}=${encodeURIComponent(query)}`), | ||
| numeric ? glabApi(cwd, gl, 'GET', `${endpoint}/${Number(query)}`) : null, | ||
| ]); | ||
| if (direct?.ok && Number(direct.data?.iid) === Number(query)) exact = direct.data; | ||
| if (!result.ok && !exact) return result; | ||
| rows = result.ok && Array.isArray(result.data) ? result.data : []; | ||
| } else { | ||
| if (kind === '!') return { ok: true, items: [], hasMore: false }; | ||
| const slug = parseRepoSlug(input.repo || origin); | ||
| if (!slug) return { ok: false, reason: 'Repository unavailable' }; | ||
| const endpoint = kind === '@' | ||
| ? `repos/${slug}/assignees?per_page=20&page=${page}` | ||
| : `search/issues?q=${encodeURIComponent(`repo:${slug} ${query}`)}&per_page=20&page=${page}`; | ||
| const host = origin.match(/^[^@/]+@([^:]+):/)?.[1] || (() => { try { return new URL(origin).hostname; } catch { return null; } })(); | ||
| if (!host) return { ok: false, reason: 'Repository host unavailable' }; | ||
| const request = endpoint => ghApiTryAsync(cwd, ['api', endpoint, '--hostname', host], { originUrl: origin, timeout: 15000 }); | ||
| const [result, direct] = await Promise.all([ | ||
| request(endpoint), numeric ? request(`repos/${slug}/issues/${Number(query)}`) : null, | ||
| ]); | ||
| if (direct?.ok) { | ||
| try { const data = JSON.parse(direct.stdout); if (Number(data?.number) === Number(query)) exact = data; } catch { /* search remains available */ } | ||
| } | ||
| if (!result.ok && !exact) return { ok: false, reason: tailErr(result.stderr || result.combined, 'Completion search failed') }; | ||
| try { const data = result.ok ? JSON.parse(result.stdout) : []; rows = Array.isArray(data) ? data : data.items || []; } | ||
| catch { if (!exact) return { ok: false, reason: 'Invalid completion response' }; rows = []; } | ||
| } | ||
| const hasMore = rows.length >= 20 && page < 10; | ||
| // Pin the exact reference without displacing any of the 20 search rows or | ||
| // shifting subsequent search pages. A first numeric page has at most 21 items. | ||
| if (exact) rows = [exact, ...rows.filter(row => Number(row.iid || row.number) !== Number(query))]; | ||
| const items = rows.map(row => kind === '@' | ||
| ? { value: `@${row.username || row.login}`, label: row.name || row.username || row.login } | ||
| : { value: `${kind}${row.iid || row.number}`, label: row.title || '' }) | ||
| .filter(row => row.value.toLowerCase().includes(query.toLowerCase()) || row.label.toLowerCase().includes(query.toLowerCase())) | ||
| .slice(0, exact ? 21 : 20); | ||
| return { ok: true, items, hasMore }; | ||
| } | ||
| module.exports = { prCompletions: async input => { | ||
| try { return await prCompletions(input); } | ||
| catch { return { ok: false, reason: 'Completion search unavailable' }; } | ||
| } }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.