podster 0.0.1-test.6 → 0.0.1-test.8

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.
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Runner's local diagnostics file (the owner's request of 2026-11-20): `logs/errors.jsonl` in Runner's home, one JSON
3
+ * line per failure, keyed by time and the run's IDs, with the raw error's message and stack and, for a Docker command,
4
+ * its exit code and the tail of its error output. It is for the machine's owner only:
5
+ *
6
+ * - **Local only.** Nothing reads it but `podster why`; it is never sent to Podster or any network.
7
+ * - **Scrubbed and bounded.** Every text has the exact secret values Runner holds (`known-secrets.ts`: the run's broker
8
+ * token, a task's GitHub token) redacted, then Runner's secret patterns (`redactSecrets`), and each field is cut to
9
+ * `MAX_FIELD_BYTES`, 4 KiB (the error output keeps its tail). Error output Docker cut at its own cap has its last word,
10
+ * which may be the start of a secret, redacted too.
11
+ * - **Private.** The folder is mode 0700, owned by this user and not a link; the file is 0600 (set before the first
12
+ * write to one that exists), owned by this user, with one link, opened without following a link. Reads check the same.
13
+ * - **Rotated.** Past `MAX_FILE_BYTES` the file moves to `errors.jsonl.1` (and that to `.2`), so at most three are kept.
14
+ *
15
+ * A write that fails is dropped: diagnostics never stop Runner.
16
+ */
17
+ import { chmodSync, closeSync, constants, existsSync, fchmodSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeSync } from "node:fs";
18
+ import { join } from "node:path";
19
+ import { DetailedError } from "../core/errors.js";
20
+ import { RepoPathError } from "../core/repository.js";
21
+ import { explain } from "../core/explain.js";
22
+ import { redactKnown } from "../core/known-secrets.js";
23
+ import { markHidden, redactSecrets } from "../core/results.js";
24
+ import { ownFileSync, ownFolderSync } from "./safe-fs.js";
25
+ export const MAX_FILE_BYTES = 1024 * 1024;
26
+ export const KEPT_FILES = 3;
27
+ export const MAX_FIELD_BYTES = 4096;
28
+ const ID = /^[A-Za-z0-9_-]{1,128}$/;
29
+ const CODE = /^[a-z][a-z0-9_.]{0,63}$/;
30
+ /** Text redacted, then cut to `max` UTF-8 bytes: its head, or its tail for an error output. */
31
+ export function scrub(text, max = MAX_FIELD_BYTES, keep = "head") {
32
+ const clean = redactSecrets(redactKnown(text).text).text;
33
+ const bytes = Buffer.from(clean, "utf8");
34
+ if (bytes.byteLength <= max)
35
+ return clean;
36
+ const cut = keep === "head" ? bytes.subarray(0, max) : bytes.subarray(bytes.byteLength - max);
37
+ // A cut inside a character drops it rather than writing half of one.
38
+ return (keep === "head" ? "" : "[cut]") + cut.toString("utf8").replace(/�/g, "") + (keep === "head" ? "[cut]" : "");
39
+ }
40
+ /**
41
+ * Output cut at a head cap: its last word, if the cut went through one, is replaced, since it may be the start of a
42
+ * secret too short for any pattern to match (`ghs_`, `sk-ant-`, part of a hex token).
43
+ */
44
+ export function cutEdge(text) {
45
+ return text.replace(/[^\s"'`<>()[\]{},;]+$/u, "[cut: partial word redacted]");
46
+ }
47
+ /** The line written for a failure. */
48
+ export function diagnosticLine(failure, now) {
49
+ const line = { time: new Date(now).toISOString(), at: CODE.test(failure.at) ? failure.at : "runner", code: /^[a-z][a-z0-9_]{0,63}$/.test(failure.code) ? failure.code : "unknown" };
50
+ if (failure.workspace && ID.test(failure.workspace))
51
+ line.workspace = failure.workspace;
52
+ if (failure.task && ID.test(failure.task))
53
+ line.task = failure.task;
54
+ if (failure.run_ref && ID.test(failure.run_ref))
55
+ line.run_ref = failure.run_ref;
56
+ const error = failure.error;
57
+ if (error instanceof Error) {
58
+ line.message = scrub(error.message);
59
+ if (typeof error.stack === "string")
60
+ line.stack = scrub(error.stack);
61
+ if (error instanceof DetailedError) {
62
+ if (typeof error.detail.exit_code === "number" && Number.isSafeInteger(error.detail.exit_code))
63
+ line.exit_code = error.detail.exit_code;
64
+ if (typeof error.detail.stderr === "string")
65
+ line.stderr_tail = scrub(error.detail.cut ? cutEdge(error.detail.stderr) : error.detail.stderr, MAX_FIELD_BYTES, "tail");
66
+ if (typeof error.detail.errno === "string")
67
+ line.errno = scrub(error.detail.errno, 64);
68
+ }
69
+ if (error instanceof RepoPathError)
70
+ line.transient = error.transient ? 1 : 0;
71
+ }
72
+ else if (error !== undefined) {
73
+ line.message = scrub(String(error));
74
+ }
75
+ return JSON.stringify(line);
76
+ }
77
+ export class FileDiagnostics {
78
+ folder;
79
+ file;
80
+ now;
81
+ constructor(home, now = () => Date.now()) {
82
+ this.folder = join(home, "logs");
83
+ this.file = join(this.folder, "errors.jsonl");
84
+ this.now = now;
85
+ }
86
+ record(failure) {
87
+ try {
88
+ this.write(`${diagnosticLine(failure, this.now())}\n`);
89
+ }
90
+ catch {
91
+ // Diagnostics never stop Runner.
92
+ }
93
+ }
94
+ write(line) {
95
+ if (!existsSync(this.folder))
96
+ mkdirSync(this.folder, { mode: 0o700 });
97
+ // Checked first, so nothing is ever changed through a link: a real folder, the owner's, writable by no one else.
98
+ ownFolderSync(this.folder);
99
+ chmodSync(this.folder, 0o700);
100
+ let size;
101
+ const fd = openSync(this.file, constants.O_WRONLY | constants.O_CREAT | constants.O_APPEND | constants.O_NOFOLLOW, 0o600);
102
+ try {
103
+ size = ownFileSync(fd).size;
104
+ }
105
+ finally {
106
+ closeSync(fd);
107
+ }
108
+ if (size > 0 && size + Buffer.byteLength(line) > MAX_FILE_BYTES)
109
+ this.rotate();
110
+ const out = openSync(this.file, constants.O_WRONLY | constants.O_CREAT | constants.O_APPEND | constants.O_NOFOLLOW, 0o600);
111
+ try {
112
+ ownFileSync(out);
113
+ // Private before anything is written, whatever mode a file that was there had.
114
+ fchmodSync(out, 0o600);
115
+ writeSync(out, line);
116
+ }
117
+ finally {
118
+ closeSync(out);
119
+ }
120
+ }
121
+ rotate() {
122
+ const oldest = `${this.file}.${KEPT_FILES - 1}`;
123
+ if (existsSync(oldest))
124
+ rmSync(oldest);
125
+ for (let n = KEPT_FILES - 2; n >= 1; n--)
126
+ if (existsSync(`${this.file}.${n}`))
127
+ renameSync(`${this.file}.${n}`, `${this.file}.${n + 1}`);
128
+ renameSync(this.file, `${this.file}.1`);
129
+ }
130
+ /** The newest failure recorded for a task, as written, or null. Reads this machine's files only. */
131
+ lastFor(task) {
132
+ if (!ID.test(task))
133
+ return null;
134
+ try {
135
+ ownFolderSync(this.folder);
136
+ }
137
+ catch {
138
+ return null;
139
+ }
140
+ for (const path of [this.file, ...Array.from({ length: KEPT_FILES - 1 }, (_, i) => `${this.file}.${i + 1}`)]) {
141
+ let text;
142
+ try {
143
+ const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
144
+ try {
145
+ ownFileSync(fd);
146
+ text = readFileSync(fd, "utf8");
147
+ }
148
+ finally {
149
+ closeSync(fd);
150
+ }
151
+ }
152
+ catch {
153
+ continue;
154
+ }
155
+ const lines = text.split("\n").filter((l) => l !== "");
156
+ for (let i = lines.length - 1; i >= 0; i--) {
157
+ try {
158
+ const entry = JSON.parse(lines[i]);
159
+ if (entry.task === task)
160
+ return entry;
161
+ }
162
+ catch {
163
+ // A torn line is skipped.
164
+ }
165
+ }
166
+ }
167
+ return null;
168
+ }
169
+ }
170
+ const TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
171
+ const AT = /^[a-z][a-z0-9_.]{0,63}$/;
172
+ const FAILURE_CODE = /^[a-z][a-z0-9_]{0,63}$/;
173
+ /** A field read back from the file, shown only when it has its fixed shape. */
174
+ const shaped = (v, re) => (typeof v === "string" && re.test(v) ? v : "invalid");
175
+ /**
176
+ * `podster why`'s lines for a task's newest failure: its time, place and code, each shown only in its fixed shape, the
177
+ * table's explanation, and the entry itself with every control, format and bidi character written as a visible mark, so
178
+ * nothing in the file can rewrite the terminal.
179
+ */
180
+ export function whyLines(task, entry, file) {
181
+ if (!entry)
182
+ return [`No failure is recorded for ${task} in ${file}.`];
183
+ const code = shaped(entry.code, FAILURE_CODE);
184
+ const e = explain(code);
185
+ return [
186
+ `${shaped(entry.time, TIME)} at ${shaped(entry.at, AT)}: ${e.what} ${e.todo} (code ${code})`,
187
+ `From ${file}, local to this machine and redacted:`,
188
+ markHidden(JSON.stringify(entry, null, 2)),
189
+ ];
190
+ }
191
+ /** `podster why <task>`: prints the lines and answers the exit code. A task that isn't an ID is refused. */
192
+ export function whyCommand(home, task, say) {
193
+ if (!task || !ID.test(task)) {
194
+ say("Name a task: `why <tsk_…>`.");
195
+ return 2;
196
+ }
197
+ const diagnostics = new FileDiagnostics(home);
198
+ for (const line of whyLines(task, diagnostics.lastFor(task), diagnostics.file))
199
+ say(line);
200
+ return 0;
201
+ }
@@ -31,6 +31,7 @@
31
31
  * The `docker` program is a seam (`DockerCli`), so tests run no Docker. It gets the allow-listed environment plus its
32
32
  * own settings: a throwaway `DOCKER_CONFIG`, and the daemon's address. Logs carry IDs and codes only.
33
33
  */
34
+ import { DetailedError } from "../core/errors.js";
34
35
  import { spawn } from "node:child_process";
35
36
  import { createHash } from "node:crypto";
36
37
  import { existsSync } from "node:fs";
@@ -254,7 +255,7 @@ export class DockerSandbox {
254
255
  const opened = { name: containerName(spec.run_ref), spec, sleep_pid: null, unwatch: () => undefined, events: events ?? null };
255
256
  this.opened.set(spec.run_ref, opened);
256
257
  if (run.code !== 0)
257
- throw new Error("container_failed");
258
+ throw new DetailedError("container_failed", { exit_code: run.code, stderr: run.stderr, cut: run.cut });
258
259
  // The disk bound, for the whole run, whatever runs in the container (M2).
259
260
  opened.unwatch = this.every(LIMITS.watch_ms, async () => {
260
261
  if (this.opened.get(spec.run_ref) === opened && (await this.overBound(opened)))
@@ -265,7 +266,7 @@ export class DockerSandbox {
265
266
  const pids = children.stdout.trim().split(/\s+/).filter((p) => p !== "");
266
267
  if (children.code !== 0 || pids.length !== 1 || !/^\d+$/.test(pids[0])) {
267
268
  await this.kill(spec.run_ref).catch(() => undefined);
268
- throw new Error("container_failed");
269
+ throw new DetailedError("container_failed", { exit_code: children.code, stderr: children.stderr, cut: children.cut });
269
270
  }
270
271
  opened.sleep_pid = pids[0];
271
272
  }
@@ -452,7 +453,7 @@ export function dockerCli(program, opts) {
452
453
  child.on("error", (error) => {
453
454
  clearTimeout(timer);
454
455
  signal?.removeEventListener("abort", onAbort);
455
- reject(new Error(`docker couldn't start (${error.code ?? "error"})`));
456
+ reject(new DetailedError("docker_unavailable", { errno: String(error.code ?? "error") }));
456
457
  });
457
458
  child.on("close", (code) => {
458
459
  clearTimeout(timer);
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Runner's terminal log with a plain-English line under each failure (the owner's request of 2026-11-20). The JSON line is
3
+ * written as before; when its outcome is a failure, a refusal or a stop and it carries a code, the next line says what
4
+ * happened and what to do, from the fixed table in `explain.ts`, and names the local diagnostics file. Nothing but the
5
+ * validated code reaches the explanation, so no task text, error message or secret can.
6
+ */
7
+ import { explainLine, FAILURE_OUTCOMES } from "../core/explain.js";
8
+ import { logLine } from "../core/runtime.js";
9
+ import { FileDiagnostics } from "./diagnostics.js";
10
+ export function explainingLogger(write, diagnosticsFile) {
11
+ return (at, outcome, fields = {}) => {
12
+ const line = logLine(at, outcome, fields);
13
+ write(line);
14
+ const code = JSON.parse(line).code;
15
+ if (FAILURE_OUTCOMES.has(outcome) && code !== undefined)
16
+ write(explainLine(code, diagnosticsFile));
17
+ };
18
+ }
19
+ /** `run`'s logger and diagnostics for a home: the terminal's explained log, naming that home's diagnostics file. */
20
+ export function runLogger(home, write) {
21
+ const diagnostics = new FileDiagnostics(home);
22
+ return { log: explainingLogger(write, diagnostics.file), diagnostics };
23
+ }
@@ -107,7 +107,9 @@ export function reviewScreen(view, width = 80) {
107
107
  const pr = view.pull_request;
108
108
  const lines = [
109
109
  "",
110
- "A run finished, and its room holds the agent's words for you before they're shared with Podster.",
110
+ view.blocked
111
+ ? "A run ended with the agent reporting it is blocked, and its room holds the agent's reason for you before it's shared with Podster."
112
+ : "A run finished, and its room holds the agent's words for you before they're shared with Podster.",
111
113
  ` room ${view.workspace_id}, task ${view.task_id}`,
112
114
  ` pull request: ${pr ? `#${pr.number} in ${pr.full_name}, from ${pr.branch} at ${pr.commit}` : "none"}`,
113
115
  ` secrets redacted: ${view.redactions}`,
@@ -151,7 +153,8 @@ export class TerminalPrompter {
151
153
  this.terminal.write(`${screen}\n`);
152
154
  let answer;
153
155
  try {
154
- answer = (await this.terminal.question(cut ? "Submit it without the agent's words? [y/N] " : "Share the agent's words with Podster? [y/N] ", signal)).trim();
156
+ const without = view.blocked ? "Report it without the agent's reason? [y/N] " : "Submit it without the agent's words? [y/N] ";
157
+ answer = (await this.terminal.question(cut ? without : "Share the agent's words with Podster? [y/N] ", signal)).trim();
155
158
  }
156
159
  catch {
157
160
  return "later";
@@ -18,10 +18,12 @@
18
18
  * Host-side folder access goes through `safe-fs.ts` (`lstat`, `O_NOFOLLOW`, `realpath`; L3 on #459). Git runs as
19
19
  * `git.ts` says (L2 on #459). Logs carry IDs and codes only.
20
20
  */
21
+ import { holdSecret } from "../core/known-secrets.js";
21
22
  import { lstat, opendir, realpath } from "node:fs/promises";
22
23
  import { dirname, join, relative } from "node:path";
23
24
  import { GatewayError, meaningOf } from "../core/errors.js";
24
- import { checkProtected, COMMIT_IDENTITY, fetchArgs, GITHUB, hardening, isCommit, locate, pushArgs, readAccess, readPullRequest, readRef, readRepository, renewDue, RepoPathError, } from "../core/repository.js";
25
+ import { pullText } from "../core/pull-text.js";
26
+ import { checkProtected, COMMIT_IDENTITY, fetchArgs, GITHUB, hardening, isCommit, locate, pushArgs, readAccess, readPullRequest, readRef, readRepository, renewDue, RepoPathError, taskBranch, } from "../core/repository.js";
25
27
  import { foldedSegment } from "../core/tool-policy.js";
26
28
  import { checkedHelper, findGit, gitCli } from "./git.js";
27
29
  import { githubApi } from "./github-api.js";
@@ -32,6 +34,13 @@ const key = (workspace_id, task_id) => `${workspace_id}/${task_id}`;
32
34
  /** Holds each task's token in memory, outside every container, and asks Podster again only when it's due. */
33
35
  export class RepoBroker {
34
36
  held = new Map();
37
+ /** Each held token's release from exact-match redaction (`known-secrets.ts`). */
38
+ releases = new Map();
39
+ drop(k) {
40
+ this.held.delete(k);
41
+ this.releases.get(k)?.();
42
+ this.releases.delete(k);
43
+ }
35
44
  request;
36
45
  clock;
37
46
  log;
@@ -52,7 +61,7 @@ export class RepoBroker {
52
61
  answer = await this.request("get_repo_access", { workspace_id, task_id });
53
62
  }
54
63
  catch (error) {
55
- this.held.delete(k);
64
+ this.drop(k);
56
65
  if (!(error instanceof GatewayError))
57
66
  throw error;
58
67
  const meaning = meaningOf(error);
@@ -69,21 +78,23 @@ export class RepoBroker {
69
78
  access = readAccess(answer, scope, this.clock.now());
70
79
  }
71
80
  catch (error) {
72
- this.held.delete(k);
81
+ this.drop(k);
73
82
  this.log("repo.access", "refused", error instanceof RepoPathError ? { ...ids, code: error.code, ...error.detail } : { ...ids, code: "access_invalid" });
74
83
  throw error;
75
84
  }
85
+ this.drop(k);
76
86
  this.held.set(k, access);
87
+ this.releases.set(k, holdSecret(access.token));
77
88
  this.log("repo.access", held ? "renewed" : "issued", ids);
78
89
  return access;
79
90
  }
80
91
  /** A token GitHub no longer takes: dropped and reported, so the next use asks Podster again. */
81
92
  revoked(workspace_id, task_id) {
82
- this.held.delete(key(workspace_id, task_id));
93
+ this.drop(key(workspace_id, task_id));
83
94
  this.log("repo.access", "revoked", { workspace: workspace_id, task: task_id });
84
95
  }
85
96
  forget(workspace_id, task_id) {
86
- this.held.delete(key(workspace_id, task_id));
97
+ this.drop(key(workspace_id, task_id));
87
98
  }
88
99
  /** How many tokens are held, for tests. */
89
100
  get size() {
@@ -225,6 +236,9 @@ export class GitRepositoryPath {
225
236
  async publish(task, signal) {
226
237
  const scope = scopeOf(task);
227
238
  const branch = task.repository.branch;
239
+ // The task's ID is checked before the words name it.
240
+ taskBranch(task.task_id);
241
+ const text = pullText({ workspace_id: task.workspace_id, task_id: task.task_id, title: task.title ?? null, change_type: task.change_type ?? null, app_origin: this.deps.app_origin ?? null });
228
242
  // Renewed after a full server recheck when it's due: a run can outlast the hour a token lives.
229
243
  const access = await this.deps.broker.access(task.workspace_id, task.task_id, scope);
230
244
  const { default_branch } = await this.checked(task, access, signal);
@@ -242,7 +256,7 @@ export class GitRepositoryPath {
242
256
  if (await this.clean(task, signal))
243
257
  return { kind: "no_changes" };
244
258
  const identity = ["-c", `user.name=${COMMIT_IDENTITY.name}`, "-c", `user.email=${COMMIT_IDENTITY.email}`];
245
- const committed = await this.git(task, [...identity, "commit", "--quiet", "--no-verify", "--no-gpg-sign", "-m", `Podster task ${task.task_id}`], { signal });
259
+ const committed = await this.git(task, [...identity, "commit", "--quiet", "--no-verify", "--no-gpg-sign", "--cleanup=verbatim", "-m", text.commit_message], { signal });
246
260
  if (committed.code !== 0)
247
261
  throw new RepoPathError("commit_failed");
248
262
  }
@@ -258,7 +272,7 @@ export class GitRepositoryPath {
258
272
  if (!pushed.stdout.split("\n").some((line) => /^[*= ]\t/.test(line) && line.includes(`refs/heads/${branch}:refs/heads/${branch}`)))
259
273
  throw new RepoPathError("push_unconfirmed");
260
274
  const want = { scope, branch, default_branch, commit };
261
- const opened = await this.api(task, access, GITHUB.openPull(scope.full_name, task.task_id, branch, default_branch), signal);
275
+ const opened = await this.api(task, access, GITHUB.openPull(scope.full_name, text, branch, default_branch), signal);
262
276
  if (opened.status !== 201 && opened.status !== 422) {
263
277
  if (opened.status >= 500 || opened.status === 403 || opened.status === 429)
264
278
  throw new RepoPathError("github_unavailable", true);
@@ -366,5 +380,5 @@ export async function hostRepositoryPath(home, request, clock, log, opts = {}) {
366
380
  }
367
381
  // An empty home for Git, so it reads no one's settings; the Git folders sit beside it, under `git/`.
368
382
  const gitHome = await ensureFolder(home, join(home, "git-home"));
369
- return new GitRepositoryPath({ home, broker: new RepoBroker(request, clock, log), git: gitCli(program, gitHome), github, helper, log });
383
+ return new GitRepositoryPath({ home, broker: new RepoBroker(request, clock, log), git: gitCli(program, gitHome), github, helper, log, app_origin: opts.app_origin ?? null });
370
384
  }
@@ -15,6 +15,7 @@ import { SupervisedAdapter } from "../core/run-interface.js";
15
15
  import { FileRunStore } from "./file-runs.js";
16
16
  import { policyFile } from "./policy-file.js";
17
17
  import { TerminalPrompter } from "./prompter.js";
18
+ import { appOriginFor } from "../core/pull-text.js";
18
19
  import { hostRepositoryPath } from "./repo-path.js";
19
20
  /** No engine: `run` records offers and runs nothing. `cli.ts` uses the Claude engine instead when given a key file. */
20
21
  export const NO_ENGINE = null;
@@ -24,8 +25,8 @@ export async function runInbox(deps) {
24
25
  const engine = deps.engine;
25
26
  if (engine === null || !Object.values(engine.drivers).some((driver) => driver !== undefined))
26
27
  return deps.poller.run(deps.signal, deps.bell);
27
- const adapter = new SupervisedAdapter({ ...engine, clock: deps.clock, log: deps.log, progress: progressLog(deps.log) });
28
- const repository = deps.repository !== undefined ? deps.repository : await hostRepositoryPath(deps.home, (capability, args) => deps.poller.request(capability, args), deps.clock, deps.log);
28
+ const adapter = new SupervisedAdapter({ ...engine, clock: deps.clock, log: deps.log, progress: progressLog(deps.log), ...(deps.diagnostics ? { diagnostics: deps.diagnostics } : {}) });
29
+ 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) });
29
30
  const lifecycle = await Lifecycle.open({
30
31
  poller: deps.poller,
31
32
  runs: new FileRunStore(deps.home),
@@ -36,6 +37,7 @@ export async function runInbox(deps) {
36
37
  prompter: new TerminalPrompter(deps.terminal),
37
38
  clock: deps.clock,
38
39
  log: deps.log,
40
+ ...(deps.diagnostics ? { diagnostics: deps.diagnostics } : {}),
39
41
  });
40
42
  return runWithLifecycle(deps.poller, lifecycle, deps.clock, deps.signal, deps.bell);
41
43
  }
@@ -11,7 +11,7 @@
11
11
  * Errors carry fixed words only, never a path.
12
12
  */
13
13
  import { randomBytes } from "node:crypto";
14
- import { closeSync, constants, openSync, writeSync } from "node:fs";
14
+ import { closeSync, constants, fstatSync, lstatSync, openSync, writeSync } from "node:fs";
15
15
  import { lstat, mkdir, open, opendir, readdir, realpath, rename, rm, unlink } from "node:fs/promises";
16
16
  import { basename, dirname, isAbsolute, join, normalize, relative, sep } from "node:path";
17
17
  export class UnsafePath extends Error {
@@ -36,6 +36,32 @@ async function realFolder(path, uid) {
36
36
  throw new UnsafePath("writable by others");
37
37
  }
38
38
  const ownUid = () => (typeof process.getuid === "function" ? process.getuid() : null);
39
+ /**
40
+ * The same checks as `realFolder`, synchronously, for the local diagnostics file (review of #489): a real folder, not a
41
+ * link, owned by this user, writable by no one else.
42
+ */
43
+ export function ownFolderSync(path) {
44
+ const info = lstatSync(path);
45
+ const uid = ownUid();
46
+ if (info.isSymbolicLink() || !info.isDirectory())
47
+ throw new UnsafePath("not a real folder");
48
+ if (uid !== null && info.uid !== uid)
49
+ throw new UnsafePath("not the owner's");
50
+ if ((info.mode & 0o022) !== 0)
51
+ throw new UnsafePath("writable by others");
52
+ }
53
+ /** An open file that is a plain file, owned by this user, with one link: not a hard link to something else. */
54
+ export function ownFileSync(fd) {
55
+ const info = fstatSync(fd);
56
+ const uid = ownUid();
57
+ if (!info.isFile())
58
+ throw new UnsafePath("not a plain file");
59
+ if (uid !== null && info.uid !== uid)
60
+ throw new UnsafePath("not the owner's");
61
+ if (info.nlink !== 1)
62
+ throw new UnsafePath("linked elsewhere");
63
+ return { size: info.size };
64
+ }
39
65
  /**
40
66
  * Makes `folder` under `root`, each missing segment with mode 0700, and checks every segment from `root` down with
41
67
  * `lstat`; then checks `realpath` of the result is the path built. `root` itself must already be a real folder, or is
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "podster",
3
- "version": "0.0.1-test.6",
3
+ "version": "0.0.1-test.8",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "podster",
9
- "version": "0.0.1-test.6",
9
+ "version": "0.0.1-test.8",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/claude-agent-sdk": "0.3.327",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "podster",
3
- "version": "0.0.1-test.6",
3
+ "version": "0.0.1-test.8",
4
4
  "description": "Podster Runner, test pre-release for Podster staging only. Not supported. Not security-reviewed.",
5
5
  "license": "MIT",
6
6
  "repository": {