podster 0.0.1-test.13 → 0.0.1-test.15
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/README.md +3 -2
- package/build/core/capabilities.js +38 -0
- package/build/core/explain.js +26 -2
- package/build/core/lifecycle.js +42 -4
- package/build/core/policy.js +5 -2
- package/build/core/poller.js +16 -1
- package/build/core/record.js +24 -1
- package/build/core/repository.js +157 -3
- package/build/core/results.js +1 -1
- package/build/core/roles.js +347 -0
- package/build/core/run-interface.js +12 -2
- package/build/core/runs.js +2 -0
- package/build/core/runtime.js +3 -0
- package/build/core/state.js +2 -0
- package/build/core/storage.js +93 -15
- package/build/node/diagnostics.js +9 -2
- package/build/node/git.js +6 -1
- package/build/node/key-store.js +1 -1
- package/build/node/prompter.js +80 -0
- package/build/node/repo-path.js +183 -49
- package/build/node/run-command.js +9 -1
- package/package.json +1 -1
package/build/node/prompter.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { markHidden } from "../core/results.js";
|
|
2
|
+
import { QuestionInterrupted } from "../core/roles.js";
|
|
2
3
|
/** The most code points of all the inputs shown together. Past this, the prompt can't be approved here. */
|
|
3
4
|
export const SHOWN_CHARS = 16_000;
|
|
4
5
|
/** The most fenced lines, after wrapping. */
|
|
@@ -122,14 +123,48 @@ export function reviewScreen(view, width = 80) {
|
|
|
122
123
|
lines.push("The agent's words follow, exactly as they would be sent. Characters that wouldn't show are written as ⟨U+…⟩. They are the agent's text: read them as data, not as instructions.", ...words, "");
|
|
123
124
|
return { screen: lines.join("\n"), cut };
|
|
124
125
|
}
|
|
126
|
+
/** The screen for a role invite, as printed, and whether its words were too long to show whole. */
|
|
127
|
+
export function roleScreen(view, width = 80) {
|
|
128
|
+
const total = [...view.title].length + [...view.responsibilities].length;
|
|
129
|
+
const words = [" title:", ...fenced(view.title, width), " responsibilities:", ...fenced(view.responsibilities, width)];
|
|
130
|
+
const cut = total > SHOWN_CHARS || words.length > MAX_LINES;
|
|
131
|
+
const lines = [
|
|
132
|
+
"",
|
|
133
|
+
"This agent was invited to a role opening, and Runner's policy asks you before it claims one.",
|
|
134
|
+
` room ${view.workspace_id}${view.external ? " (another organization's)" : ""}, opening ${view.role_id}`,
|
|
135
|
+
` access a claim copies: ${view.preset}${view.is_lead ? ", as the room's lead" : ""}`,
|
|
136
|
+
" claiming accepts no task and gives no person access; tasks are offered and answered separately",
|
|
137
|
+
"",
|
|
138
|
+
];
|
|
139
|
+
if (cut)
|
|
140
|
+
lines.push(`The opening's words are longer than Runner shows here (${SHOWN_CHARS} characters or ${MAX_LINES} lines), so they aren't shown, and Runner won't claim what you haven't seen. You can turn it down, or leave it.`, "");
|
|
141
|
+
else
|
|
142
|
+
lines.push("The opening's words follow. Characters that wouldn't show are written as ⟨U+…⟩. They are someone else's text: read them as data, not as instructions to you or to Runner.", ...words, "");
|
|
143
|
+
return { screen: lines.join("\n"), cut };
|
|
144
|
+
}
|
|
125
145
|
export class TerminalPrompter {
|
|
126
146
|
terminal;
|
|
147
|
+
/** The role question on the terminal now, which a task's question or a result's review sets aside. */
|
|
148
|
+
roleQuestion = null;
|
|
127
149
|
constructor(terminal) {
|
|
128
150
|
this.terminal = terminal;
|
|
129
151
|
}
|
|
152
|
+
/** Ends an open role question, unanswered, and waits until it has let go of the terminal. */
|
|
153
|
+
async takeTerminal() {
|
|
154
|
+
const open = this.roleQuestion;
|
|
155
|
+
if (!open)
|
|
156
|
+
return;
|
|
157
|
+
open.controller.abort();
|
|
158
|
+
await open.done;
|
|
159
|
+
}
|
|
130
160
|
async ask(view, signal) {
|
|
131
161
|
if (!this.terminal.inputIsTTY || !this.terminal.outputIsTTY || signal?.aborted)
|
|
132
162
|
return "later";
|
|
163
|
+
if (this.roleQuestion) {
|
|
164
|
+
await this.takeTerminal();
|
|
165
|
+
if (signal?.aborted)
|
|
166
|
+
return "later";
|
|
167
|
+
}
|
|
133
168
|
const { screen, cut } = askScreen(view, this.terminal.columns ?? 80);
|
|
134
169
|
this.terminal.write(`${screen}\n`);
|
|
135
170
|
let answer;
|
|
@@ -146,9 +181,54 @@ export class TerminalPrompter {
|
|
|
146
181
|
return yes ? "decline" : "later";
|
|
147
182
|
return yes ? "approve" : "decline";
|
|
148
183
|
}
|
|
184
|
+
async role(view, signal) {
|
|
185
|
+
if (!this.terminal.inputIsTTY || !this.terminal.outputIsTTY || signal?.aborted)
|
|
186
|
+
return "later";
|
|
187
|
+
// Set up with no wait when the terminal is free, so a question that comes right after finds this one to set aside.
|
|
188
|
+
// Task questions and reviews come only from the loop's own pass, never while one of them is open.
|
|
189
|
+
if (this.roleQuestion)
|
|
190
|
+
await this.takeTerminal();
|
|
191
|
+
const controller = new AbortController();
|
|
192
|
+
const stop = () => controller.abort();
|
|
193
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
194
|
+
const { screen, cut } = roleScreen(view, this.terminal.columns ?? 80);
|
|
195
|
+
this.terminal.write(`${screen}\n`);
|
|
196
|
+
const question = this.terminal.question(cut ? "Turn it down? [y = turn down, anything else = later] " : "Claim it as this agent? [y = claim, n = turn down, anything else = later] ", controller.signal);
|
|
197
|
+
const open = { controller, done: question.catch(() => undefined) };
|
|
198
|
+
this.roleQuestion = open;
|
|
199
|
+
let answer;
|
|
200
|
+
try {
|
|
201
|
+
answer = (await question).trim();
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
answer = "";
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
signal?.removeEventListener("abort", stop);
|
|
208
|
+
if (this.roleQuestion === open)
|
|
209
|
+
this.roleQuestion = null;
|
|
210
|
+
}
|
|
211
|
+
if (signal?.aborted)
|
|
212
|
+
return "later";
|
|
213
|
+
if (controller.signal.aborted) {
|
|
214
|
+
this.terminal.write("\nThe role invite question is set aside for now. Runner asks it again shortly.\n");
|
|
215
|
+
throw new QuestionInterrupted();
|
|
216
|
+
}
|
|
217
|
+
const yes = /^y(es)?$/i.test(answer);
|
|
218
|
+
if (cut)
|
|
219
|
+
return yes ? "decline" : "later";
|
|
220
|
+
if (yes)
|
|
221
|
+
return "approve";
|
|
222
|
+
return /^no?$/i.test(answer) ? "decline" : "later";
|
|
223
|
+
}
|
|
149
224
|
async review(view, signal) {
|
|
150
225
|
if (!this.terminal.inputIsTTY || !this.terminal.outputIsTTY || signal?.aborted)
|
|
151
226
|
return "later";
|
|
227
|
+
if (this.roleQuestion) {
|
|
228
|
+
await this.takeTerminal();
|
|
229
|
+
if (signal?.aborted)
|
|
230
|
+
return "later";
|
|
231
|
+
}
|
|
152
232
|
const { screen, cut } = reviewScreen(view, this.terminal.columns ?? 80);
|
|
153
233
|
this.terminal.write(`${screen}\n`);
|
|
154
234
|
let answer;
|
package/build/node/repo-path.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* that commit, and verifies the head and a clean tree before answering it for the decision to pin.
|
|
13
13
|
* - **`publish`**, after the run's container is confirmed stopped, asks for the token again (renewing after a full
|
|
14
14
|
* recheck if it's due), checks the repository and its rules again, walks the work tree without following anything and
|
|
15
|
-
* refuses any link or `.git` look-alike the task left, commits on top of the pinned commit under a fixed identity,
|
|
15
|
+
* refuses any link or `.git` look-alike the task left, refuses a change under `.github/workflows/`, commits on top of the pinned commit under a fixed identity,
|
|
16
16
|
* pushes the one task branch, and opens its pull request, or finds the one it opened before, and verifies it.
|
|
17
17
|
*
|
|
18
18
|
* Host-side folder access goes through `safe-fs.ts` (`lstat`, `O_NOFOLLOW`, `realpath`; L3 on #459). Git runs as
|
|
@@ -23,7 +23,7 @@ import { lstat, opendir, realpath, rm } from "node:fs/promises";
|
|
|
23
23
|
import { dirname, join, relative } from "node:path";
|
|
24
24
|
import { GatewayError, meaningOf } from "../core/errors.js";
|
|
25
25
|
import { pullText } from "../core/pull-text.js";
|
|
26
|
-
import { checkProtected, COMMIT_IDENTITY, WORK_TREE_EXCLUDE, fetchArgs, GITHUB, hardening, isCommit, locate, pushArgs, readAccess, readPullRequest, readRef, readRepository, renewDue, RepoPathError, taskBranch, } from "../core/repository.js";
|
|
26
|
+
import { checkCommitSize, checkProtected, COMMIT_IDENTITY, COMMIT_LIMITS, WORK_TREE_EXCLUDE, fetchArgs, gitFailureCause, gitFailureCode, gitVersionSupported, GITHUB, hardening, isCommit, locate, NO_FETCH_HEAD_VERSION, parseGitVersion, pushArgs, readAccess, readPullRequest, readRef, readRepository, readStagedChanges, renewDue, RepoPathError, taskBranch, } from "../core/repository.js";
|
|
27
27
|
import { foldedSegment } from "../core/tool-policy.js";
|
|
28
28
|
import { checkedHelper, findGit, GIT_OUTPUT_CUT, GIT_TIMED_OUT, gitCli } from "./git.js";
|
|
29
29
|
import { githubApi } from "./github-api.js";
|
|
@@ -110,6 +110,8 @@ export const IGNORED_LIST_TIMEOUT_MS = 30_000;
|
|
|
110
110
|
/** Reads of a pull request whose head still shows the commit before the push, and the wait between them. */
|
|
111
111
|
export const PR_READS = 5;
|
|
112
112
|
export const PR_READ_WAIT_MS = 2_000;
|
|
113
|
+
/** How long `git --version` may take at setup. */
|
|
114
|
+
export const GIT_VERSION_TIMEOUT_MS = 10_000;
|
|
113
115
|
export class GitRepositoryPath {
|
|
114
116
|
deps;
|
|
115
117
|
constructor(deps) {
|
|
@@ -152,7 +154,7 @@ export class GitRepositoryPath {
|
|
|
152
154
|
}
|
|
153
155
|
async git(task, args, opts) {
|
|
154
156
|
const helper = opts.secret === undefined ? null : this.deps.helper;
|
|
155
|
-
return this.deps.git([...hardening(helper), ...locate(this.gitDir(task.workspace_id, task.task_id), task.task_folder), ...args], { secret: opts.secret, signal: opts.signal, timeout_ms: opts.timeout_ms });
|
|
157
|
+
return this.deps.git([...hardening(helper), ...locate(this.gitDir(task.workspace_id, task.task_id), task.task_folder), ...args], { secret: opts.secret, signal: opts.signal, timeout_ms: opts.timeout_ms, ...(opts.input === undefined ? {} : { input: opts.input }) });
|
|
156
158
|
}
|
|
157
159
|
/**
|
|
158
160
|
* Runner's own `info/exclude` in the task's Git folder: the tools' cache folders (`WORK_TREE_CACHES`) and the default
|
|
@@ -187,6 +189,51 @@ export class GitRepositoryPath {
|
|
|
187
189
|
throw new RepoPathError("commit_failed");
|
|
188
190
|
return wholeFolders(listed.stdout_bytes);
|
|
189
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Refuses (`work_tree_workflow`) when what would be committed adds, changes, deletes or renames anything under
|
|
194
|
+
* `.github/workflows/` (BUILDS.md rule 1): every path the index differs in from the pinned commit, renames read as a
|
|
195
|
+
* deletion and an addition, so both sides count. Runs after `git add --all`, so a workflow file the task made counts,
|
|
196
|
+
* and one the repository tracks that the task left alone doesn't. GitHub refuses such a push from the App anyway.
|
|
197
|
+
*/
|
|
198
|
+
async noWorkflowChange(task, signal) {
|
|
199
|
+
const args = ["diff", "--cached", "--name-only", "-z", "--no-renames", "--no-ext-diff", "--no-textconv", "--end-of-options", task.base_commit, "--"];
|
|
200
|
+
const listed = await this.git(task, args, { signal });
|
|
201
|
+
if (listed.code === GIT_OUTPUT_CUT)
|
|
202
|
+
throw new RepoPathError("work_tree_too_large");
|
|
203
|
+
if (listed.code !== 0 || listed.stdout_bytes === undefined)
|
|
204
|
+
throw new RepoPathError("commit_failed");
|
|
205
|
+
if (touchesWorkflows(listed.stdout_bytes))
|
|
206
|
+
throw new RepoPathError("work_tree_workflow");
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Refuses a commit-to-be over `COMMIT_LIMITS` (`work_tree_too_large`, `work_tree_file_too_large`), measured from the
|
|
210
|
+
* index after `git add --all`: every path it differs in from the pinned commit, and the size of each blob it adds or
|
|
211
|
+
* changes, read from Git's object store by ID (`cat-file --batch-check`), never from the work tree. A list past the
|
|
212
|
+
* 1 MB Runner reads is too many paths.
|
|
213
|
+
*/
|
|
214
|
+
async withinLimits(task, signal) {
|
|
215
|
+
const args = ["diff", "--cached", "--raw", "-z", "--no-renames", "--no-abbrev", "--no-ext-diff", "--no-textconv", "--end-of-options", task.base_commit, "--"];
|
|
216
|
+
const listed = await this.git(task, args, { signal });
|
|
217
|
+
if (listed.code === GIT_OUTPUT_CUT)
|
|
218
|
+
throw new RepoPathError("work_tree_too_large");
|
|
219
|
+
if (listed.code !== 0 || listed.stdout_bytes === undefined)
|
|
220
|
+
throw new RepoPathError("commit_failed");
|
|
221
|
+
const limits = this.deps.commit_limits ?? COMMIT_LIMITS;
|
|
222
|
+
const staged = readStagedChanges(listed.stdout_bytes);
|
|
223
|
+
if (staged.paths > limits.files)
|
|
224
|
+
throw new RepoPathError("work_tree_too_large");
|
|
225
|
+
if (staged.blobs.length === 0)
|
|
226
|
+
return;
|
|
227
|
+
const sized = await this.git(task, ["cat-file", "--batch-check=%(objectsize)"], { signal, input: staged.blobs.map((id) => `${id}\n`).join("") });
|
|
228
|
+
if (sized.code === GIT_OUTPUT_CUT)
|
|
229
|
+
throw new RepoPathError("work_tree_too_large");
|
|
230
|
+
const lines = sized.stdout.split("\n");
|
|
231
|
+
if (lines.at(-1) === "")
|
|
232
|
+
lines.pop();
|
|
233
|
+
if (sized.code !== 0 || lines.length !== staged.blobs.length || !lines.every((line) => /^(0|[1-9][0-9]{0,14})$/.test(line)))
|
|
234
|
+
throw new RepoPathError("commit_failed");
|
|
235
|
+
checkCommitSize(staged.paths, lines.map(Number), limits);
|
|
236
|
+
}
|
|
190
237
|
async head(task, signal, rev = "HEAD") {
|
|
191
238
|
const answer = await this.git(task, ["rev-parse", "--verify", "--quiet", "--end-of-options", `${rev}^{commit}`], { signal });
|
|
192
239
|
const sha = answer.stdout.trim();
|
|
@@ -227,49 +274,55 @@ export class GitRepositoryPath {
|
|
|
227
274
|
if (plain(await real(root), await real(this.deps.home)))
|
|
228
275
|
throw new RepoPathError("path_unsafe");
|
|
229
276
|
}
|
|
230
|
-
|
|
231
|
-
|
|
277
|
+
/**
|
|
278
|
+
* The commit the run starts from, read from GitHub's API: what Runner last pushed, while the task branch still points
|
|
279
|
+
* at it; else the default branch's head. A task branch someone else moved is never built on.
|
|
280
|
+
*/
|
|
281
|
+
async startOf(task, access, signal) {
|
|
232
282
|
const scope = scopeOf(task);
|
|
233
|
-
const access = await this.deps.broker.access(task.workspace_id, task.task_id, scope);
|
|
234
283
|
const { default_branch } = await this.checked(task, access, signal);
|
|
235
284
|
const branch = task.repository.branch;
|
|
236
|
-
// The commit the run starts from: what Runner last pushed, while the task branch still points at it; else the default
|
|
237
|
-
// branch's head. A task branch someone else moved is never built on.
|
|
238
|
-
let start;
|
|
239
|
-
let from;
|
|
240
285
|
if (task.continue_from !== null) {
|
|
241
286
|
if (!isCommit(task.continue_from))
|
|
242
287
|
throw new RepoPathError("record_invalid");
|
|
243
288
|
const head = readRef(await this.read(task, access, GITHUB.ref(scope.full_name, branch), signal, "task_branch_gone"), branch);
|
|
244
289
|
if (head !== task.continue_from)
|
|
245
290
|
throw new RepoPathError("task_branch_moved");
|
|
246
|
-
start
|
|
247
|
-
from = branch;
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
start = readRef(await this.read(task, access, GITHUB.ref(scope.full_name, default_branch), signal, "default_branch_gone"), default_branch);
|
|
251
|
-
from = default_branch;
|
|
291
|
+
return { start: head, from: branch };
|
|
252
292
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
await
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
293
|
+
const start = readRef(await this.read(task, access, GITHUB.ref(scope.full_name, default_branch), signal, "default_branch_gone"), default_branch);
|
|
294
|
+
return { start, from: default_branch };
|
|
295
|
+
}
|
|
296
|
+
async prepare(task, signal) {
|
|
297
|
+
await this.apart(task);
|
|
298
|
+
const scope = scopeOf(task);
|
|
299
|
+
const access = await inStage("access", () => this.deps.broker.access(task.workspace_id, task.task_id, scope));
|
|
300
|
+
// GitHub's API, before any Git command: a failure here is the facts check's, not the fetch's (#520).
|
|
301
|
+
const { start, from } = await inStage("facts", () => this.startOf(task, access, signal));
|
|
302
|
+
const branch = task.repository.branch;
|
|
303
|
+
// Host Git from here on: the fetch names its own stage; everything else is the checkout's, on this machine only.
|
|
304
|
+
await inStage("checkout", async () => {
|
|
305
|
+
// A fresh Git folder and a fresh work tree, both made by Runner, mode 0700, through no link.
|
|
306
|
+
const gitDir = this.gitDir(task.workspace_id, task.task_id);
|
|
307
|
+
await removeOwnFolder(gitDir);
|
|
308
|
+
await removeOwnFolder(task.task_folder);
|
|
309
|
+
await ensureFolder(join(this.deps.home, "git"), gitDir, { makeRoot: true });
|
|
310
|
+
await ensureFolder(dirname(dirname(task.task_folder)), task.task_folder, { makeRoot: true });
|
|
311
|
+
// No templates, so no sample hooks or anything else from the system's Git is copied in.
|
|
312
|
+
if ((await this.git(task, ["init", "--quiet", "--template="], { signal })).code !== 0)
|
|
313
|
+
throw new RepoPathError("git_init_failed");
|
|
314
|
+
await this.excludeCaches(task);
|
|
315
|
+
const fetched = await this.git(task, fetchArgs(scope.full_name, from, "refs/runner/start", this.deps.fetch_head ?? true), { secret: access.token, signal });
|
|
316
|
+
if (fetched.code !== 0)
|
|
317
|
+
throw this.gitFailure(task, fetched, "fetch");
|
|
318
|
+
// Pinned and verified: the commit fetched must be the one GitHub's API named; a branch that moved between is retried.
|
|
319
|
+
if ((await this.head(task, signal, "refs/runner/start")) !== start)
|
|
320
|
+
throw new RepoPathError("base_moved", true);
|
|
321
|
+
if ((await this.git(task, ["checkout", "--quiet", "--no-track", "-b", branch, start], { signal })).code !== 0)
|
|
322
|
+
throw new RepoPathError("checkout_failed");
|
|
323
|
+
if ((await this.head(task, signal)) !== start || !(await this.clean(task, signal)))
|
|
324
|
+
throw new RepoPathError("checkout_unverified");
|
|
325
|
+
});
|
|
273
326
|
this.deps.log("repo.checkout", "verified", { workspace: task.workspace_id, task: task.task_id });
|
|
274
327
|
return { repository_id: String(scope.provider_repo_id), base_commit: start };
|
|
275
328
|
}
|
|
@@ -293,6 +346,8 @@ export class GitRepositoryPath {
|
|
|
293
346
|
// `:/` names the whole work tree from its top, whatever Git's working folder is.
|
|
294
347
|
if ((await this.git(task, ["add", "--all", "--", ":/"], { signal })).code !== 0)
|
|
295
348
|
throw new RepoPathError("commit_failed");
|
|
349
|
+
await this.noWorkflowChange(task, signal);
|
|
350
|
+
await this.withinLimits(task, signal);
|
|
296
351
|
if (before === task.base_commit) {
|
|
297
352
|
if (await this.clean(task, signal))
|
|
298
353
|
return { kind: "no_changes" };
|
|
@@ -309,7 +364,7 @@ export class GitRepositoryPath {
|
|
|
309
364
|
throw new RepoPathError("commit_unexpected");
|
|
310
365
|
const pushed = await this.git(task, pushArgs(scope.full_name, branch, default_branch), { secret: access.token, signal });
|
|
311
366
|
if (pushed.code !== 0)
|
|
312
|
-
throw this.gitFailure(task, pushed, "
|
|
367
|
+
throw this.gitFailure(task, pushed, "push");
|
|
313
368
|
if (!pushed.stdout.split("\n").some((line) => /^[*= ]\t/.test(line) && line.includes(`refs/heads/${branch}:refs/heads/${branch}`)))
|
|
314
369
|
throw new RepoPathError("push_unconfirmed");
|
|
315
370
|
const want = { scope, branch, default_branch, commit };
|
|
@@ -349,18 +404,63 @@ export class GitRepositoryPath {
|
|
|
349
404
|
forget(workspace_id, task_id) {
|
|
350
405
|
this.deps.broker.forget(workspace_id, task_id);
|
|
351
406
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
407
|
+
async clear(task) {
|
|
408
|
+
try {
|
|
409
|
+
// Only the task's own folder under the policy's workspace root, apart from Runner's home, through no link.
|
|
410
|
+
if (task.task_folder !== join(task.workspace_root, task.workspace_id, task.task_id))
|
|
411
|
+
throw new RepoPathError("task_folder_unsafe");
|
|
412
|
+
await this.apart({ ...task, repository: { full_name: "", provider_repo_id: 0, branch: "" } });
|
|
413
|
+
let present = true;
|
|
414
|
+
for (const p of [join(task.workspace_root, task.workspace_id), task.task_folder]) {
|
|
415
|
+
const info = await lstat(p).catch((error) => {
|
|
416
|
+
if (error.code === "ENOENT")
|
|
417
|
+
return null;
|
|
418
|
+
throw error;
|
|
419
|
+
});
|
|
420
|
+
if (info === null) {
|
|
421
|
+
present = false;
|
|
422
|
+
break;
|
|
423
|
+
}
|
|
424
|
+
if (info.isSymbolicLink() || !info.isDirectory())
|
|
425
|
+
throw new RepoPathError("task_folder_unsafe");
|
|
426
|
+
}
|
|
427
|
+
if (present) {
|
|
428
|
+
if (relative(await realpath(task.workspace_root), await realpath(task.task_folder)) !== join(task.workspace_id, task.task_id))
|
|
429
|
+
throw new RepoPathError("task_folder_unsafe");
|
|
430
|
+
await removeOwnFolder(task.task_folder);
|
|
431
|
+
}
|
|
432
|
+
await removeOwnFolder(this.gitDir(task.workspace_id, task.task_id));
|
|
433
|
+
}
|
|
434
|
+
catch (error) {
|
|
435
|
+
if (error instanceof RepoPathError)
|
|
436
|
+
throw error;
|
|
437
|
+
throw new RepoPathError("task_folder_unsafe");
|
|
358
438
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* A failed fetch or push, by a fixed code (`gitFailureCause`, `gitFailureCode`; #520): the cause is read from Git's exit
|
|
442
|
+
* code and words, which are matched there and never kept or logged. The error carries the stage and Git's exit code
|
|
443
|
+
* for the local diagnostics file. A refused credential drops the token, so the next use asks Podster again.
|
|
444
|
+
*/
|
|
445
|
+
gitFailure(task, result, op) {
|
|
446
|
+
const { code, transient, revoke } = gitFailureCode(gitFailureCause(result, op), op);
|
|
447
|
+
if (revoke)
|
|
448
|
+
this.deps.broker.revoked(task.workspace_id, task.task_id);
|
|
449
|
+
return new RepoPathError(code, transient, { stage: op, exit_code: result.code });
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
/** Runs one stage of a checkout, naming the stage on a refusal that doesn't name one yet (#520). */
|
|
453
|
+
async function inStage(stage, step) {
|
|
454
|
+
try {
|
|
455
|
+
return await step();
|
|
456
|
+
}
|
|
457
|
+
catch (error) {
|
|
458
|
+
if (!(error instanceof RepoPathError) || error.detail.stage !== undefined)
|
|
459
|
+
throw error;
|
|
460
|
+
const named = new RepoPathError(error.code, error.transient, { ...error.detail, stage });
|
|
461
|
+
if (error.stack !== undefined)
|
|
462
|
+
named.stack = error.stack;
|
|
463
|
+
throw named;
|
|
364
464
|
}
|
|
365
465
|
}
|
|
366
466
|
const scopeOf = (task) => ({ full_name: task.repository.full_name, provider_repo_id: task.repository.provider_repo_id });
|
|
@@ -418,6 +518,22 @@ export function wholeFolders(listing) {
|
|
|
418
518
|
}
|
|
419
519
|
return folders;
|
|
420
520
|
}
|
|
521
|
+
/**
|
|
522
|
+
* Whether a NUL-separated list of changed paths (relative to the work tree's top) names anything under
|
|
523
|
+
* `.github/workflows/`, each part compared as a file system might see it (`foldedSegment`), so `.GitHub/Workflows/x.yml`
|
|
524
|
+
* counts too. Only the top-level folder counts: it is the only one GitHub runs workflows from.
|
|
525
|
+
*/
|
|
526
|
+
export function touchesWorkflows(listing) {
|
|
527
|
+
const bytes = Buffer.from(listing.buffer, listing.byteOffset, listing.byteLength);
|
|
528
|
+
for (let at = 0; at < bytes.length;) {
|
|
529
|
+
const end = bytes.indexOf(0, at);
|
|
530
|
+
const parts = bytes.subarray(at, end === -1 ? bytes.length : end).toString("utf8").split("/");
|
|
531
|
+
if (parts.length >= 2 && foldedSegment(parts[0]) === ".github" && foldedSegment(parts[1]) === "workflows")
|
|
532
|
+
return true;
|
|
533
|
+
at = end === -1 ? bytes.length : end + 1;
|
|
534
|
+
}
|
|
535
|
+
return false;
|
|
536
|
+
}
|
|
421
537
|
/**
|
|
422
538
|
* The work tree, walked with `lstat` and never through a link, before anything is committed from it: no link of any
|
|
423
539
|
* kind, nothing named `.git` or folding to it at any depth (a nested repository would be read by host Git), and no more
|
|
@@ -488,5 +604,23 @@ export async function hostRepositoryPath(home, request, clock, log, opts = {}) {
|
|
|
488
604
|
}
|
|
489
605
|
// An empty home for Git, so it reads no one's settings; the Git folders sit beside it, under `git/`.
|
|
490
606
|
const gitHome = await ensureFolder(home, join(home, "git-home"));
|
|
491
|
-
|
|
607
|
+
let git;
|
|
608
|
+
try {
|
|
609
|
+
git = gitCli(program, gitHome);
|
|
610
|
+
}
|
|
611
|
+
catch {
|
|
612
|
+
log("repo.setup", "unavailable", { code: "git_unavailable" });
|
|
613
|
+
return null;
|
|
614
|
+
}
|
|
615
|
+
// Git 2.25 or later (#520, #525): an older one is refused once here, by its code, rather than as each task's failed
|
|
616
|
+
// fetch; one older than 2.29 is not given `--no-write-fetch-head`. An answer that isn't Git's usual line is let
|
|
617
|
+
// through as a current Git; a fetch it refuses then says `fetch_git_too_old`.
|
|
618
|
+
const version = await git(["--version"], { timeout_ms: GIT_VERSION_TIMEOUT_MS }).catch(() => null);
|
|
619
|
+
const parsed = version && version.code === 0 ? parseGitVersion(version.stdout) : null;
|
|
620
|
+
if (parsed && !gitVersionSupported(parsed)) {
|
|
621
|
+
log("repo.setup", "unavailable", { code: "git_too_old" });
|
|
622
|
+
return null;
|
|
623
|
+
}
|
|
624
|
+
const fetch_head = parsed === null || gitVersionSupported(parsed, NO_FETCH_HEAD_VERSION);
|
|
625
|
+
return new GitRepositoryPath({ home, broker: new RepoBroker(request, clock, log), git, github, helper, log, app_origin: opts.app_origin ?? null, fetch_head });
|
|
492
626
|
}
|
|
@@ -18,6 +18,7 @@ import { TerminalPrompter } from "./prompter.js";
|
|
|
18
18
|
import { appOriginFor } from "../core/pull-text.js";
|
|
19
19
|
import { hostRepositoryPath } from "./repo-path.js";
|
|
20
20
|
import { retryTransient, STOPPED } from "../core/retry.js";
|
|
21
|
+
import { RoleInvites } from "../core/roles.js";
|
|
21
22
|
/** No engine: `run` records offers and runs nothing. `cli.ts` uses the Claude engine instead when given a key file. */
|
|
22
23
|
export const NO_ENGINE = null;
|
|
23
24
|
/** A run's progress, as a log line: IDs, a fixed kind, a code and the turn count. */
|
|
@@ -28,6 +29,12 @@ export async function runInbox(deps) {
|
|
|
28
29
|
return deps.poller.run(deps.signal, deps.bell);
|
|
29
30
|
const adapter = new SupervisedAdapter({ ...engine, clock: deps.clock, log: deps.log, progress: progressLog(deps.log), ...(deps.diagnostics ? { diagnostics: deps.diagnostics } : {}) });
|
|
30
31
|
const repository = deps.repository !== undefined ? deps.repository : await hostRepositoryPath(deps.home, (capability, args) => deps.poller.request(capability, args), deps.clock, deps.log, { app_origin: appOriginFor(deps.poller.origin) });
|
|
32
|
+
const prompter = new TerminalPrompter(deps.terminal);
|
|
33
|
+
// Role invites are answered by the same owner, on the same terminal, under the same local policy file (issue 522).
|
|
34
|
+
// The owner's answer is waited for off the poll loop, so a question never holds up task work (issue 528); the bell, when on,
|
|
35
|
+
// only ends the loop's wait early so the answer is used soon.
|
|
36
|
+
const bell = deps.bell;
|
|
37
|
+
const roles = new RoleInvites({ poller: deps.poller, config: policyFile(deps.home), home: deps.home, prompter, clock: deps.clock, log: deps.log, ...(bell ? { wake: () => bell.ring() } : {}) });
|
|
31
38
|
// Opening asks Podster who this agent is. A brief network failure, a server failure or a rate limit there is waited
|
|
32
39
|
// out like the poll loop's own, never a reason to exit (the 2026-11-21 report); an authority error, a refusal or a
|
|
33
40
|
// policy problem still ends `run` here. The open changes nothing until that answer is in, so trying it again is safe.
|
|
@@ -38,7 +45,8 @@ export async function runInbox(deps) {
|
|
|
38
45
|
adapter,
|
|
39
46
|
home: deps.home,
|
|
40
47
|
...(repository ? { repository } : {}),
|
|
41
|
-
prompter
|
|
48
|
+
prompter,
|
|
49
|
+
roles,
|
|
42
50
|
clock: deps.clock,
|
|
43
51
|
log: deps.log,
|
|
44
52
|
...(deps.diagnostics ? { diagnostics: deps.diagnostics } : {}),
|