@nathanstephenson/flow 0.1.10-beta.8 → 0.1.10-beta.9
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/build/backend-worker-chunks/{claude-THGSOTC2.mjs → claude-X57GT57M.mjs} +12 -4
- package/build/backend-worker-chunks/{pi-5LAWIJNE.mjs → pi-IZ3GX6HN.mjs} +5 -1
- package/build/backend-worker.mjs +7 -4
- package/dist/backend/claude/index.js +15 -4
- package/dist/backend/mcp.js +4 -1
- package/dist/backend/pi/index.js +6 -1
- package/dist/backend/worker/index.js +8 -3
- package/dist/build-id +1 -1
- package/dist/cli/bootstrap.js +1 -1
- package/dist/client/connection.js +46 -0
- package/dist/client/project-name.js +3 -1
- package/dist/client/scope-kind.js +4 -0
- package/dist/daemon/changes.js +22 -12
- package/dist/daemon/git.js +10 -1
- package/dist/daemon/host.js +248 -42
- package/dist/daemon/pull-request.js +90 -25
- package/dist/daemon/repository.js +15 -9
- package/dist/daemon/runtime.js +2 -0
- package/dist/daemon/server.js +25 -0
- package/dist/daemon/tour.js +7 -1
- package/dist/daemon/workflow-environment.js +6 -4
- package/dist/daemon/workflow-executions.js +1 -1
- package/dist/isolation/filesystem.js +1 -1
- package/dist/protocol/spend.js +1 -1
- package/dist/workflows/executors.js +2 -1
- package/package.json +1 -1
- package/web/dist/assets/index-CHFNROUs.js +51 -0
- package/web/dist/assets/index-D9AneSPi.css +2 -0
- package/web/dist/assets/{select-C-BND5Jn.js → select-COVn-75j.js} +1 -1
- package/web/dist/assets/{settings-mcp-DEU2AgQP.js → settings-mcp-BHZwEeJF.js} +1 -1
- package/web/dist/assets/{settings-secrets-29ZG3w6p.js → settings-secrets-NGSRhEbU.js} +1 -1
- package/web/dist/assets/settings-workflows-uew3ONyO.js +23 -0
- package/web/dist/assets/{workflow-api-DkUjAZ4w.js → workflow-api-3z2Qqsmo.js} +1 -1
- package/web/dist/assets/{workflows-DOxarXng.js → workflows-hcZXxss1.js} +2 -2
- package/web/dist/assets/{workflows-pane-DlaP2y8m.js → workflows-pane-DntY7Dcw.js} +1 -1
- package/web/dist/index.html +5 -5
- package/web/dist/assets/index-Cf28Ke0f.js +0 -51
- package/web/dist/assets/index-DBl7acBx.css +0 -2
- package/web/dist/assets/settings-workflows-CS_5CtP9.js +0 -23
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { api, connection, gh, page } from "./github.js";
|
|
2
|
-
import { githubRepository, localRepository, mergeMethods, mergeSettingsFields, resolvePullRequest, resolveRepository, writers } from "./repository.js";
|
|
2
|
+
import { githubRepository, localRepository, mergeMethods, mergeSettingsFields, pullRequestByNumber, resolvePullRequest, resolveRepository, writers } from "./repository.js";
|
|
3
3
|
import { cleanStack } from "./stack.js";
|
|
4
4
|
import { pushTarget, remoteHead } from "./push.js";
|
|
5
5
|
import { localStack, stackParent } from "./stack-metadata.js";
|
|
6
|
-
import { head, isRepository, run, GIT_WRITE_TIMEOUT_MS } from "./git.js";
|
|
6
|
+
import { head, isRepository, run, GIT_READ_TIMEOUT_MS, GIT_WRITE_TIMEOUT_MS } from "./git.js";
|
|
7
7
|
const commentFields = "id author{login} body url createdAt";
|
|
8
8
|
const threadFields = "id path line isOutdated isResolved viewerCanReply viewerCanResolve viewerCanUnresolve";
|
|
9
9
|
const threadCommentFields = `${commentFields} diffHunk`;
|
|
@@ -54,6 +54,29 @@ export async function pullRequest(scope, known, github = gh) {
|
|
|
54
54
|
const resolved = await resolvePullRequest(scope, repository, branch.value.name, github);
|
|
55
55
|
return resolved ? (await details(scope, resolved, github))?.pr ?? null : null;
|
|
56
56
|
}
|
|
57
|
+
export async function projectPullRequest(scope, number, github = gh) {
|
|
58
|
+
if (!Number.isSafeInteger(number) || number < 1)
|
|
59
|
+
throw new Error("Invalid pull request number.");
|
|
60
|
+
const repository = await resolveRepository(scope, undefined, github);
|
|
61
|
+
const found = await pullRequestByNumber(scope, repository.base.repo, number, github);
|
|
62
|
+
return found ? (await details(scope, found, github))?.pr ?? null : null;
|
|
63
|
+
}
|
|
64
|
+
const listFields = "id number title state isDraft updatedAt author{login} reviewRequests(first:100){nodes{requestedReviewer{... on User{login}}}}";
|
|
65
|
+
/** Open Pull Requests of the base repository, or with `query`, all of them whose title matches. */
|
|
66
|
+
export async function listPullRequests(scope, github = gh, query) {
|
|
67
|
+
const repo = (await resolveRepository(scope, undefined, github)).base.repo;
|
|
68
|
+
const [owner, name] = repo.split("/");
|
|
69
|
+
const item = (viewer) => ({ author, reviewRequests, repository: _, ...node }) => ({
|
|
70
|
+
...node, repo, author: author?.login ?? "[deleted]",
|
|
71
|
+
reviewRequested: reviewRequests.nodes.some(request => request.requestedReviewer?.login === viewer),
|
|
72
|
+
});
|
|
73
|
+
if (query) {
|
|
74
|
+
const data = await api(scope, github, `query($q:String!){viewer{login} search(type:ISSUE,first:50,query:$q){nodes{... on PullRequest{${listFields} repository{nameWithOwner}}}}}`, { q: `repo:${repo} is:pr in:title sort:updated-desc ${query}` });
|
|
75
|
+
return data.search.nodes.filter((node) => node.repository?.nameWithOwner.toLowerCase() === repo.toLowerCase()).map(item(data.viewer.login));
|
|
76
|
+
}
|
|
77
|
+
const data = await api(scope, github, `query($owner:String!,$name:String!){viewer{login} repository(owner:$owner,name:$name){pullRequests(states:OPEN,first:100,orderBy:{field:UPDATED_AT,direction:DESC}){nodes{${listFields}}}}}`, { owner: owner, name: name });
|
|
78
|
+
return data.repository.pullRequests.nodes.map(item(data.viewer.login)).sort((a, b) => Number(b.reviewRequested) - Number(a.reviewRequested));
|
|
79
|
+
}
|
|
57
80
|
async function git(scope, args) {
|
|
58
81
|
const result = await run(scope, args, GIT_WRITE_TIMEOUT_MS);
|
|
59
82
|
if (!result.ok)
|
|
@@ -88,6 +111,44 @@ function validate(ref) {
|
|
|
88
111
|
if (!ref || typeof ref.repo !== "string" || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(ref.repo) || !Number.isSafeInteger(ref.number) || ref.number < 1 || !validId(ref.id))
|
|
89
112
|
throw new Error("Invalid pull request reference.");
|
|
90
113
|
}
|
|
114
|
+
export const projectTarget = async (scope, ref, github) => {
|
|
115
|
+
validate(ref);
|
|
116
|
+
const repository = await resolveRepository(scope, undefined, github);
|
|
117
|
+
const pr = ref.repo === repository.base.repo ? await pullRequestByNumber(scope, ref.repo, ref.number, github) : undefined;
|
|
118
|
+
if (!pr || pr.id !== ref.id)
|
|
119
|
+
throw new Error("The pull request has changed. Reload it before continuing.");
|
|
120
|
+
return pr;
|
|
121
|
+
};
|
|
122
|
+
export async function remoteUrl(scope, repo) {
|
|
123
|
+
for (const remote of (await git(scope, ["remote"])).split("\n").filter(Boolean)) {
|
|
124
|
+
const url = await git(scope, ["remote", "get-url", remote]);
|
|
125
|
+
if (githubRepository(url)?.toLowerCase() === repo.toLowerCase())
|
|
126
|
+
return { remote, url };
|
|
127
|
+
}
|
|
128
|
+
return { url: `https://github.com/${repo}.git` };
|
|
129
|
+
}
|
|
130
|
+
export async function fetchBranch(scope, remote, branch) {
|
|
131
|
+
await git(scope, ["check-ref-format", `refs/heads/${branch}`]);
|
|
132
|
+
await git(scope, ["fetch", "--no-tags", remote, `+refs/heads/${branch}:refs/remotes/${remote}/${branch}`]);
|
|
133
|
+
return await git(scope, ["rev-parse", `refs/remotes/${remote}/${branch}`]);
|
|
134
|
+
}
|
|
135
|
+
export async function dropUnchangedBranch(scope, branch, oid) {
|
|
136
|
+
const current = await run(scope, ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`], GIT_READ_TIMEOUT_MS);
|
|
137
|
+
if (current.ok && current.value.trim() === oid)
|
|
138
|
+
await run(scope, ["branch", "-D", "--", branch], GIT_WRITE_TIMEOUT_MS);
|
|
139
|
+
}
|
|
140
|
+
const hasCommit = async (scope, oid) => (await run(scope, ["cat-file", "-e", `${oid}^{commit}`], GIT_READ_TIMEOUT_MS)).ok;
|
|
141
|
+
export async function pullRequestRange(scope, ref, github = gh) {
|
|
142
|
+
validate(ref);
|
|
143
|
+
const pr = await projectTarget(scope, ref, github);
|
|
144
|
+
if (!await hasCommit(scope, pr.headRefOid) || !await hasCommit(scope, pr.baseRefOid)) {
|
|
145
|
+
await git(scope, ["check-ref-format", `refs/heads/${pr.baseBranch}`]);
|
|
146
|
+
await git(scope, ["fetch", "--no-tags", "--no-write-fetch-head", (await remoteUrl(scope, pr.repo)).url, `refs/pull/${pr.number}/head`, `refs/heads/${pr.baseBranch}`]);
|
|
147
|
+
if (!await hasCommit(scope, pr.headRefOid) || !await hasCommit(scope, pr.baseRefOid))
|
|
148
|
+
throw new Error("The pull request has changed. Reload it before continuing.");
|
|
149
|
+
}
|
|
150
|
+
return { base: pr.baseRefOid, head: pr.headRefOid, pr };
|
|
151
|
+
}
|
|
91
152
|
async function target(scope, ref, github) {
|
|
92
153
|
const selected = await head(scope);
|
|
93
154
|
const branch = selected.ok && !selected.value.detached ? selected.value.name : undefined;
|
|
@@ -96,7 +157,7 @@ async function target(scope, ref, github) {
|
|
|
96
157
|
throw new Error("The branch's pull request has changed. Reload it before continuing.");
|
|
97
158
|
return { ...pr, branch: branch };
|
|
98
159
|
}
|
|
99
|
-
export async function changePullRequest(scope, action, input, github = gh) {
|
|
160
|
+
export async function changePullRequest(scope, action, input, github = gh, find = target) {
|
|
100
161
|
validate(input?.pr);
|
|
101
162
|
if (action !== "rebase" && action !== "merge")
|
|
102
163
|
throw new Error("Invalid pull request action.");
|
|
@@ -104,9 +165,11 @@ export async function changePullRequest(scope, action, input, github = gh) {
|
|
|
104
165
|
throw new Error("Invalid pull request action.");
|
|
105
166
|
if (action === "merge" && !["MERGE", "SQUASH", "REBASE"].includes(input.method ?? ""))
|
|
106
167
|
throw new Error("Invalid merge method.");
|
|
168
|
+
if (action === "rebase" && find !== target)
|
|
169
|
+
throw new Error("Rebase this pull request from an Agent Session on its branch.");
|
|
107
170
|
if (action === "rebase")
|
|
108
171
|
await cleanStack(scope);
|
|
109
|
-
const pr = await target(scope, input.pr, github);
|
|
172
|
+
const pr = await (action === "merge" ? find : target)(scope, input.pr, github);
|
|
110
173
|
if (pr.state !== "OPEN" || pr.headRefOid !== input.headOid || pr.baseBranch !== input.baseBranch)
|
|
111
174
|
throw new Error("The pull request has changed. Reload it before continuing.");
|
|
112
175
|
if (action === "merge") {
|
|
@@ -117,15 +180,7 @@ export async function changePullRequest(scope, action, input, github = gh) {
|
|
|
117
180
|
}
|
|
118
181
|
await git(scope, ["check-ref-format", `refs/heads/${pr.baseBranch}`]);
|
|
119
182
|
const before = await git(scope, ["rev-parse", "HEAD"]);
|
|
120
|
-
|
|
121
|
-
for (const remote of (await git(scope, ["remote"])).split("\n").filter(Boolean)) {
|
|
122
|
-
const url = await git(scope, ["remote", "get-url", remote]);
|
|
123
|
-
const repo = githubRepository(url);
|
|
124
|
-
if (repo?.toLowerCase() === pr.repo.toLowerCase()) {
|
|
125
|
-
baseUrl = url;
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
183
|
+
const baseUrl = (await remoteUrl(scope, pr.repo)).url;
|
|
129
184
|
await git(scope, ["fetch", "--no-tags", baseUrl, `refs/heads/${pr.baseBranch}`]);
|
|
130
185
|
const base = await git(scope, ["rev-parse", "FETCH_HEAD"]);
|
|
131
186
|
const latest = await target(scope, input.pr, github);
|
|
@@ -146,11 +201,11 @@ async function requireThread(scope, pr, thread, github) {
|
|
|
146
201
|
if (data.node?.pullRequest?.id !== pr.id)
|
|
147
202
|
throw new Error("This review thread is not on this pull request. Reload it before continuing.");
|
|
148
203
|
}
|
|
149
|
-
export async function commentPullRequest(scope, input, github = gh) {
|
|
204
|
+
export async function commentPullRequest(scope, input, github = gh, find = target) {
|
|
150
205
|
validate(input?.pr);
|
|
151
206
|
if (typeof input.body !== "string" || !input.body.trim() || (input.threadId !== undefined && !validId(input.threadId)))
|
|
152
207
|
throw new Error("Invalid comment input.");
|
|
153
|
-
const pr = await
|
|
208
|
+
const pr = await find(scope, input.pr, github);
|
|
154
209
|
if (input.threadId !== undefined) {
|
|
155
210
|
await requireThread(scope, pr, input.threadId, github);
|
|
156
211
|
await api(scope, github, "mutation($id:ID!,$body:String!){addPullRequestReviewThreadReply(input:{pullRequestReviewThreadId:$id,body:$body}){comment{id}}}", { id: input.threadId, body: input.body });
|
|
@@ -158,45 +213,45 @@ export async function commentPullRequest(scope, input, github = gh) {
|
|
|
158
213
|
else
|
|
159
214
|
await api(scope, github, "mutation($id:ID!,$body:String!){addComment(input:{subjectId:$id,body:$body}){commentEdge{node{id}}}}", { id: pr.id, body: input.body });
|
|
160
215
|
}
|
|
161
|
-
export async function resolvePullRequestThread(scope, input, github = gh) {
|
|
216
|
+
export async function resolvePullRequestThread(scope, input, github = gh, find = target) {
|
|
162
217
|
validate(input?.pr);
|
|
163
218
|
if (!validId(input.threadId) || typeof input.resolved !== "boolean")
|
|
164
219
|
throw new Error("Invalid thread input.");
|
|
165
|
-
await requireThread(scope, await
|
|
220
|
+
await requireThread(scope, await find(scope, input.pr, github), input.threadId, github);
|
|
166
221
|
const operation = input.resolved ? "resolveReviewThread" : "unresolveReviewThread";
|
|
167
222
|
await api(scope, github, `mutation($id:ID!){${operation}(input:{threadId:$id}){thread{id}}}`, { id: input.threadId });
|
|
168
223
|
}
|
|
169
|
-
export async function editPullRequest(scope, input, github = gh) {
|
|
224
|
+
export async function editPullRequest(scope, input, github = gh, find = target) {
|
|
170
225
|
validate(input?.pr);
|
|
171
226
|
if (typeof input.title !== "string" || !input.title.trim() || typeof input.body !== "string")
|
|
172
227
|
throw new Error("Enter a pull request title.");
|
|
173
|
-
const pr = await
|
|
228
|
+
const pr = await find(scope, input.pr, github);
|
|
174
229
|
await api(scope, github, "mutation($id:ID!,$title:String!,$body:String!){updatePullRequest(input:{pullRequestId:$id,title:$title,body:$body}){pullRequest{id}}}", { id: pr.id, title: input.title, body: input.body });
|
|
175
230
|
}
|
|
176
|
-
export async function setPullRequestDraft(scope, input, github = gh) {
|
|
231
|
+
export async function setPullRequestDraft(scope, input, github = gh, find = target) {
|
|
177
232
|
validate(input?.pr);
|
|
178
233
|
if (typeof input.draft !== "boolean")
|
|
179
234
|
throw new Error("Invalid draft input.");
|
|
180
|
-
const pr = await
|
|
235
|
+
const pr = await find(scope, input.pr, github);
|
|
181
236
|
const operation = input.draft ? "convertPullRequestToDraft" : "markPullRequestReadyForReview";
|
|
182
237
|
await api(scope, github, `mutation($id:ID!){${operation}(input:{pullRequestId:$id}){pullRequest{id}}}`, { id: pr.id });
|
|
183
238
|
}
|
|
184
|
-
export async function rerunPullRequestChecks(scope, input, github = gh) {
|
|
239
|
+
export async function rerunPullRequestChecks(scope, input, github = gh, find = target) {
|
|
185
240
|
validate(input?.pr);
|
|
186
241
|
if (!Number.isSafeInteger(input.runId) || input.runId < 1)
|
|
187
242
|
throw new Error("Invalid run ID.");
|
|
188
|
-
const pr = await
|
|
243
|
+
const pr = await find(scope, input.pr, github);
|
|
189
244
|
const run = JSON.parse(await github(scope, ["api", `repos/${pr.repo}/actions/runs/${input.runId}`]));
|
|
190
245
|
if (run.head_sha !== pr.headRefOid)
|
|
191
246
|
throw new Error("This run is not for the current head of the pull request. Reload it before you re-run checks.");
|
|
192
247
|
await github(scope, ["run", "rerun", String(input.runId), "--failed", "--repo", pr.repo]);
|
|
193
248
|
}
|
|
194
249
|
const checkLogLines = 80;
|
|
195
|
-
export async function checkLog(scope, ref, jobId, github = gh) {
|
|
250
|
+
export async function checkLog(scope, ref, jobId, github = gh, find = target) {
|
|
196
251
|
validate(ref);
|
|
197
252
|
if (!Number.isSafeInteger(jobId) || jobId < 1)
|
|
198
253
|
throw new Error("Invalid job ID.");
|
|
199
|
-
const pr = await
|
|
254
|
+
const pr = await find(scope, ref, github);
|
|
200
255
|
const job = JSON.parse(await github(scope, ["api", `repos/${pr.repo}/actions/jobs/${jobId}`]));
|
|
201
256
|
if (job.head_sha !== pr.headRefOid)
|
|
202
257
|
throw new Error("This job is not for the current head of the pull request. Reload it before you add its log.");
|
|
@@ -216,3 +271,13 @@ export async function checkLog(scope, ref, jobId, github = gh) {
|
|
|
216
271
|
const start = Math.max(0, end - checkLogLines);
|
|
217
272
|
return { text: lines.slice(start, end).join("\n"), truncated: start > 0 || end < lines.length };
|
|
218
273
|
}
|
|
274
|
+
const reviewEvents = ["APPROVE", "REQUEST_CHANGES", "COMMENT"];
|
|
275
|
+
export async function submitReview(scope, input, github = gh, find = target) {
|
|
276
|
+
validate(input?.pr);
|
|
277
|
+
if (!reviewEvents.includes(input.event) || typeof input.body !== "string")
|
|
278
|
+
throw new Error("Invalid review input.");
|
|
279
|
+
if (input.event !== "APPROVE" && !input.body.trim())
|
|
280
|
+
throw new Error("Enter a comment for this review.");
|
|
281
|
+
const pr = await find(scope, input.pr, github);
|
|
282
|
+
await api(scope, github, "mutation($id:ID!,$event:PullRequestReviewEvent!,$body:String){addPullRequestReview(input:{pullRequestId:$id,event:$event,body:$body}){pullRequestReview{id}}}", { id: pr.id, event: input.event, body: input.body });
|
|
283
|
+
}
|
|
@@ -90,20 +90,26 @@ function checks(rollup) {
|
|
|
90
90
|
return "failing";
|
|
91
91
|
return "pending";
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const data = await api(scope, github, "query($owner:String!,$name:String!,$branch:String!){repository(owner:$owner,name:$name){pullRequests(headRefName:$branch,first:100,orderBy:{field:UPDATED_AT,direction:DESC}){nodes{id number url title baseRefName headRefOid state isDraft reviewDecision updatedAt closedAt headRepository{id} commits(last:1){nodes{commit{statusCheckRollup{state contexts(first:0){checkRunCountsByState{state count} statusContextCountsByState{state count}}}}}} reviewThreads(first:100){nodes{isResolved}}}}}}", { owner: owner, name: name, branch });
|
|
96
|
-
const matches = data.repository.pullRequests.nodes.filter(pr => pr.headRepository?.id === repository.head.id);
|
|
97
|
-
matches.sort((a, b) => Number(b.state === "OPEN") - Number(a.state === "OPEN") || (b.closedAt ?? b.updatedAt).localeCompare(a.closedAt ?? a.updatedAt));
|
|
98
|
-
const pr = matches[0];
|
|
99
|
-
if (!pr)
|
|
100
|
-
return undefined;
|
|
93
|
+
const candidateFields = "id number url title baseRefName headRefOid baseRefOid headRefName state isDraft reviewDecision updatedAt closedAt headRepository{id} commits(last:1){nodes{commit{statusCheckRollup{state contexts(first:0){checkRunCountsByState{state count} statusContextCountsByState{state count}}}}}} reviewThreads(first:100){nodes{isResolved}}";
|
|
94
|
+
function resolved(repo, pr) {
|
|
101
95
|
return {
|
|
102
|
-
repo
|
|
96
|
+
repo, id: pr.id, number: pr.number, url: pr.url, title: pr.title, baseBranch: pr.baseRefName, headRefOid: pr.headRefOid, baseRefOid: pr.baseRefOid, headRefName: pr.headRefName, headRepository: pr.headRepository, state: pr.state, isDraft: pr.isDraft,
|
|
103
97
|
checks: checks(pr.commits.nodes[0]?.commit.statusCheckRollup), checksCompleted: completed(pr.commits.nodes[0]?.commit.statusCheckRollup?.contexts), reviewDecision: pr.reviewDecision,
|
|
104
98
|
unresolvedThreads: pr.reviewThreads.nodes.filter(thread => !thread.isResolved).length, updatedAt: pr.updatedAt,
|
|
105
99
|
};
|
|
106
100
|
}
|
|
101
|
+
export async function resolvePullRequest(scope, repository, branch, github = gh) {
|
|
102
|
+
const [owner, name] = repository.base.repo.split("/");
|
|
103
|
+
const data = await api(scope, github, `query($owner:String!,$name:String!,$branch:String!){repository(owner:$owner,name:$name){pullRequests(headRefName:$branch,first:100,orderBy:{field:UPDATED_AT,direction:DESC}){nodes{${candidateFields}}}}}`, { owner: owner, name: name, branch });
|
|
104
|
+
const matches = data.repository.pullRequests.nodes.filter(pr => pr.headRepository?.id === repository.head.id);
|
|
105
|
+
matches.sort((a, b) => Number(b.state === "OPEN") - Number(a.state === "OPEN") || (b.closedAt ?? b.updatedAt).localeCompare(a.closedAt ?? a.updatedAt));
|
|
106
|
+
return matches[0] && resolved(repository.base.repo, matches[0]);
|
|
107
|
+
}
|
|
108
|
+
export async function pullRequestByNumber(scope, repo, number, github = gh) {
|
|
109
|
+
const [owner, name] = repo.split("/");
|
|
110
|
+
const data = await api(scope, github, `query($owner:String!,$name:String!,$number:Int!){repository(owner:$owner,name:$name){pullRequest(number:$number){${candidateFields}}}}`, { owner: owner, name: name, number });
|
|
111
|
+
return data.repository.pullRequest ? resolved(repo, data.repository.pullRequest) : undefined;
|
|
112
|
+
}
|
|
107
113
|
export const writers = ["ADMIN", "MAINTAIN", "WRITE"];
|
|
108
114
|
export const mergeSettingsFields = "isArchived viewerPermission mergeCommitAllowed squashMergeAllowed rebaseMergeAllowed";
|
|
109
115
|
export function mergeMethods(repository) {
|
package/dist/daemon/runtime.js
CHANGED
|
@@ -11,6 +11,7 @@ import { WorkflowBuilderService } from './workflow-builder.js';
|
|
|
11
11
|
import { workflowCatalogue } from './workflow-routes.js';
|
|
12
12
|
import { WorkflowMcpAuthoringService } from './workflow-mcp-authoring.js';
|
|
13
13
|
import { SessionHost } from './host.js';
|
|
14
|
+
import { includedProjects } from './projects.js';
|
|
14
15
|
import { McpAuth } from './mcp-auth.js';
|
|
15
16
|
import { serve } from './server.js';
|
|
16
17
|
import { ShellRegistry } from './shell.js';
|
|
@@ -50,6 +51,7 @@ export async function startRuntime(options) {
|
|
|
50
51
|
mcpConnections: config.mcpConnections, mcpAuth,
|
|
51
52
|
filesystemIsolationMode: config.filesystemIsolationMode, sandboxSupport: config.sandboxSupport,
|
|
52
53
|
sandboxSharing: config.sandboxSharing, updateSourceBranch: config.updateSourceBranch, projectRoot: config.projectRoot,
|
|
54
|
+
projectPaths: () => includedProjects(config.rawProjectRoot(), config.projectInclude()).map(project => project.path),
|
|
53
55
|
standingAuthorisations: config.standingAuthorisations, allowTool: config.allowTool,
|
|
54
56
|
defaultBackend: config.defaultBackend, defaultModel: config.defaultModel,
|
|
55
57
|
defaultEffort: config.defaultEffort, defaultPermissionMode: config.defaultPermissionMode, autoCompaction: config.autoCompaction, compactionModel: config.compactionModel, summaryModel: config.summaryModel, tourModel: config.tourModel,
|
package/dist/daemon/server.js
CHANGED
|
@@ -551,6 +551,10 @@ ${ICON_LINKS}</head><body><script>window.location.replace(${JSON.stringify(locat
|
|
|
551
551
|
servePresentation(response, options.host, presentationMatch[1], url.searchParams, presentationMatch[2] !== undefined, authentication.kind === "browser" ? options.oidc : undefined, authentication.kind === "browser" ? authentication.sessionId : undefined);
|
|
552
552
|
return;
|
|
553
553
|
}
|
|
554
|
+
if (request.method === "GET" && url.pathname === "/api/attention/events") {
|
|
555
|
+
streamAttention(response, options.host, authentication.kind === "browser" ? options.oidc : undefined, authentication.kind === "browser" ? authentication.sessionId : undefined);
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
554
558
|
const eventsMatch = /^\/api\/sessions\/([^/]+)\/events$/.exec(url.pathname);
|
|
555
559
|
const sessionId = eventsMatch?.[1];
|
|
556
560
|
if (request.method === "GET" && sessionId) {
|
|
@@ -959,6 +963,27 @@ function streamEvents(response, host, sessionId, since, oidc, browserSessionId)
|
|
|
959
963
|
detachAuth?.();
|
|
960
964
|
});
|
|
961
965
|
}
|
|
966
|
+
function streamAttention(response, host, oidc, browserSessionId) {
|
|
967
|
+
response.writeHead(200, {
|
|
968
|
+
"content-type": "text/event-stream",
|
|
969
|
+
"cache-control": "no-store",
|
|
970
|
+
connection: "keep-alive",
|
|
971
|
+
});
|
|
972
|
+
response.flushHeaders();
|
|
973
|
+
const unsubscribe = host.onAttentionRaised((raised) => {
|
|
974
|
+
response.write(`data: ${JSON.stringify(raised)}\n\n`);
|
|
975
|
+
});
|
|
976
|
+
const heartbeat = setInterval(() => response.write(": keepalive\n\n"), 15_000);
|
|
977
|
+
heartbeat.unref();
|
|
978
|
+
const detachAuth = oidc && browserSessionId
|
|
979
|
+
? oidc.registerConnection(browserSessionId, () => response.end())
|
|
980
|
+
: undefined;
|
|
981
|
+
response.on("close", () => {
|
|
982
|
+
clearInterval(heartbeat);
|
|
983
|
+
unsubscribe();
|
|
984
|
+
detachAuth?.();
|
|
985
|
+
});
|
|
986
|
+
}
|
|
962
987
|
/** Bearer access is deliberately independent of OIDC so remote CLI clients keep working. */
|
|
963
988
|
async function authenticateRequest(request, options) {
|
|
964
989
|
if (tokenMatches(options.token, presentedBearer(request)))
|
package/dist/daemon/tour.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { head, run, GIT_READ_TIMEOUT_MS } from "./git.js";
|
|
2
2
|
import { gh } from "./github.js";
|
|
3
|
-
import { changes, changesText } from "./changes.js";
|
|
3
|
+
import { changes, changesText, rangeText } from "./changes.js";
|
|
4
4
|
import { resolveRepository } from "./repository.js";
|
|
5
5
|
export const TOUR_INSTRUCTIONS = [
|
|
6
6
|
"Give an in-depth tour of this branch's committed changes, with the diff shown for each change you discuss.",
|
|
@@ -31,6 +31,12 @@ export async function tourInput(scope, github = gh) {
|
|
|
31
31
|
input: `Branch: ${branch.value.name}\nBase: ${listed.base}\n${await changesText(scope, "branch", undefined, undefined, github)}`,
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
+
export async function pullRequestTourInput(scope, range, pr) {
|
|
35
|
+
const text = await rangeText(scope, range.base, range.head);
|
|
36
|
+
if (!text)
|
|
37
|
+
throw new Error("This pull request has no committed changes to tour.");
|
|
38
|
+
return `Branch: ${pr.headRefName}\nBase: ${pr.baseRefName}\n${text}`;
|
|
39
|
+
}
|
|
34
40
|
export function tourText(raw) {
|
|
35
41
|
try {
|
|
36
42
|
const parsed = JSON.parse(raw);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdirSync } from 'node:fs';
|
|
1
|
+
import { existsSync, mkdirSync, realpathSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { isSea } from 'node:sea';
|
|
@@ -27,7 +27,8 @@ export class WorkflowEnvironment {
|
|
|
27
27
|
mode;
|
|
28
28
|
stateDir;
|
|
29
29
|
readablePaths;
|
|
30
|
-
|
|
30
|
+
scopeReadOnly;
|
|
31
|
+
constructor(host, ownerId, scope, connectionIds, mode, stateDir, readablePaths = [], scopeReadOnly = false) {
|
|
31
32
|
this.host = host;
|
|
32
33
|
this.ownerId = ownerId;
|
|
33
34
|
this.scope = scope;
|
|
@@ -35,6 +36,7 @@ export class WorkflowEnvironment {
|
|
|
35
36
|
this.mode = mode;
|
|
36
37
|
this.stateDir = stateDir;
|
|
37
38
|
this.readablePaths = readablePaths;
|
|
39
|
+
this.scopeReadOnly = scopeReadOnly;
|
|
38
40
|
}
|
|
39
41
|
async prepare(signal) {
|
|
40
42
|
this.lifetime.signal.throwIfAborted();
|
|
@@ -79,7 +81,7 @@ export class WorkflowEnvironment {
|
|
|
79
81
|
if (roots && !roots.slice(0, 3).some(root => this.scope === root || this.scope.startsWith(root + '/')))
|
|
80
82
|
throw new Error('Scope is outside shared Sandbox roots');
|
|
81
83
|
const attachment = shared ? this.host.scheduledSandboxMounts(this.scope) : { writable: [], readable: [] };
|
|
82
|
-
const mounts = sandboxMounts([...(roots ?? [this.scope, this.stateDir]), ...attachment.writable], [packageRoot, ...this.readablePaths, ...nodeExecutionAssets([bundle]), ...attachment.readable]);
|
|
84
|
+
const mounts = sandboxMounts([...(roots ?? (this.scopeReadOnly ? [this.stateDir] : [this.scope, this.stateDir])), ...attachment.writable], [...(this.scopeReadOnly ? [this.scope] : []), packageRoot, ...this.readablePaths, ...nodeExecutionAssets([bundle]), ...attachment.readable]);
|
|
83
85
|
if (shared) {
|
|
84
86
|
const lease = await shared.acquire(support.provider, roots[0], mounts, signal);
|
|
85
87
|
this.sandbox = lease.sandbox;
|
|
@@ -87,7 +89,7 @@ export class WorkflowEnvironment {
|
|
|
87
89
|
}
|
|
88
90
|
else {
|
|
89
91
|
this.ownedProvider = support.provider;
|
|
90
|
-
this.sandbox = await createSandbox(support.provider, { name: `flow-${this.ownerId}`, workspace: this.scope, mounts, env: {} }, join(this.stateDir, 'sandbox.json'), signal);
|
|
92
|
+
this.sandbox = await createSandbox(support.provider, { name: `flow-${this.ownerId}`, workspace: this.scopeReadOnly ? realpathSync(this.stateDir) : this.scope, mounts, env: {} }, join(this.stateDir, 'sandbox.json'), signal);
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
signal.throwIfAborted();
|
|
@@ -168,7 +168,7 @@ export class WorkflowExecutionService {
|
|
|
168
168
|
this.code = {};
|
|
169
169
|
this.ready = (async () => {
|
|
170
170
|
try {
|
|
171
|
-
const executors = await createCodeExecutors({ ...this.filesystemPolicy(), sandbox: (sessionId) => this.host.workflowSandbox(sessionId), isolationMode: options.isolationMode, runtimePath: this.runtimePath, nodePath: options.nodePath ?? '', resolveSecret: async (name, signal) => this.secrets.resolve(name, signal) });
|
|
171
|
+
const executors = await createCodeExecutors({ ...this.filesystemPolicy(), sandbox: (sessionId) => this.host.workflowSandbox(sessionId), readOnly: (sessionId) => this.host.isReadOnly(sessionId), isolationMode: options.isolationMode, runtimePath: this.runtimePath, nodePath: options.nodePath ?? '', resolveSecret: async (name, signal) => this.secrets.resolve(name, signal) });
|
|
172
172
|
if (key !== this.runtimeKey)
|
|
173
173
|
return;
|
|
174
174
|
this.code = executors;
|
|
@@ -307,7 +307,7 @@ export async function prepareFilesystemIsolation(options) {
|
|
|
307
307
|
const privateHome = join(scratch, "home");
|
|
308
308
|
mkdirSync(join(privateHome, ".pi/agent"), { recursive: true, mode: 0o700 });
|
|
309
309
|
mkdirSync(join(privateHome, ".claude"), { mode: 0o700 });
|
|
310
|
-
args.push("--bind-fd", pinned(scope, options.expectedScopeIdentity), scope, "--dir", virtualRoot, "--bind-fd", pinned(privateHome), virtualHome, "--dir", `${virtualRoot}/run`, "--bind-fd", pinned(backend), virtualState);
|
|
310
|
+
args.push(options.scopeReadOnly ? "--ro-bind-fd" : "--bind-fd", pinned(scope, options.expectedScopeIdentity), scope, "--dir", virtualRoot, "--bind-fd", pinned(privateHome), virtualHome, "--dir", `${virtualRoot}/run`, "--bind-fd", pinned(backend), virtualState);
|
|
311
311
|
for (const path of directoryMasks)
|
|
312
312
|
args.push("--remount-ro", path);
|
|
313
313
|
const stage = (source, destination) => {
|
package/dist/protocol/spend.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const SPEND_SOURCES = ["session", "workflow", "naming", "publish", "builder"];
|
|
1
|
+
export const SPEND_SOURCES = ["session", "workflow", "naming", "publish", "tour", "builder"];
|
|
2
2
|
export const SPEND_WINDOWS = ["day", "week", "month", "lifetime"];
|
|
@@ -113,7 +113,8 @@ export async function createCodeExecutors(options) {
|
|
|
113
113
|
CLAUDE_CONFIG_DIR: process.env.CLAUDE_CONFIG_DIR };
|
|
114
114
|
const launch = sandbox?.command(scope, ['/bin/bash', ...args], environment);
|
|
115
115
|
const isolation = isolationEnabled && !sandbox ? await prepareFilesystemIsolation({ scope, expectedScope: resolve(context.scope),
|
|
116
|
-
...stateRoot, command: '/bin/bash', args, env, readablePaths: [nodePath, runtimePath], credentials: 'none'
|
|
116
|
+
...stateRoot, command: '/bin/bash', args, env, readablePaths: [nodePath, runtimePath], credentials: 'none',
|
|
117
|
+
scopeReadOnly: context.sessionId !== undefined && !!options.readOnly?.(context.sessionId) }) : undefined;
|
|
117
118
|
const release = sandbox?.hold();
|
|
118
119
|
try {
|
|
119
120
|
context.signal.throwIfAborted();
|