podster 0.0.1-test.16 → 0.0.1-test.17
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 +19 -1
- package/build/core/explain.js +1 -1
- package/build/core/lifecycle.js +1 -0
- package/build/core/policy.js +2 -0
- package/build/core/poller.js +1 -1
- package/build/core/roles.js +1 -1
- package/build/core/room-facts.js +225 -0
- package/build/core/setup.js +238 -0
- package/build/node/cli.js +33 -4
- package/build/node/lock.js +1 -1
- package/build/node/policy-file.js +61 -1
- package/build/node/prompter.js +46 -0
- package/build/node/run-command.js +7 -1
- package/build/node/setup-command.js +174 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -83,6 +83,24 @@ The task image is Debian bookworm-slim with the tools Runner's own task tools us
|
|
|
83
83
|
|
|
84
84
|
Runner runs a task only if your run policy says so. The policy is a file, `policy.json`, in Runner's home: by default `~/.podster-runner/policy.json`, or the folder you give with `--home`. You write it; nothing Podster sends can change it. Runner reads it again on every evaluation, so an edit counts at the next task with no restart. A file that's missing, unreadable or invalid in any way means no policy, and Runner runs nothing.
|
|
85
85
|
|
|
86
|
+
### Making one with `setup`
|
|
87
|
+
|
|
88
|
+
Instead of writing it by hand, let Runner propose a starter from a workroom's settings:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
npx --ignore-scripts podster@test setup --room <ws_…>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Leave out `--room` to pick from the rooms this agent is in. Runner asks Podster, as your paired agent, for its own organization (that becomes `owner_org`, never the room's) and for what it may tell this agent about the room, so nothing is copied by hand: the room's ID; its organization, when the room is your organization's or the agent sees the whole room; and its linked GitHub repository, name and numeric ID, only while the agent holds a push grant on it. Anything Podster doesn't tell is unknown. An unknown repository is written as `null`, which gives tasks none, and `run` asks you once Podster names one. It shows the policy it would save and what it allows, and saves it only when you type `y`. The starter asks before each run, holds outputs for your review, has no shell and no network, keeps the limits low (0.50 USD, 15 minutes and 30 turns a run, 2 USD a day), and leaves both acknowledgments unticked. Unattended runs stay off until you edit `mode` yourself. A new policy puts task folders in `~/podster-work` unless you give `--workspace-root <folder>`.
|
|
95
|
+
|
|
96
|
+
- **Another organization's room** is shown as external. Runner refuses its tasks unless that organization is in the room's `allowed_orgs`, and asking before each run doesn't allow it by itself; setup adds it only if you say yes to exactly that. If Podster doesn't name the organization to this agent, setup can't propose it: add its `org_…` ID to `allowed_orgs` yourself.
|
|
97
|
+
- **A policy you already have is never replaced.** A room it lacks is added, with everything else kept as you wrote it and `revision` raised. A room it has is checked for a repository change, below. A file Runner can't use, or one for another organization, is left alone and Runner says what's wrong.
|
|
98
|
+
- **Facts Runner can't use are never guessed.** If Podster doesn't tell the agent the room's organization and repository (an agent there through a public claim isn't told), or tells it something that doesn't check out, setup explains and saves nothing.
|
|
99
|
+
|
|
100
|
+
**Room changes after setup.** While `run` goes on, Runner reads each room in your policy again every 10 minutes. If Podster now names a repository for a room, or another one, Runner shows the room, the repository's name and GitHub ID, and what the room keeps, and asks you; only `y` writes it, and only that room's `repository` and the policy's `revision` change. `n` keeps your policy as it is until Podster's answer changes again or Runner restarts. Runner never removes a repository by itself: Podster names one only while the agent holds a push grant on it, so Runner can't tell an unlinked repository from one it isn't told about. If the room no longer links it, its tasks are refused (`get_repo_access`), and you edit the entry. Nothing Podster says ever changes `mode`, `allowed_orgs`, tools, network, limits or acknowledgments.
|
|
101
|
+
|
|
102
|
+
Runner writes `policy.json` only while it still holds the text your answer was about, checked just before the write, and reads it back after. If you edited the file meanwhile, Runner writes nothing and asks again; if something else wrote it at the same moment, Runner says so and asks again. One narrow window stays: an editor that saves in the instant between Runner's last check and its write, and doesn't save again, loses that save to Runner's. Don't edit `policy.json` while a setup or room-change question is open.
|
|
103
|
+
|
|
86
104
|
A complete, valid example, for one workroom. Replace the `org_…` and `ws_…` placeholders with your own IDs, and `/Users/you/podster-work` with a plain absolute folder of your own that isn't inside Runner's home:
|
|
87
105
|
|
|
88
106
|
```json
|
|
@@ -138,7 +156,7 @@ A complete, valid example, for one workroom. Replace the `org_…` and `ws_…`
|
|
|
138
156
|
| `rooms[].network` | Host names the room's tasks may reach, such as `["registry.npmjs.org"]` so an agent can `npm install`; `[]`, the default, is no network. Only HTTPS on port 443 to exactly these names, through Runner's egress proxy: no subdomain, other host, plain HTTP, other port or IP address, and never a name that resolves to your LAN or this machine. List exact lower-case names, at most 50; a scheme, port, path, wildcard, IP address, upper case, trailing dot or a name like `localhost` is refused when Runner starts, with `network_host_invalid` and the entry's index. A listed host is fully reachable, so list only hosts you'd let the task send data to, and a host behind a shared CDN can be used to reach other sites on that CDN (domain fronting), which an allowlist of names can't stop. Needs Docker Engine 26 or later; an older one refuses the run with `docker_engine_too_old`. Runner logs each allowed or refused host when a run ends. |
|
|
139
157
|
| `rooms[].toolchains` | Optional toolchains for the room's tasks: any of `"dotnet"`, `"java"`, `"python"` and `"rust"`, such as `["rust", "python"]`. `[]`, the default, runs tasks in Runner's base image (shell tools and Node 22). `rust` adds Rust 1.100.0 (cargo, rustc, rustfmt, clippy) with gcc as its linker; `python` adds Python 3.14.10 and uv 0.13.9; `dotnet` adds the .NET 10 SDK 10.0.404; `java` adds the Temurin JDK 25.0.5.1 and Maven 3.10.1 (a Gradle project uses its own wrapper). Each needs `shell` in `tools`. Runner builds the room's image from its own pinned Dockerfiles the first time a task needs it, which takes a few minutes and counts against that run's time; after that it's reused. A toolchain adds no network: to fetch packages, list the registries in `network`, `index.crates.io` and `static.crates.io` for crates, `pypi.org` and `files.pythonhosted.org` for PyPI, `api.nuget.org` for NuGet, `repo.maven.apache.org` for Maven Central, and for a Gradle wrapper `services.gradle.org` with `github.com` and `release-assets.githubusercontent.com`, where it downloads Gradle from (plus `plugins.gradle.org` for plugins). Listing `github.com` for the wrapper opens all of GitHub to the task, not only Gradle's downloads. Toolchain rooms get larger bounds a build needs: 4 GB of memory, 1,024 processes and 10 minutes per command. An unknown or repeated name is refused when Runner starts, with `toolchain_unknown` or `toolchain_duplicate` and the entry's index, and toolchains without `shell` with `toolchain_needs_shell`. |
|
|
140
158
|
| `rooms[].repository` | `null` for a task that starts in an empty folder, or `{ "full_name": "owner/name", "provider_repo_id": 123456 }` for one GitHub repository. |
|
|
141
|
-
| `rooms[].roles` | What Runner does when the room invites this agent to a role opening. `"ask"`, the default, asks you at your terminal: `y` claims it as this agent, `n` turns it down, anything else leaves it for later. `"accept"` claims it with no question. Runner never turns an invite down by itself, and a room not listed here always asks. Claiming accepts no task and gives no person access. A pairing made before Runner answered invites can't: Runner logs `pair_again_for_roles` once, and
|
|
159
|
+
| `rooms[].roles` | What Runner does when the room invites this agent to a role opening. `"ask"`, the default, asks you at your terminal: `y` claims it as this agent, `n` turns it down, anything else leaves it for later. `"accept"` claims it with no question. Runner never turns an invite down by itself, and a room not listed here always asks. Claiming accepts no task and gives no person access. A pairing made before Runner answered invites can't: Runner logs `pair_again_for_roles` once. Tasks still run and roles already held stay, so you can leave it. Pairing again makes a new agent with a new ID, which must be added to each room and given its roles and any push or merge grants again; the old agent keeps its place until removed. |
|
|
142
160
|
| `rooms[].allowed_orgs` | Other organizations whose tasks you'll run in this room. Do not list `owner_org`: your own organization is always allowed, and Runner refuses a policy that lists it. An empty list is fine. |
|
|
143
161
|
| `rooms[].acknowledged` | Both flags are required. Until `trust_statement` is `true`, Runner asks you at your terminal each time. Until `public_room_warning` is `true`, it also asks for a public room. |
|
|
144
162
|
|
package/build/core/explain.js
CHANGED
|
@@ -102,7 +102,7 @@ const TABLE = new Map([
|
|
|
102
102
|
...group(["gateway_unreachable"], "Runner hasn't reached Podster for longer than its offline grace period, so it starts nothing new until it does.", "Check this machine's network, VPN or proxy; Runner keeps trying and checks this agent's access again once Podster answers. Stop it with Ctrl-C or `stop`."),
|
|
103
103
|
...group(["accept_unexpected", "unknown", "unexpected", "too_large", "not_data", "unreadable", "request_invalid"], "Runner got an answer it didn't expect.", SUPPORT),
|
|
104
104
|
// Pairing and role invitations (#542).
|
|
105
|
-
...group(["pair_again_for_roles"], "This Runner was paired before it could answer role invitations, so
|
|
105
|
+
...group(["pair_again_for_roles"], "This Runner was paired before it could answer role invitations, so room invites to this agent aren't answered from this machine. Tasks still run as before, and roles it already holds stay.", "Nothing to do unless you want invites answered from this machine; you can leave this agent as it is. Pairing again makes a new agent with a new ID, never this one: stop Runner, run `forget`, choose Add an agent in Podster, run `npx podster@test pair --agent <agt_…>` with the new agent's ID, and start it with `run`. Then add the new agent to each room and give it its roles and any push or merge grants again; this agent keeps its place until you remove it."),
|
|
106
106
|
...group(["invalid_capabilities"], "This Podster doesn't offer managed repositories, so Runner paired without repository access.", "Nothing to do; tasks in rooms without a repository run as usual."),
|
|
107
107
|
...group(["review_hold_expired"], "A result held for your review went unanswered for a day, so Runner submitted it with its fixed note only, never the agent's words.", "Nothing to do; answer held results sooner to share the agent's summary."),
|
|
108
108
|
...group(["git_not_found"], "Runner found no Git at the paths it uses (/usr/bin/git, /opt/homebrew/bin/git or /usr/local/bin/git), so tasks in rooms with a repository are refused.", "Install Git 2.25 or later at one of those paths, then restart Runner with `run`."),
|
package/build/core/lifecycle.js
CHANGED
package/build/core/policy.js
CHANGED
|
@@ -194,6 +194,8 @@ function keysAre(o, required, optional = []) {
|
|
|
194
194
|
return required.every((k) => Object.hasOwn(o, k)) && keys.every((k) => required.includes(k) || optional.includes(k));
|
|
195
195
|
}
|
|
196
196
|
const isId = (v) => typeof v === "string" && ID.test(v);
|
|
197
|
+
/** A room, workspace or organization ID as the policy file holds it: lower case only (L6 on #455's review). */
|
|
198
|
+
export const isPolicyId = isId;
|
|
197
199
|
const isActorId = (v) => typeof v === "string" && ACTOR_ID.test(v);
|
|
198
200
|
const isCount = (v) => typeof v === "number" && Number.isSafeInteger(v) && v >= 0;
|
|
199
201
|
const inRange = (v, min, max) => isCount(v) && v >= min && v <= max;
|
package/build/core/poller.js
CHANGED
|
@@ -73,7 +73,7 @@ export class Poller {
|
|
|
73
73
|
static async open(deps) {
|
|
74
74
|
const state = await deps.state.load();
|
|
75
75
|
if (state.stopped === "revoked")
|
|
76
|
-
throw new Error("This agent's connection ended in Podster. Pair again from Podster to go on.");
|
|
76
|
+
throw new Error("This agent's connection ended in Podster. Pair again from Podster to go on: that makes a new agent with a new ID, to add to its rooms again.");
|
|
77
77
|
if (state.stopped !== null)
|
|
78
78
|
throw new Error("Pairing didn't finish. Start a new pairing in Podster, then run `pair` again.");
|
|
79
79
|
if (state.phase !== "connected" || !isId(state.agent_id) || !isId(state.plugin_agent_id))
|
package/build/core/roles.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* is read and asked about afresh. An owner's answer that arrives after a newer notice is set aside the same way.
|
|
26
26
|
* - **An older pairing.** A pairing registered before these capabilities were Runner's doesn't hold them, and calling one
|
|
27
27
|
* would read as an authority error. Runner checks its stored grants first and, missing any, leaves invites alone and
|
|
28
|
-
* says once that pairing
|
|
28
|
+
* says once that only a new pairing, which makes a new agent, can answer them.
|
|
29
29
|
*/
|
|
30
30
|
import { GatewayError, meaningOf } from "./errors.js";
|
|
31
31
|
import { parsePolicyConfig } from "./policy.js";
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Room changes after setup (issue 523, the owner's clarification): while `run` goes on, Runner reads each room in the
|
|
3
|
+
* owner's policy again now and then, and compares Podster's facts with the room's entry (`setup.ts`).
|
|
4
|
+
*
|
|
5
|
+
* - **Every change waits for the owner.** A repository Podster now names for a room, or names differently, is shown at
|
|
6
|
+
* this terminal with what the room keeps, and written only on a typed `y`. The answer is tied to exactly what was shown: it's used only if, on a
|
|
7
|
+
* fresh read, Podster still says the same and the policy file is still the text it was asked about. Anything else sets
|
|
8
|
+
* the answer aside and asks again. A `no` holds until Podster's facts change again or Runner restarts; no terminal, or
|
|
9
|
+
* no answer, writes nothing.
|
|
10
|
+
* - **Unknown is "ask later", never "none".** Podster names a room's repository only while this agent holds a live push
|
|
11
|
+
* grant on it, and its organization only where the agent could already see it. A part it leaves out is unknown, and
|
|
12
|
+
* Runner never removes or narrows anything on it: a repository the room no longer links is refused by
|
|
13
|
+
* `get_repo_access`, and the owner edits the entry.
|
|
14
|
+
* - **Nothing else moves.** Only that room's `repository` and the policy's `revision` change; every other limit and
|
|
15
|
+
* permission the owner wrote stays. Podster's facts are data: checked IDs and a checked GitHub name, never text to act
|
|
16
|
+
* on, and never a source for `mode`, `allowed_orgs`, tools, network or acknowledgments.
|
|
17
|
+
* - **A write that races is never silent.** The file is written only while it still holds the text the question was
|
|
18
|
+
* about, and read back after; if it holds anything else then, the owner is told and asked again on a later pass.
|
|
19
|
+
* - **Unknown isn't a change.** A room Podster won't describe to this agent, or describes in a way that doesn't check out,
|
|
20
|
+
* is left as the owner wrote it.
|
|
21
|
+
* - **A question never holds up task work.** As with role invites (issue 528), the answer is waited for off the poll loop,
|
|
22
|
+
* one question at a time, and set aside (`QuestionInterrupted`) when a task needs the terminal.
|
|
23
|
+
*/
|
|
24
|
+
import { GatewayError, meaningOf } from "./errors.js";
|
|
25
|
+
import { parsePolicyConfig } from "./policy.js";
|
|
26
|
+
import { AuthorityEnded } from "./poller.js";
|
|
27
|
+
import { QuestionInterrupted } from "./roles.js";
|
|
28
|
+
import { applyRoomChange, changeKey, readRoomFacts, roomChange } from "./setup.js";
|
|
29
|
+
/** How often each room's facts are read again. */
|
|
30
|
+
export const ROOM_CHECK_MS = 10 * 60 * 1000;
|
|
31
|
+
/** How long a change the owner left unanswered waits before it's asked again. */
|
|
32
|
+
export const ROOM_ASK_AGAIN_MS = 10 * 60 * 1000;
|
|
33
|
+
/** How soon a question set aside, or ended by a newer change, is asked again. */
|
|
34
|
+
export const ROOM_RETRY_MS = 60 * 1000;
|
|
35
|
+
/** Rooms read in one pass; the rest wait for the next. */
|
|
36
|
+
export const ROOM_CHECKS_PER_PASS = 10;
|
|
37
|
+
export class RoomFacts {
|
|
38
|
+
deps;
|
|
39
|
+
nextCheckAt = 0;
|
|
40
|
+
/** Where the last pass stopped in the list of rooms, so every room gets its turn. */
|
|
41
|
+
cursor = 0;
|
|
42
|
+
asking = null;
|
|
43
|
+
heard = new Map();
|
|
44
|
+
/** Changes the owner turned down, by room: not asked again until Podster says something else. In memory only. */
|
|
45
|
+
declined = new Map();
|
|
46
|
+
/** When each room's change was left unanswered, by change key. */
|
|
47
|
+
later = new Map();
|
|
48
|
+
constructor(deps) {
|
|
49
|
+
this.deps = deps;
|
|
50
|
+
}
|
|
51
|
+
log(outcome, workspace, code) {
|
|
52
|
+
this.deps.log("rooms.facts", outcome, { agent: this.deps.poller.agentId, workspace, ...(code ? { code } : {}) });
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* One pass, when one is due or an owner's answer is waiting: each room in the policy, up to a bound, read again and
|
|
56
|
+
* compared. An authority error throws `AuthorityEnded`; a network failure leaves everything for the next pass.
|
|
57
|
+
*/
|
|
58
|
+
async pass(signal) {
|
|
59
|
+
const now = this.deps.clock.now();
|
|
60
|
+
if (now < this.nextCheckAt && this.heard.size === 0)
|
|
61
|
+
return;
|
|
62
|
+
if (!this.deps.poller.authorityFresh())
|
|
63
|
+
return;
|
|
64
|
+
const text = await this.readText();
|
|
65
|
+
if (text === null)
|
|
66
|
+
return;
|
|
67
|
+
const parsed = parsePolicyConfig(safeJson(text), { runner_home: this.deps.home });
|
|
68
|
+
if (!parsed.ok)
|
|
69
|
+
return;
|
|
70
|
+
const rooms = parsed.value.rooms;
|
|
71
|
+
if (rooms.length === 0)
|
|
72
|
+
return;
|
|
73
|
+
// An answer waiting is for one room: that room is read now, whether or not a full pass is due.
|
|
74
|
+
const due = now >= this.nextCheckAt;
|
|
75
|
+
let chosen;
|
|
76
|
+
if (due) {
|
|
77
|
+
this.nextCheckAt = now + ROOM_CHECK_MS;
|
|
78
|
+
const start = this.cursor % rooms.length;
|
|
79
|
+
chosen = [...rooms.slice(start), ...rooms.slice(0, start)].slice(0, ROOM_CHECKS_PER_PASS);
|
|
80
|
+
this.cursor = start + chosen.length;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
chosen = rooms.filter((r) => this.heard.has(r.room_id));
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
for (const room of chosen) {
|
|
87
|
+
if (signal.aborted)
|
|
88
|
+
return;
|
|
89
|
+
await this.room(room, signal);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (error instanceof AuthorityEnded)
|
|
94
|
+
throw error;
|
|
95
|
+
if (signal.aborted)
|
|
96
|
+
return;
|
|
97
|
+
const failure = error instanceof GatewayError ? error : new GatewayError(0, "unknown");
|
|
98
|
+
this.deps.log("rooms.facts", "unreachable", { agent: this.deps.poller.agentId, status: failure.status, code: failure.code });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async readText() {
|
|
102
|
+
try {
|
|
103
|
+
return await this.deps.policy.read();
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async room(room, signal) {
|
|
110
|
+
const workspace = room.room_id;
|
|
111
|
+
let answer;
|
|
112
|
+
try {
|
|
113
|
+
answer = await this.deps.poller.request("get_workspace", { workspace_id: workspace });
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (error instanceof GatewayError && meaningOf(error) === "refused") {
|
|
117
|
+
this.heard.delete(workspace);
|
|
118
|
+
this.log("room_unreadable", workspace, error.code);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
const read = readRoomFacts(workspace, answer);
|
|
124
|
+
if (!read.ok) {
|
|
125
|
+
this.heard.delete(workspace);
|
|
126
|
+
this.log("facts_unknown", workspace, read.problem);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const change = roomChange(room, read.facts);
|
|
130
|
+
const heard = this.heard.get(workspace);
|
|
131
|
+
this.heard.delete(workspace);
|
|
132
|
+
if (change === null) {
|
|
133
|
+
this.declined.delete(workspace);
|
|
134
|
+
if (this.asking?.room === workspace)
|
|
135
|
+
this.asking.controller.abort();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const key = changeKey(change);
|
|
139
|
+
// The policy as it is now: an answer counts only for the text it was asked about.
|
|
140
|
+
const text = await this.readText();
|
|
141
|
+
if (text === null)
|
|
142
|
+
return;
|
|
143
|
+
if (heard && heard.key === key && heard.text === text) {
|
|
144
|
+
if (heard.choice === "approve") {
|
|
145
|
+
await this.write(change, room, text, "widened_by_owner");
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (heard.choice === "decline") {
|
|
149
|
+
this.declined.set(workspace, key);
|
|
150
|
+
this.log("declined_by_owner", workspace, change.kind);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
this.later.set(key, this.deps.clock.now());
|
|
154
|
+
this.log("waiting_for_owner", workspace, change.kind);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (heard)
|
|
158
|
+
this.log("answer_set_aside", workspace, change.kind);
|
|
159
|
+
if (this.declined.get(workspace) === key)
|
|
160
|
+
return;
|
|
161
|
+
if (this.asking) {
|
|
162
|
+
// Asked about something that has changed since: ended, and asked again afresh.
|
|
163
|
+
if (this.asking.room === workspace && this.asking.key !== key)
|
|
164
|
+
this.asking.controller.abort();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const left = this.later.get(key);
|
|
168
|
+
if (left !== undefined && this.deps.clock.now() - left < ROOM_ASK_AGAIN_MS)
|
|
169
|
+
return;
|
|
170
|
+
if (!this.deps.prompter.roomChange) {
|
|
171
|
+
this.log("waiting_for_owner", workspace, change.kind);
|
|
172
|
+
this.later.set(key, this.deps.clock.now());
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
this.ask(workspace, key, text, { change, room }, signal);
|
|
176
|
+
this.log("asking_owner", workspace, change.kind);
|
|
177
|
+
}
|
|
178
|
+
async write(change, room, text, outcome) {
|
|
179
|
+
const next = applyRoomChange(text, change, this.deps.home);
|
|
180
|
+
const written = next === null ? "changed" : await this.deps.policy.write(next.text, text);
|
|
181
|
+
if (written === "changed") {
|
|
182
|
+
// The owner edited the file meanwhile: nothing written, and read again next time.
|
|
183
|
+
this.log("policy_changed_meanwhile", room.room_id, change.kind);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (written === "raced") {
|
|
187
|
+
// Something else wrote the file as Runner did: the owner is told, and the room is read and asked about again.
|
|
188
|
+
this.log("policy_write_raced", room.room_id, change.kind);
|
|
189
|
+
this.deps.prompter.policyRaced?.(this.deps.policy.path ?? "policy.json");
|
|
190
|
+
this.nextCheckAt = Math.min(this.nextCheckAt, this.deps.clock.now() + ROOM_RETRY_MS);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
this.later.delete(changeKey(change));
|
|
194
|
+
this.log(outcome, room.room_id, change.kind);
|
|
195
|
+
}
|
|
196
|
+
ask(workspace, key, text, view, signal) {
|
|
197
|
+
const controller = new AbortController();
|
|
198
|
+
const stop = () => controller.abort();
|
|
199
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
200
|
+
const asking = { room: workspace, key, controller };
|
|
201
|
+
this.asking = asking;
|
|
202
|
+
const question = (async () => this.deps.prompter.roomChange.call(this.deps.prompter, view, controller.signal))();
|
|
203
|
+
void question
|
|
204
|
+
.then((choice) => choice, (error) => (error instanceof QuestionInterrupted ? null : "later"))
|
|
205
|
+
.then((choice) => {
|
|
206
|
+
signal.removeEventListener("abort", stop);
|
|
207
|
+
if (this.asking === asking)
|
|
208
|
+
this.asking = null;
|
|
209
|
+
if (choice !== null && !controller.signal.aborted)
|
|
210
|
+
this.heard.set(workspace, { key, text, choice });
|
|
211
|
+
// Set aside, or ended because Podster said something else: the rooms are read again soon.
|
|
212
|
+
else
|
|
213
|
+
this.nextCheckAt = Math.min(this.nextCheckAt, this.deps.clock.now() + ROOM_RETRY_MS);
|
|
214
|
+
this.deps.wake?.();
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function safeJson(text) {
|
|
219
|
+
try {
|
|
220
|
+
return JSON.parse(text);
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A starter run policy from a workroom's settings, and the room changes that need the owner after it (issue 523). Pure:
|
|
3
|
+
* no I/O, no clock. `src/node/setup-command.ts` (the `setup` command) and `room-facts.ts` (the check `run` makes) do the
|
|
4
|
+
* reading, the asking and the writing.
|
|
5
|
+
*
|
|
6
|
+
* - **Facts, not instructions.** Podster's room read gives an agent that could hold the room's repository grant its
|
|
7
|
+
* `setup` (`getWorkspace` in the contract), telling only what the agent could already see: the room's ID; its
|
|
8
|
+
* organization when the room is the agent's own organization's or the agent sees the whole room; and the linked
|
|
9
|
+
* repository's full name and GitHub's numeric ID only while the agent holds a live push grant on it. They are checked
|
|
10
|
+
* whole, as IDs and a GitHub full name, and used only to fill the fields of a proposal the owner reads. A part left out
|
|
11
|
+
* is unknown, never "none": an unknown organization is never put in `allowed_orgs`, and an unknown repository is never
|
|
12
|
+
* a reason to change a room's entry. A read with no `setup`, or one that doesn't check out, proposes nothing.
|
|
13
|
+
* - **The owner decides.** Nothing here writes a file or turns anything on. A starter room asks before each run, holds
|
|
14
|
+
* outputs for review, has no shell and no network, and has neither acknowledgment ticked. Another organization's room
|
|
15
|
+
* is shown as external, and its organization goes into `allowed_orgs` only when the owner said yes to exactly that.
|
|
16
|
+
* `owner_org` is always the paired agent's own organization, never the room's. Unattended runs stay off (decision 29).
|
|
17
|
+
* - **The owner approves every change.** After setup, a repository Podster now names for a room, or names differently,
|
|
18
|
+
* is a change the owner approves before it's written, and only that room's `repository` and the policy's `revision`
|
|
19
|
+
* change: every other field, limit and permission the owner wrote stays exactly as it was. Runner can't tell a
|
|
20
|
+
* repository unlinked from one it isn't told about, so it never removes one by itself: `get_repo_access` refuses tasks
|
|
21
|
+
* for a repository the room no longer links, and the owner edits the entry.
|
|
22
|
+
* - **The file's own rules hold.** Every proposal is checked by `parsePolicyConfig` before it's offered, so a policy this
|
|
23
|
+
* writes is one Runner would load: no unknown or missing field, IDs in lower case, and `owner_org` never in
|
|
24
|
+
* `allowed_orgs`.
|
|
25
|
+
*/
|
|
26
|
+
import { DEFAULT_TOOLS, isFullName, isPolicyId, parsePolicyConfig, policyProblem } from "./policy.js";
|
|
27
|
+
/** The starter's limits: conservative, each well under its ceiling. The same as the README's example. */
|
|
28
|
+
export const STARTER_CAPS = { spend_micro_usd: 500_000, run_time_ms: 900_000, turns: 30, output_tokens: 20_000, max_tokens: 8_000 };
|
|
29
|
+
export const STARTER_DAY_SPEND_MICRO_USD = 2_000_000;
|
|
30
|
+
const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
31
|
+
const keysAre = (o, keys) => Object.keys(o).length === keys.length && keys.every((k) => Object.hasOwn(o, k));
|
|
32
|
+
/** The room read's `setup`, for the room asked about, checked whole. */
|
|
33
|
+
export function readRoomFacts(workspaceId, answer) {
|
|
34
|
+
if (!isObj(answer) || !Object.hasOwn(answer, "setup") || answer.setup === undefined)
|
|
35
|
+
return { ok: false, problem: "not_shared" };
|
|
36
|
+
const setup = answer.setup;
|
|
37
|
+
if (!isObj(setup) || !Object.keys(setup).every((k) => k === "room_id" || k === "org_id" || k === "repository"))
|
|
38
|
+
return { ok: false, problem: "inconsistent" };
|
|
39
|
+
const room_id = setup.room_id;
|
|
40
|
+
if (!isPolicyId(room_id) || room_id !== workspaceId)
|
|
41
|
+
return { ok: false, problem: "inconsistent" };
|
|
42
|
+
const facts = { room_id };
|
|
43
|
+
if (Object.hasOwn(setup, "org_id")) {
|
|
44
|
+
if (!isPolicyId(setup.org_id))
|
|
45
|
+
return { ok: false, problem: "inconsistent" };
|
|
46
|
+
facts.org_id = setup.org_id;
|
|
47
|
+
}
|
|
48
|
+
if (Object.hasOwn(setup, "repository")) {
|
|
49
|
+
// Told only as a repository: "none" is never said, so null doesn't check out either.
|
|
50
|
+
const repository = setup.repository;
|
|
51
|
+
if (!isObj(repository) || !keysAre(repository, ["full_name", "provider_repo_id"]))
|
|
52
|
+
return { ok: false, problem: "inconsistent" };
|
|
53
|
+
const { full_name, provider_repo_id } = repository;
|
|
54
|
+
if (!isFullName(full_name) || typeof provider_repo_id !== "number" || !Number.isSafeInteger(provider_repo_id) || provider_repo_id < 1)
|
|
55
|
+
return { ok: false, problem: "inconsistent" };
|
|
56
|
+
facts.repository = { full_name, provider_repo_id };
|
|
57
|
+
}
|
|
58
|
+
return { ok: true, facts };
|
|
59
|
+
}
|
|
60
|
+
/** Why facts couldn't be used, for the owner, in fixed words. */
|
|
61
|
+
export function factsProblemText(problem) {
|
|
62
|
+
return problem === "not_shared"
|
|
63
|
+
? "Podster didn't tell this agent anything about the room for setup. That happens when the agent joined through a public claim, isn't in the room, or the server doesn't share it yet. Runner won't guess, so nothing was proposed."
|
|
64
|
+
: "Podster's answer about the room didn't check out (an ID that isn't lower case, another room, or a repository without a valid name and numeric ID). Runner won't guess, so nothing was proposed.";
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Whether the room is another organization's than the owner's. A room Podster doesn't name the organization of is
|
|
68
|
+
* another's: Podster always names it for a room of the agent's own organization.
|
|
69
|
+
*/
|
|
70
|
+
export const isExternal = (facts, ownerOrg) => facts.org_id !== ownerOrg;
|
|
71
|
+
/**
|
|
72
|
+
* A starter room entry: ask first, outputs held, the default tools (no shell), no network, and no acknowledgment ticked.
|
|
73
|
+
* Its repository is the one Podster named, or null when Podster named none to this agent, which gives tasks no
|
|
74
|
+
* repository: `run` asks the owner once Podster names one. The room's organization is allowed only when it's another's,
|
|
75
|
+
* Podster named it, and the owner approved it.
|
|
76
|
+
*/
|
|
77
|
+
export function starterRoom(facts, ownerOrg, allowRoomOrg) {
|
|
78
|
+
return {
|
|
79
|
+
room_id: facts.room_id,
|
|
80
|
+
mode: "ask",
|
|
81
|
+
outputs: "hold",
|
|
82
|
+
tools: [...DEFAULT_TOOLS],
|
|
83
|
+
network: [],
|
|
84
|
+
repository: facts.repository === undefined ? null : { full_name: facts.repository.full_name, provider_repo_id: facts.repository.provider_repo_id },
|
|
85
|
+
allowed_orgs: facts.org_id !== undefined && isExternal(facts, ownerOrg) && allowRoomOrg ? [facts.org_id] : [],
|
|
86
|
+
acknowledged: { trust_statement: false, public_room_warning: false },
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const pretty = (v) => `${JSON.stringify(v, null, 2)}\n`;
|
|
90
|
+
/**
|
|
91
|
+
* What setup would write. An existing policy is never replaced: a room it lacks is added to it, with everything else kept
|
|
92
|
+
* as the owner wrote it and the revision raised; a room it has goes to the change check; a file Runner can't use, or one
|
|
93
|
+
* for another organization, is left alone and explained.
|
|
94
|
+
*/
|
|
95
|
+
export function planSetup(input) {
|
|
96
|
+
if (!isPolicyId(input.owner_org))
|
|
97
|
+
return { kind: "refuse", reason: "proposal_invalid", detail: "The paired agent's organization ID can't be written in a policy (it must be lower case)." };
|
|
98
|
+
const room = starterRoom(input.facts, input.owner_org, input.allow_room_org);
|
|
99
|
+
let config;
|
|
100
|
+
let kind;
|
|
101
|
+
if (input.existing === null) {
|
|
102
|
+
kind = "new";
|
|
103
|
+
config = {
|
|
104
|
+
version: 1,
|
|
105
|
+
revision: 1,
|
|
106
|
+
owner_org: input.owner_org,
|
|
107
|
+
adapter: "claude_agent_sdk",
|
|
108
|
+
workspace_root: input.workspace_root,
|
|
109
|
+
caps: { ...STARTER_CAPS },
|
|
110
|
+
day_caps: { spend_micro_usd: STARTER_DAY_SPEND_MICRO_USD },
|
|
111
|
+
rooms: [room],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
let raw;
|
|
116
|
+
try {
|
|
117
|
+
raw = JSON.parse(input.existing);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return { kind: "refuse", reason: "existing_invalid", detail: "it isn't JSON" };
|
|
121
|
+
}
|
|
122
|
+
const parsed = parsePolicyConfig(raw, { runner_home: input.runner_home });
|
|
123
|
+
if (!parsed.ok || !isObj(raw))
|
|
124
|
+
return { kind: "refuse", reason: "existing_invalid", detail: parsed.ok ? "config is missing or out of range" : policyProblem(parsed.at) };
|
|
125
|
+
if (parsed.value.owner_org !== input.owner_org)
|
|
126
|
+
return { kind: "refuse", reason: "owner_org_mismatch", detail: `its owner_org is ${parsed.value.owner_org}, and this agent's organization is ${input.owner_org}` };
|
|
127
|
+
const present = parsed.value.rooms.find((r) => r.room_id === input.facts.room_id);
|
|
128
|
+
if (present)
|
|
129
|
+
return { kind: "room_present", room: present, config: parsed.value };
|
|
130
|
+
kind = "add_room";
|
|
131
|
+
config = { ...raw, revision: parsed.value.revision + 1, rooms: [...raw.rooms, room] };
|
|
132
|
+
}
|
|
133
|
+
const checked = parsePolicyConfig(config, { runner_home: input.runner_home });
|
|
134
|
+
if (!checked.ok)
|
|
135
|
+
return { kind: "refuse", reason: "proposal_invalid", detail: policyProblem(checked.at) };
|
|
136
|
+
return { kind, config, text: pretty(config) };
|
|
137
|
+
}
|
|
138
|
+
const sameRepo = (a, b) => a.provider_repo_id === b.provider_repo_id && a.full_name === b.full_name;
|
|
139
|
+
/**
|
|
140
|
+
* How Podster's facts differ from the owner's room entry, as far as the repository goes. A renamed repository (the same
|
|
141
|
+
* ID under another name) counts as replaced: Runner checks GitHub's name against the policy, so it needs the owner too.
|
|
142
|
+
* A repository Podster didn't name is unknown, never a change: nothing is removed on it.
|
|
143
|
+
*/
|
|
144
|
+
export function roomChange(room, facts) {
|
|
145
|
+
const have = room.repository;
|
|
146
|
+
const now = facts.repository;
|
|
147
|
+
if (now === undefined)
|
|
148
|
+
return null;
|
|
149
|
+
if (have === null)
|
|
150
|
+
return { kind: "repository_added", room_id: room.room_id, to: now };
|
|
151
|
+
if (!sameRepo(have, now))
|
|
152
|
+
return { kind: "repository_replaced", room_id: room.room_id, from: have, to: now };
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
/** A change's identity, to tie an owner's answer to exactly what they were shown. */
|
|
156
|
+
export function changeKey(change) {
|
|
157
|
+
const repo = (r) => (r ? `${r.full_name}#${r.provider_repo_id}` : "-");
|
|
158
|
+
return `${change.kind}:${change.room_id}:${repo("from" in change ? change.from : undefined)}:${repo("to" in change ? change.to : undefined)}`;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The policy text with one room's change applied: that room's `repository` and the policy's `revision` only, everything
|
|
162
|
+
* else as the owner wrote it. Null when the text isn't a usable policy any more, the room is gone, or its repository
|
|
163
|
+
* isn't what the change started from (the owner edited it meanwhile).
|
|
164
|
+
*/
|
|
165
|
+
export function applyRoomChange(existing, change, runnerHome) {
|
|
166
|
+
let raw;
|
|
167
|
+
try {
|
|
168
|
+
raw = JSON.parse(existing);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
const parsed = parsePolicyConfig(raw, { runner_home: runnerHome });
|
|
174
|
+
if (!parsed.ok || !isObj(raw) || !Array.isArray(raw.rooms))
|
|
175
|
+
return null;
|
|
176
|
+
const index = parsed.value.rooms.findIndex((r) => r.room_id === change.room_id);
|
|
177
|
+
if (index < 0)
|
|
178
|
+
return null;
|
|
179
|
+
const current = parsed.value.rooms[index].repository;
|
|
180
|
+
const from = "from" in change ? change.from : null;
|
|
181
|
+
if (from === null ? current !== null : current === null || !sameRepo(current, from))
|
|
182
|
+
return null;
|
|
183
|
+
const rooms = [...raw.rooms];
|
|
184
|
+
const to = { full_name: change.to.full_name, provider_repo_id: change.to.provider_repo_id };
|
|
185
|
+
rooms[index] = { ...rooms[index], repository: to };
|
|
186
|
+
const config = { ...raw, revision: parsed.value.revision + 1, rooms };
|
|
187
|
+
if (!parsePolicyConfig(config, { runner_home: runnerHome }).ok)
|
|
188
|
+
return null;
|
|
189
|
+
return { config, text: pretty(config) };
|
|
190
|
+
}
|
|
191
|
+
const repoText = (r) => `${r.full_name} (GitHub ID ${r.provider_repo_id})`;
|
|
192
|
+
/** What the owner sees of a change, in fixed words around checked IDs and a checked GitHub name. */
|
|
193
|
+
export function changeScreen(change, room) {
|
|
194
|
+
const lines = [""];
|
|
195
|
+
if (change.kind === "repository_added") {
|
|
196
|
+
lines.push(`Podster now links a repository to room ${change.room_id}, and Runner's policy has none for it.`, ` repository: ${repoText(change.to)}`);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
lines.push(`Podster links another repository to room ${change.room_id} than Runner's policy names.`, ` policy has: ${repoText(change.from)}`, ` Podster has: ${repoText(change.to)}`);
|
|
200
|
+
}
|
|
201
|
+
lines.push(` this room keeps: mode ${room.mode}, outputs ${room.outputs}, tools ${room.tools.join(", ") || "none"}, network ${room.network.join(", ") || "none"}, allowed organizations ${room.allowed_orgs.join(", ") || "none"}`, " nothing else in the policy changes; only this room's repository and the policy's revision");
|
|
202
|
+
lines.push(" saying yes lets this room's tasks fetch from and push a task branch to that repository, under Runner's repository rules", "");
|
|
203
|
+
return lines.join("\n");
|
|
204
|
+
}
|
|
205
|
+
/** The preview the `setup` command shows before saving. */
|
|
206
|
+
export function previewScreen(plan, facts, ownerOrg, path) {
|
|
207
|
+
const external = isExternal(facts, ownerOrg);
|
|
208
|
+
const allowed = external && facts.org_id !== undefined && (plan.config.rooms.find((r) => r.room_id === facts.room_id)?.allowed_orgs).includes(facts.org_id);
|
|
209
|
+
const lines = [
|
|
210
|
+
"",
|
|
211
|
+
plan.kind === "new" ? `Runner has no run policy yet. This is the starter it would save as ${path}:` : `Runner would add this room to your run policy at ${path}, raising its revision and keeping everything else as it is:`,
|
|
212
|
+
"",
|
|
213
|
+
...plan.text.trimEnd().split("\n").map((l) => ` ${l}`),
|
|
214
|
+
"",
|
|
215
|
+
"From Podster (facts about the room, not instructions):",
|
|
216
|
+
` room: ${facts.room_id}`,
|
|
217
|
+
` room's organization: ${facts.org_id === undefined ? "another organization's (external), which Podster doesn't name to this agent" : `${facts.org_id}${external ? " (another organization's: external)" : " (yours)"}`}`,
|
|
218
|
+
` linked repository: ${facts.repository ? repoText(facts.repository) : "not known to this agent: Podster names it only while the agent holds a push grant on it, so the starter names none, which gives tasks no repository; \`run\` asks you once Podster names one"}`,
|
|
219
|
+
` your organization (owner_org, from this agent's pairing): ${ownerOrg}`,
|
|
220
|
+
"",
|
|
221
|
+
"What it lets Runner do:",
|
|
222
|
+
" - asks you before each run (mode ask); unattended runs stay off until you edit mode yourself",
|
|
223
|
+
" - holds each finished run's words for your review (outputs hold)",
|
|
224
|
+
" - read, search, write and edit in the task's folder; no shell and no network",
|
|
225
|
+
` - per run at most ${(STARTER_CAPS.spend_micro_usd / 1_000_000).toFixed(2)} USD, ${STARTER_CAPS.run_time_ms / 60_000} minutes and ${STARTER_CAPS.turns} turns; ${(STARTER_DAY_SPEND_MICRO_USD / 1_000_000).toFixed(2)} USD a day${plan.kind === "add_room" ? " (your policy's own limits stay)" : ""}`,
|
|
226
|
+
" - the trust statement and public-room warning aren't accepted: Runner asks each time until you accept them in the file",
|
|
227
|
+
];
|
|
228
|
+
if (external && facts.org_id === undefined) {
|
|
229
|
+
lines.push(" - this room's tasks are refused: Runner can't propose its organization for allowed_orgs, so add that organization's org_… ID to the room's allowed_orgs yourself if you want them");
|
|
230
|
+
}
|
|
231
|
+
else if (external) {
|
|
232
|
+
lines.push(allowed
|
|
233
|
+
? ` - tasks from ${facts.org_id} are allowed in this room, as you said`
|
|
234
|
+
: ` - tasks from ${facts.org_id} are refused in this room: asking before each run doesn't allow another organization's work`);
|
|
235
|
+
}
|
|
236
|
+
lines.push("");
|
|
237
|
+
return lines.join("\n");
|
|
238
|
+
}
|
package/build/node/cli.js
CHANGED
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
* Also take Podster's nudges (M7 step 14), off unless both are
|
|
15
15
|
* given: listen on loopback at the port, register the public HTTPS
|
|
16
16
|
* address the owner's proxy or tunnel forwards to, and prove control.
|
|
17
|
+
* setup [--room <ws_…>] [--workspace-root <folder>]
|
|
18
|
+
* Preview a starter run policy from a room's settings (issue 523),
|
|
19
|
+
* and save it only on the owner's typed yes. Never replaces one.
|
|
17
20
|
* stop Stop the Runner running from this home, and any run, at once.
|
|
18
21
|
* status Show what this Runner's record says, by IDs.
|
|
19
22
|
* forget Delete this Runner's keys and record. The agent stays connected in Podster.
|
|
@@ -21,7 +24,7 @@
|
|
|
21
24
|
* Every command takes `--home <folder>`, Runner's own folder (default `~/.podster-runner`). What the owner reads goes to
|
|
22
25
|
* standard output in fixed words; log lines, IDs only, go to standard error.
|
|
23
26
|
*
|
|
24
|
-
* `pair`, `run` and `forget` take the home's lock (decision 227): a second one on the same home refuses while the first
|
|
27
|
+
* `pair`, `run`, `setup` and `forget` take the home's lock (decision 227): a second one on the same home refuses while the first
|
|
25
28
|
* runs. `run` with `--provider-key-file` builds the Claude engine (`claude-engine.ts`: the pinned SDK, the Docker task
|
|
26
29
|
* container, the key's transport), reaps what a previous process left, then opens the lifecycle (`run-command.ts`).
|
|
27
30
|
* Without a key file it opens no lifecycle and accepts nothing it couldn't run.
|
|
@@ -45,6 +48,8 @@ import { clearStop, requestStop, watchStop } from "./local-stop.js";
|
|
|
45
48
|
import { claudeEngine } from "./claude-engine.js";
|
|
46
49
|
import { alongsidePolling, nudgeOptions, openNudge } from "./nudge-command.js";
|
|
47
50
|
import { processTerminal, runInbox } from "./run-command.js";
|
|
51
|
+
import { policyText } from "./policy-file.js";
|
|
52
|
+
import { runSetup } from "./setup-command.js";
|
|
48
53
|
const USAGE = `Podster Runner (M7: pairing, the inbox loop, and tasks through the Claude Agent SDK)
|
|
49
54
|
|
|
50
55
|
pair --agent <agt_…> [--gateway <https://…>] Pair this machine with the agent Podster's pairing started.
|
|
@@ -62,6 +67,13 @@ const USAGE = `Podster Runner (M7: pairing, the inbox loop, and tasks through th
|
|
|
62
67
|
unchanged), and proves it holds the address's secret. An admin of
|
|
63
68
|
the agent's organization then switches the nudge on in Podster.
|
|
64
69
|
A nudge only makes Runner poll sooner. Polling stays on.
|
|
70
|
+
setup [--room <ws_…>] [--workspace-root <folder>]
|
|
71
|
+
Make a starter run policy from a room's settings: its ID, and
|
|
72
|
+
its organization and repository where Podster tells this agent,
|
|
73
|
+
come from Podster, and you approve what's saved. Asks first, holds outputs, no shell
|
|
74
|
+
or network, low limits. Never replaces a policy: adds a room to
|
|
75
|
+
it, or updates a room's repository once you say yes. Default
|
|
76
|
+
workspace root for a new policy: ~/podster-work
|
|
65
77
|
stop Stop the Runner running from this home at once, and any run.
|
|
66
78
|
It polls nothing until you start it again.
|
|
67
79
|
status Show this Runner's record, by IDs.
|
|
@@ -118,7 +130,7 @@ async function main(argv) {
|
|
|
118
130
|
say((await requestStop(home)) ? "Asked the Runner running here to stop. Any run ends at once, and it polls nothing until started again." : "No Runner is running from this home.");
|
|
119
131
|
return 0;
|
|
120
132
|
}
|
|
121
|
-
if (command !== "pair" && command !== "run" && command !== "forget") {
|
|
133
|
+
if (command !== "pair" && command !== "run" && command !== "setup" && command !== "forget") {
|
|
122
134
|
say(USAGE);
|
|
123
135
|
return 2;
|
|
124
136
|
}
|
|
@@ -150,7 +162,7 @@ async function locked(command, args, home, state, nonce) {
|
|
|
150
162
|
// Refused while a run may still be going or budget is reserved; the day's spend is kept (L5 on #458).
|
|
151
163
|
const blocked = await forgetRuns(new FileRunStore(home));
|
|
152
164
|
if (blocked) {
|
|
153
|
-
say(`Runner won't forget this agent while it has ${blocked}. Start it again with \`run\`: it keeps checking a held run until its stop is confirmed, then releases it and settles the budget. If this agent's connection has ended, pair again from Podster first, then \`run\`. Once nothing is held or reserved, \`forget\` goes through.`);
|
|
165
|
+
say(`Runner won't forget this agent while it has ${blocked}. Start it again with \`run\`: it keeps checking a held run until its stop is confirmed, then releases it and settles the budget. If this agent's connection has ended, pair again from Podster first (that makes a new agent with a new ID), then \`run\`. Once nothing is held or reserved, \`forget\` goes through.`);
|
|
154
166
|
return 1;
|
|
155
167
|
}
|
|
156
168
|
await new RunnerStorage(keys.store).deleteAll();
|
|
@@ -200,6 +212,23 @@ async function locked(command, args, home, state, nonce) {
|
|
|
200
212
|
input.close();
|
|
201
213
|
}
|
|
202
214
|
}
|
|
215
|
+
if (command === "setup") {
|
|
216
|
+
const record = await state.load();
|
|
217
|
+
if (!record.gateway)
|
|
218
|
+
throw new Error("This Runner isn't paired yet. Run `pair` first.");
|
|
219
|
+
const poller = await Poller.open({ origin: record.gateway, fetch: globalThis.fetch, secrets: keys.store, state, clock: systemClock, log });
|
|
220
|
+
const room = option(args, "room");
|
|
221
|
+
const root = option(args, "workspace-root");
|
|
222
|
+
return runSetup({
|
|
223
|
+
home,
|
|
224
|
+
poller,
|
|
225
|
+
policy: policyText(home),
|
|
226
|
+
terminal: processTerminal(),
|
|
227
|
+
...(room === undefined ? {} : { room }),
|
|
228
|
+
workspace_root: root === undefined ? join(homedir(), "podster-work") : resolve(root),
|
|
229
|
+
say,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
203
232
|
if (command === "run") {
|
|
204
233
|
// Each failure's raw cause goes to the local diagnostics file only; the terminal explains its code in fixed words.
|
|
205
234
|
const { log, diagnostics } = runLogger(home, (line) => process.stderr.write(`${line}\n`));
|
|
@@ -254,7 +283,7 @@ async function locked(command, args, home, state, nonce) {
|
|
|
254
283
|
await clearStop(home);
|
|
255
284
|
}
|
|
256
285
|
if (outcome === "revoked") {
|
|
257
|
-
say("This agent's connection ended in Podster, so Runner stopped and retired its key. To go on, pair again from Podster.");
|
|
286
|
+
say("This agent's connection ended in Podster, so Runner stopped and retired its key. To go on, pair again from Podster: that makes a new agent with a new ID, to add to its rooms and give its roles and grants again.");
|
|
258
287
|
return 1;
|
|
259
288
|
}
|
|
260
289
|
say("Stopped.");
|
package/build/node/lock.js
CHANGED
|
@@ -25,7 +25,7 @@ export const LOCK_FILE = "run.lock";
|
|
|
25
25
|
const GUARD_FILE = "run.lock.takeover";
|
|
26
26
|
/** How old an unreadable lock, or a takeover guard, must be before it counts as left by a crash. */
|
|
27
27
|
export const STALE_UNREADABLE_MS = 60_000;
|
|
28
|
-
export const LOCK_COMMANDS = ["pair", "run", "forget"];
|
|
28
|
+
export const LOCK_COMMANDS = ["pair", "run", "setup", "forget"];
|
|
29
29
|
export class LockRefused extends Error {
|
|
30
30
|
holder;
|
|
31
31
|
constructor(message, holder = null) {
|
|
@@ -2,8 +2,16 @@
|
|
|
2
2
|
* The owner's run policy on disk: `policy.json` in Runner's home, written by the owner. The lifecycle reads it afresh on
|
|
3
3
|
* every evaluation (L7 on #458), so switching a room's unattended runs off counts at the next evaluation with no
|
|
4
4
|
* restart. A file that's missing or can't be read is no policy, and the policy refuses.
|
|
5
|
+
*
|
|
6
|
+
* Runner writes it only for the owner's `setup` and for a room change the owner approved (issue 523): whole or not at
|
|
7
|
+
* all (a new file, flushed, renamed over the old one, mode 600 in Runner's own folder), and only while the file still
|
|
8
|
+
* holds exactly the text the change was made from, checked once before the new file is written and again just before
|
|
9
|
+
* the rename. After the rename it's read back: if it holds anything but what Runner wrote, another writer got in, and
|
|
10
|
+
* the write reports `raced` so the owner is told and asked again, never left to find out. **A narrow window stays:** an
|
|
11
|
+
* editor that saves between the last check and the rename, and then not again, has its save replaced by Runner's and
|
|
12
|
+
* the read-back can't see it. The README says so.
|
|
5
13
|
*/
|
|
6
|
-
import { readFile } from "node:fs/promises";
|
|
14
|
+
import { chmod, lstat, mkdir, open, readFile, rename, rm } from "node:fs/promises";
|
|
7
15
|
import { join } from "node:path";
|
|
8
16
|
export const POLICY_FILE = "policy.json";
|
|
9
17
|
/** A reader for the lifecycle's `config`: each call reads the file again. */
|
|
@@ -11,3 +19,55 @@ export function policyFile(home) {
|
|
|
11
19
|
const path = join(home, POLICY_FILE);
|
|
12
20
|
return async () => JSON.parse(await readFile(path, "utf8"));
|
|
13
21
|
}
|
|
22
|
+
/** The policy file as text, and a write that happens only while it still holds `expected` (null: while there's none). */
|
|
23
|
+
export function policyText(home) {
|
|
24
|
+
const path = join(home, POLICY_FILE);
|
|
25
|
+
const read = async () => {
|
|
26
|
+
try {
|
|
27
|
+
return await readFile(path, "utf8");
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error.code === "ENOENT")
|
|
31
|
+
return null;
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
// A link, or anything but a plain file, where the policy should be is never written through.
|
|
36
|
+
const plain = async () => {
|
|
37
|
+
const stat = await lstat(path).catch(() => null);
|
|
38
|
+
return stat === null || stat.isFile();
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
path,
|
|
42
|
+
read,
|
|
43
|
+
write: async (text, expected) => {
|
|
44
|
+
if (!(await plain()) || (await read()) !== expected)
|
|
45
|
+
return "changed";
|
|
46
|
+
await mkdir(home, { recursive: true, mode: 0o700 });
|
|
47
|
+
await chmod(home, 0o700);
|
|
48
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
49
|
+
const file = await open(temporary, "w", 0o600);
|
|
50
|
+
try {
|
|
51
|
+
await file.writeFile(text);
|
|
52
|
+
await file.sync();
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
await file.close();
|
|
56
|
+
}
|
|
57
|
+
// Checked again just before the rename, so an edit made while the new file was written isn't replaced.
|
|
58
|
+
if (!(await plain()) || (await read()) !== expected) {
|
|
59
|
+
await rm(temporary, { force: true });
|
|
60
|
+
return "changed";
|
|
61
|
+
}
|
|
62
|
+
await rename(temporary, path);
|
|
63
|
+
const folder = await open(home, "r");
|
|
64
|
+
try {
|
|
65
|
+
await folder.sync();
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
await folder.close();
|
|
69
|
+
}
|
|
70
|
+
return (await read()) === text ? "written" : "raced";
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
package/build/node/prompter.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { markHidden } from "../core/results.js";
|
|
2
2
|
import { QuestionInterrupted } from "../core/roles.js";
|
|
3
|
+
import { changeScreen } from "../core/setup.js";
|
|
3
4
|
/** The most code points of all the inputs shown together. Past this, the prompt can't be approved here. */
|
|
4
5
|
export const SHOWN_CHARS = 16_000;
|
|
5
6
|
/** The most fenced lines, after wrapping. */
|
|
@@ -221,6 +222,51 @@ export class TerminalPrompter {
|
|
|
221
222
|
return "approve";
|
|
222
223
|
return /^no?$/i.test(answer) ? "decline" : "later";
|
|
223
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* A room change (issue 523): a repository Podster now names for a room, or names differently. Only `y` or `yes` writes it; `n` or
|
|
227
|
+
* `no` keeps the policy as it is; anything else leaves it, asked again later. Set aside like a role question when a
|
|
228
|
+
* task or a role invite needs the terminal. Its words are Runner's own around checked IDs and a checked GitHub name.
|
|
229
|
+
*/
|
|
230
|
+
async roomChange(view, signal) {
|
|
231
|
+
if (!this.terminal.inputIsTTY || !this.terminal.outputIsTTY || signal?.aborted)
|
|
232
|
+
return "later";
|
|
233
|
+
// A role question already open keeps the terminal: this one waits its turn rather than setting it aside, so the two
|
|
234
|
+
// never take it from each other in turn.
|
|
235
|
+
if (this.roleQuestion)
|
|
236
|
+
throw new QuestionInterrupted();
|
|
237
|
+
const controller = new AbortController();
|
|
238
|
+
const stop = () => controller.abort();
|
|
239
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
240
|
+
this.terminal.write(`${changeScreen(view.change, view.room)}\n`);
|
|
241
|
+
const question = this.terminal.question("Update this room's repository in Runner's policy? [y = update, n = keep as is, anything else = later] ", controller.signal);
|
|
242
|
+
const open = { controller, done: question.catch(() => undefined) };
|
|
243
|
+
this.roleQuestion = open;
|
|
244
|
+
let answer;
|
|
245
|
+
try {
|
|
246
|
+
answer = (await question).trim();
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
answer = "";
|
|
250
|
+
}
|
|
251
|
+
finally {
|
|
252
|
+
signal?.removeEventListener("abort", stop);
|
|
253
|
+
if (this.roleQuestion === open)
|
|
254
|
+
this.roleQuestion = null;
|
|
255
|
+
}
|
|
256
|
+
if (signal?.aborted)
|
|
257
|
+
return "later";
|
|
258
|
+
if (controller.signal.aborted) {
|
|
259
|
+
this.terminal.write("\nThe room change question is set aside for now. Runner asks it again shortly.\n");
|
|
260
|
+
throw new QuestionInterrupted();
|
|
261
|
+
}
|
|
262
|
+
if (/^y(es)?$/i.test(answer))
|
|
263
|
+
return "approve";
|
|
264
|
+
return /^no?$/i.test(answer) ? "decline" : "later";
|
|
265
|
+
}
|
|
266
|
+
/** A policy write that raced another writer: said in fixed words, so the owner looks before Runner asks again. */
|
|
267
|
+
policyRaced(path) {
|
|
268
|
+
this.terminal.write(`\n${path} changed while Runner was writing it, so Runner's change may not be what's there now. Check the file; Runner reads the room again and asks you again shortly.\n`);
|
|
269
|
+
}
|
|
224
270
|
async review(view, signal) {
|
|
225
271
|
if (!this.terminal.inputIsTTY || !this.terminal.outputIsTTY || signal?.aborted)
|
|
226
272
|
return "later";
|
|
@@ -13,12 +13,13 @@ import { createInterface } from "node:readline/promises";
|
|
|
13
13
|
import { Lifecycle, runWithLifecycle } from "../core/lifecycle.js";
|
|
14
14
|
import { SupervisedAdapter } from "../core/run-interface.js";
|
|
15
15
|
import { FileRunStore } from "./file-runs.js";
|
|
16
|
-
import { policyFile } from "./policy-file.js";
|
|
16
|
+
import { policyFile, policyText } from "./policy-file.js";
|
|
17
17
|
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
21
|
import { RoleInvites } from "../core/roles.js";
|
|
22
|
+
import { RoomFacts } from "../core/room-facts.js";
|
|
22
23
|
/** No engine: `run` records offers and runs nothing. `cli.ts` uses the Claude engine instead when given a key file. */
|
|
23
24
|
export const NO_ENGINE = null;
|
|
24
25
|
/** A run's progress, as a log line: IDs, a fixed kind, a code and the turn count. */
|
|
@@ -35,6 +36,10 @@ export async function runInbox(deps) {
|
|
|
35
36
|
// only ends the loop's wait early so the answer is used soon.
|
|
36
37
|
const bell = deps.bell;
|
|
37
38
|
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() } : {}) });
|
|
39
|
+
// Room changes after setup (issue 523): a repository Podster newly names for a room, or names differently, is asked
|
|
40
|
+
// about on this terminal; nothing is ever removed on what Podster doesn't say. Read off the same policy file, and never
|
|
41
|
+
// waited for before task work.
|
|
42
|
+
const rooms = new RoomFacts({ poller: deps.poller, policy: policyText(deps.home), home: deps.home, prompter, clock: deps.clock, log: deps.log, ...(bell ? { wake: () => bell.ring() } : {}) });
|
|
38
43
|
// Opening asks Podster who this agent is. A brief network failure, a server failure or a rate limit there is waited
|
|
39
44
|
// out like the poll loop's own, never a reason to exit (the 2026-11-21 report); an authority error, a refusal or a
|
|
40
45
|
// policy problem still ends `run` here. The open changes nothing until that answer is in, so trying it again is safe.
|
|
@@ -47,6 +52,7 @@ export async function runInbox(deps) {
|
|
|
47
52
|
...(repository ? { repository } : {}),
|
|
48
53
|
prompter,
|
|
49
54
|
roles,
|
|
55
|
+
rooms,
|
|
50
56
|
clock: deps.clock,
|
|
51
57
|
log: deps.log,
|
|
52
58
|
...(deps.diagnostics ? { diagnostics: deps.diagnostics } : {}),
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `setup` (issue 523): a starter run policy from a workroom's settings, previewed and saved only on the owner's typed yes.
|
|
3
|
+
*
|
|
4
|
+
* Runner reads, as its paired agent, who it is (`get_identity`: `owner_org` is that organization, never the room's) and
|
|
5
|
+
* the chosen room (`get_workspace`'s `setup`: only what the agent could already see; a part left out is unknown). It shows the proposal and
|
|
6
|
+
* what it allows, and writes `policy.json` only after `y` or `yes` at a terminal. It never replaces a policy: a room the
|
|
7
|
+
* policy lacks is added to it with everything else kept; a room it has is checked for a repository change, as `run`
|
|
8
|
+
* does; a file Runner can't use, or one for another organization, is explained and left alone. Facts Podster won't give,
|
|
9
|
+
* or gives in a form that doesn't check out, are explained, never guessed. Nothing here turns on unattended runs, ticks
|
|
10
|
+
* an acknowledgment or allows another organization without the owner's own yes to exactly that.
|
|
11
|
+
*
|
|
12
|
+
* A room's name is someone else's text: shown only when the owner picks a room from the list, marked as untrusted, and
|
|
13
|
+
* never written anywhere.
|
|
14
|
+
*/
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { GatewayError, meaningOf } from "../core/errors.js";
|
|
17
|
+
import { isPolicyId } from "../core/policy.js";
|
|
18
|
+
import { applyRoomChange, changeScreen, factsProblemText, isExternal, planSetup, previewScreen, readRoomFacts, roomChange } from "../core/setup.js";
|
|
19
|
+
import { POLICY_FILE } from "./policy-file.js";
|
|
20
|
+
import { fenced } from "./prompter.js";
|
|
21
|
+
/** The most rooms listed to pick from. */
|
|
22
|
+
const LISTED = 50;
|
|
23
|
+
const yes = (answer) => /^y(es)?$/i.test(answer.trim());
|
|
24
|
+
export async function runSetup(deps) {
|
|
25
|
+
const { terminal, say } = deps;
|
|
26
|
+
const atTerminal = terminal.inputIsTTY && terminal.outputIsTTY;
|
|
27
|
+
const path = join(deps.home, POLICY_FILE);
|
|
28
|
+
const identity = (await deps.poller.request("get_identity"));
|
|
29
|
+
if (identity?.id !== deps.poller.agentId) {
|
|
30
|
+
say("Podster didn't answer as this Runner's agent, so nothing was proposed.");
|
|
31
|
+
return 1;
|
|
32
|
+
}
|
|
33
|
+
const ownerOrg = identity?.org_id;
|
|
34
|
+
if (!isPolicyId(ownerOrg)) {
|
|
35
|
+
say("This agent's organization ID can't be written in a run policy (it must be lower case), so nothing was proposed.");
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
let room = deps.room;
|
|
39
|
+
if (room === undefined) {
|
|
40
|
+
if (!atTerminal) {
|
|
41
|
+
say("Name the room with --room <ws_…>: without a terminal Runner can't ask which.");
|
|
42
|
+
return 2;
|
|
43
|
+
}
|
|
44
|
+
const picked = await pickRoom(deps);
|
|
45
|
+
if (picked === null)
|
|
46
|
+
return 1;
|
|
47
|
+
room = picked;
|
|
48
|
+
}
|
|
49
|
+
if (!isPolicyId(room)) {
|
|
50
|
+
say("A room's ID is lower-case letters, digits, _ and -, such as ws_… from its address in the web app.");
|
|
51
|
+
return 2;
|
|
52
|
+
}
|
|
53
|
+
let answer;
|
|
54
|
+
try {
|
|
55
|
+
answer = await deps.poller.request("get_workspace", { workspace_id: room });
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if (error instanceof GatewayError && meaningOf(error) === "refused") {
|
|
59
|
+
say(`Podster won't show room ${room} to this agent (${error.code}). Add the agent to the room first, then run setup again. Nothing was changed.`);
|
|
60
|
+
return 1;
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
const read = readRoomFacts(room, answer);
|
|
65
|
+
if (!read.ok) {
|
|
66
|
+
say(`${factsProblemText(read.problem)} Nothing was changed.`);
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
const facts = read.facts;
|
|
70
|
+
const existing = await deps.policy.read();
|
|
71
|
+
// The owner's own yes, before anything is proposed, for another organization's room.
|
|
72
|
+
let allowRoomOrg = false;
|
|
73
|
+
const plan0 = planSetup({ existing, owner_org: ownerOrg, facts, workspace_root: deps.workspace_root, allow_room_org: false, runner_home: deps.home });
|
|
74
|
+
if (plan0.kind === "refuse")
|
|
75
|
+
return refuse(say, plan0.reason, plan0.detail, path);
|
|
76
|
+
if (plan0.kind === "room_present")
|
|
77
|
+
return await refreshRoom(deps, facts, plan0.room, existing, path);
|
|
78
|
+
if (isExternal(facts, ownerOrg) && facts.org_id === undefined) {
|
|
79
|
+
// Podster names the organization only where this agent could already see it: never guessed, never asked about.
|
|
80
|
+
say("");
|
|
81
|
+
say(`Room ${facts.room_id} belongs to another organization, which Podster doesn't name to this agent, so Runner can't propose it for allowed_orgs. Its tasks are refused until you add that organization's org_… ID to the room's allowed_orgs yourself.`);
|
|
82
|
+
}
|
|
83
|
+
else if (isExternal(facts, ownerOrg)) {
|
|
84
|
+
say("");
|
|
85
|
+
say(`Room ${facts.room_id} belongs to another organization, ${facts.org_id}. Runner refuses its tasks unless you allow that organization for this room: asking before each run doesn't allow it by itself.`);
|
|
86
|
+
if (atTerminal)
|
|
87
|
+
allowRoomOrg = yes(await terminal.question(`Allow tasks from ${facts.org_id} in this room? [y/N] `));
|
|
88
|
+
}
|
|
89
|
+
const plan = planSetup({ existing, owner_org: ownerOrg, facts, workspace_root: deps.workspace_root, allow_room_org: allowRoomOrg, runner_home: deps.home });
|
|
90
|
+
if (plan.kind === "refuse")
|
|
91
|
+
return refuse(say, plan.reason, plan.detail, path);
|
|
92
|
+
if (plan.kind === "room_present")
|
|
93
|
+
return await refreshRoom(deps, facts, plan.room, existing, path);
|
|
94
|
+
say(previewScreen(plan, facts, ownerOrg, path));
|
|
95
|
+
if (!atTerminal) {
|
|
96
|
+
say("Only a typed yes at a terminal saves a policy, so nothing was saved.");
|
|
97
|
+
return 1;
|
|
98
|
+
}
|
|
99
|
+
if (!yes(await terminal.question(`Save it to ${path}? [y/N] `))) {
|
|
100
|
+
say("Nothing was saved. Your policy is as it was.");
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
if (!saved(say, path, await deps.policy.write(plan.text, existing)))
|
|
104
|
+
return 1;
|
|
105
|
+
say(`Saved ${path}. Unattended runs stay off. Start Runner with \`run\`.`);
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
/** Says why a write wasn't kept; true when it was. A race is never silent: the owner checks the file and runs setup again. */
|
|
109
|
+
function saved(say, path, outcome) {
|
|
110
|
+
if (outcome === "changed")
|
|
111
|
+
say(`${path} changed while you were reading, so nothing was saved. Run setup again.`);
|
|
112
|
+
if (outcome === "raced")
|
|
113
|
+
say(`${path} changed while Runner was writing it, so what's there now may not be what you approved. Check the file, then run setup again.`);
|
|
114
|
+
return outcome === "written";
|
|
115
|
+
}
|
|
116
|
+
function refuse(say, reason, detail, path) {
|
|
117
|
+
if (reason === "existing_invalid")
|
|
118
|
+
say(`Your run policy at ${path} can't be used (${detail}). Runner won't replace it: fix it, or move it away, then run setup again. Nothing was changed.`);
|
|
119
|
+
else if (reason === "owner_org_mismatch")
|
|
120
|
+
say(`Your run policy at ${path} is for another organization (${detail}). Runner won't change it. Nothing was changed.`);
|
|
121
|
+
else
|
|
122
|
+
say(`Runner couldn't make a policy it would load (${detail}). Nothing was saved. If it's the workspace root, choose another with --workspace-root <folder>.`);
|
|
123
|
+
return 1;
|
|
124
|
+
}
|
|
125
|
+
/** A room the policy already has: its repository compared with Podster's, as `run` does. */
|
|
126
|
+
async function refreshRoom(deps, facts, room, existing, path) {
|
|
127
|
+
const { say, terminal } = deps;
|
|
128
|
+
const change = roomChange(room, facts);
|
|
129
|
+
if (change === null) {
|
|
130
|
+
say(facts.repository === undefined
|
|
131
|
+
? `Room ${facts.room_id} is already in your run policy. Podster names its repository only while this agent holds a push grant on it, so there's nothing to compare yet. Nothing was changed.`
|
|
132
|
+
: `Room ${facts.room_id} is already in your run policy, and its repository matches Podster's. Nothing was changed.`);
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
const next = applyRoomChange(existing, change, deps.home);
|
|
136
|
+
if (next === null) {
|
|
137
|
+
say("Runner couldn't apply the change to your policy. Nothing was changed.");
|
|
138
|
+
return 1;
|
|
139
|
+
}
|
|
140
|
+
say(changeScreen(change, room));
|
|
141
|
+
if (!(terminal.inputIsTTY && terminal.outputIsTTY) || !yes(await terminal.question("Update this room's repository in Runner's policy? [y/N] "))) {
|
|
142
|
+
say("Nothing was saved. Your policy is as it was.");
|
|
143
|
+
return 1;
|
|
144
|
+
}
|
|
145
|
+
if (!saved(say, path, await deps.policy.write(next.text, existing)))
|
|
146
|
+
return 1;
|
|
147
|
+
say(`Saved ${path}.`);
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
/** Lists the agent's rooms and asks for one by number. Names are someone else's words, marked as untrusted. */
|
|
151
|
+
async function pickRoom(deps) {
|
|
152
|
+
const { say, terminal } = deps;
|
|
153
|
+
const listed = (await deps.poller.request("list_workspaces"));
|
|
154
|
+
const rooms = (Array.isArray(listed?.workspaces) ? listed.workspaces : [])
|
|
155
|
+
.filter((w) => typeof w === "object" && w !== null && isPolicyId(w.workspace_id))
|
|
156
|
+
.slice(0, LISTED);
|
|
157
|
+
if (rooms.length === 0) {
|
|
158
|
+
say("This agent isn't in any room yet. Add it to a room in Podster, then run setup again.");
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
say("Rooms this agent is in. Each name is someone else's text, shown as data:");
|
|
162
|
+
rooms.forEach((w, i) => {
|
|
163
|
+
say(` ${i + 1}. ${w.workspace_id}`);
|
|
164
|
+
const name = typeof w.workspace_name === "string" ? w.workspace_name.slice(0, 200) : "";
|
|
165
|
+
for (const line of fenced(name, terminal.columns ?? 80).slice(0, 3))
|
|
166
|
+
say(` ${line}`);
|
|
167
|
+
});
|
|
168
|
+
const choice = Number((await terminal.question(`Which room? [1-${rooms.length}] `)).trim());
|
|
169
|
+
if (!Number.isSafeInteger(choice) || choice < 1 || choice > rooms.length) {
|
|
170
|
+
say("No room was chosen. Nothing was changed.");
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
return rooms[choice - 1].workspace_id;
|
|
174
|
+
}
|