monoban 1.8.0 → 1.9.0
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/dist/index.mjs +2087 -422
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { homedir, hostname, tmpdir } from "node:os";
|
|
3
3
|
import path, { basename, delimiter, dirname, isAbsolute, join, resolve, sep } from "node:path";
|
|
4
|
-
import { access, constants, mkdir, mkdtemp, open, readFile, readdir, readlink, realpath, rename, rm, rmdir, stat, symlink, writeFile } from "node:fs/promises";
|
|
4
|
+
import { access, constants, mkdir, mkdtemp, open as open$3, readFile, readdir, readlink, realpath, rename, rm as rm$1, rmdir, stat, symlink, writeFile } from "node:fs/promises";
|
|
5
5
|
import childProcess, { execFile, spawn, spawnSync } from "node:child_process";
|
|
6
6
|
import { EventEmitter } from "node:events";
|
|
7
|
-
import fs, { closeSync, existsSync, openSync, readdirSync, realpathSync } from "node:fs";
|
|
7
|
+
import fs, { closeSync, existsSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
8
8
|
import process$1 from "node:process";
|
|
9
9
|
import { stripVTControlCharacters } from "node:util";
|
|
10
10
|
import { createInterface } from "node:readline/promises";
|
|
@@ -3031,7 +3031,7 @@ function bucketFor(state, inst) {
|
|
|
3031
3031
|
return bucket;
|
|
3032
3032
|
}
|
|
3033
3033
|
let handoff;
|
|
3034
|
-
const open$
|
|
3034
|
+
const open$2 = [];
|
|
3035
3035
|
const memo = {
|
|
3036
3036
|
alloc(_inst, payload, empty) {
|
|
3037
3037
|
const bucket = handoff;
|
|
@@ -3042,7 +3042,7 @@ const memo = {
|
|
|
3042
3042
|
issues: null
|
|
3043
3043
|
};
|
|
3044
3044
|
bucket.set(payload.value, entry);
|
|
3045
|
-
open$
|
|
3045
|
+
open$2.push(entry);
|
|
3046
3046
|
return empty;
|
|
3047
3047
|
},
|
|
3048
3048
|
guard(inst) {
|
|
@@ -3108,10 +3108,10 @@ const memo = {
|
|
|
3108
3108
|
return payload;
|
|
3109
3109
|
}
|
|
3110
3110
|
handoff = bucket;
|
|
3111
|
-
const depth = open$
|
|
3111
|
+
const depth = open$2.length;
|
|
3112
3112
|
const result = base(payload, ctx);
|
|
3113
3113
|
handoff = void 0;
|
|
3114
|
-
const entry = open$
|
|
3114
|
+
const entry = open$2.length > depth ? open$2.pop() : void 0;
|
|
3115
3115
|
if (result instanceof Promise) return result.then((r) => {
|
|
3116
3116
|
if (entry) entry.issues = r.issues.length ? cloneIssues(r.issues) : NO_ISSUES;
|
|
3117
3117
|
return r;
|
|
@@ -5892,6 +5892,119 @@ function linkLabel(link) {
|
|
|
5892
5892
|
return link.url;
|
|
5893
5893
|
}
|
|
5894
5894
|
}
|
|
5895
|
+
// ../../packages/contract/src/loops.ts
|
|
5896
|
+
/**
|
|
5897
|
+
* Agent loops (docs/PLAN-AGENT-LOOPS.md): looping agents a user creates per project, which `monoban runner` runs
|
|
5898
|
+
* through agentpipe. A loop's type is its recipe: a fixed, ordered list of steps, each one agentpipe command. One
|
|
5899
|
+
* pass of a loop is an ordinary run. Their shapes (options, a loop, its create and patch) are in schemas.ts; the
|
|
5900
|
+
* words for a loop's state are @monoban/i18n's `describeLoopState`.
|
|
5901
|
+
*/
|
|
5902
|
+
/**
|
|
5903
|
+
* The recipes and their steps, in order. `deliver` takes a task from a column and delivers it as a merged pull
|
|
5904
|
+
* request; its `review` step is `agentpipe review --fix` (kept by the owner, plan §1.9 S1).
|
|
5905
|
+
* `scavenge` finds problems and files tasks.
|
|
5906
|
+
*/
|
|
5907
|
+
const RECIPES$1 = {
|
|
5908
|
+
deliver: { steps: [
|
|
5909
|
+
"implement",
|
|
5910
|
+
"review",
|
|
5911
|
+
"checks",
|
|
5912
|
+
"feedback",
|
|
5913
|
+
"merge"
|
|
5914
|
+
] },
|
|
5915
|
+
scavenge: { steps: ["scout"] }
|
|
5916
|
+
};
|
|
5917
|
+
const RECIPE_NAMES = Object.keys(RECIPES$1);
|
|
5918
|
+
const range = (min, max) => ({
|
|
5919
|
+
min,
|
|
5920
|
+
max
|
|
5921
|
+
});
|
|
5922
|
+
/** How much a loop may be and take (plan §1.4). The owner confirms them at the mockup (MON-193). */
|
|
5923
|
+
const LOOP_LIMITS = {
|
|
5924
|
+
/** Loops per project. */
|
|
5925
|
+
perProject: 10,
|
|
5926
|
+
name: 64,
|
|
5927
|
+
/** Between the starts of its runs: 5 minutes to a week. */
|
|
5928
|
+
intervalSeconds: range(300, 604800),
|
|
5929
|
+
/** Its options, as stored (bytes of JSON). */
|
|
5930
|
+
optionsBytes: 2048,
|
|
5931
|
+
/** Runs started per 24 hours. */
|
|
5932
|
+
perDay: range(1, 100),
|
|
5933
|
+
/** Per run, in US dollars. */
|
|
5934
|
+
budgetUsd: range(1, 100),
|
|
5935
|
+
/** Per 24 hours, in US dollars. */
|
|
5936
|
+
budgetUsdPerDay: range(1, 1e3),
|
|
5937
|
+
/** Runs in a row that failed or need you before the loop pauses itself. */
|
|
5938
|
+
pauseAfter: range(1, 10),
|
|
5939
|
+
/** deliver: its pull requests that may wait for you before it stops taking tasks. */
|
|
5940
|
+
deliverMaxOpen: range(1, 10),
|
|
5941
|
+
/** deliver: how long its `checks` step may wait for CI, in minutes. */
|
|
5942
|
+
checksMinutes: range(10, 240),
|
|
5943
|
+
/** scavenge: its open tasks before it stops filing. */
|
|
5944
|
+
scavengeMaxOpen: range(1, 20),
|
|
5945
|
+
/** scavenge: what to look for, on one line. */
|
|
5946
|
+
focus: 500
|
|
5947
|
+
};
|
|
5948
|
+
/** What a loop's options are when left out. Merge is on unless the loop says otherwise (plan §1.10.3). */
|
|
5949
|
+
const LOOP_DEFAULTS = {
|
|
5950
|
+
perDay: 5,
|
|
5951
|
+
budgetUsd: 10,
|
|
5952
|
+
budgetUsdPerDay: 50,
|
|
5953
|
+
pauseAfter: 2,
|
|
5954
|
+
merge: true,
|
|
5955
|
+
deliverMaxOpen: 1,
|
|
5956
|
+
checksMinutes: 60,
|
|
5957
|
+
/** deliver: agentpipe's own tier for its review step. */
|
|
5958
|
+
reviewTier: null,
|
|
5959
|
+
scavengeMaxOpen: 5
|
|
5960
|
+
};
|
|
5961
|
+
/** A tier's name, as agentpipe takes it (`--tier NAME`). */
|
|
5962
|
+
const TIER_NAME = /^[a-z][a-z0-9_-]{0,31}$/;
|
|
5963
|
+
/**
|
|
5964
|
+
* The steps a deliver run can continue a pull request from (`POST /v1/loops/{id}/runs {task, from}`): the ones
|
|
5965
|
+
* after it was opened and reviewed. `merge` only when the loop merges.
|
|
5966
|
+
*/
|
|
5967
|
+
const CONTINUE_STEPS = [
|
|
5968
|
+
"checks",
|
|
5969
|
+
"feedback",
|
|
5970
|
+
"merge"
|
|
5971
|
+
];
|
|
5972
|
+
/**
|
|
5973
|
+
* Why a deliver run stops before `merge` (plan §1.12): the loop doesn't merge (`mergeOff`); nobody queued its task
|
|
5974
|
+
* from a browser (`queuedOutside`); or its title or description was written outside a browser after it was queued
|
|
5975
|
+
* (`textChanged`). A loop merges on its own only what a person queued from a browser, and nothing has rewritten since.
|
|
5976
|
+
*/
|
|
5977
|
+
const MERGE_HOLDS = [
|
|
5978
|
+
"mergeOff",
|
|
5979
|
+
"queuedOutside",
|
|
5980
|
+
"textChanged"
|
|
5981
|
+
];
|
|
5982
|
+
/**
|
|
5983
|
+
* Why a loop is paused: you paused it; `pauseAfter` runs in a row failed or needed you; or a run couldn't start
|
|
5984
|
+
* (the folder, agentpipe missing, a refusing precondition: the run says which).
|
|
5985
|
+
*/
|
|
5986
|
+
const PAUSE_REASONS = [
|
|
5987
|
+
"you",
|
|
5988
|
+
"failures",
|
|
5989
|
+
"unstartable"
|
|
5990
|
+
];
|
|
5991
|
+
/**
|
|
5992
|
+
* What a loop is doing, as `loopState()` works it out, in the order it checks them: the first that holds is the
|
|
5993
|
+
* state. `due` means it starts at its runner's next check-in.
|
|
5994
|
+
*/
|
|
5995
|
+
const LOOP_STATES = [
|
|
5996
|
+
"paused",
|
|
5997
|
+
"noRunner",
|
|
5998
|
+
"runnerOffline",
|
|
5999
|
+
"runnerOutdated",
|
|
6000
|
+
"running",
|
|
6001
|
+
"waitingForYou",
|
|
6002
|
+
"dailyLimit",
|
|
6003
|
+
"budget",
|
|
6004
|
+
"waitingForTask",
|
|
6005
|
+
"due",
|
|
6006
|
+
"next"
|
|
6007
|
+
];
|
|
5895
6008
|
// ../../node_modules/.pnpm/fractional-indexing@4.0.0/node_modules/fractional-indexing/src/index.js
|
|
5896
6009
|
const BASE_62_DIGITS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
5897
6010
|
const BASE_52_DIGITS = BASE_62_DIGITS.slice(10);
|
|
@@ -6254,7 +6367,10 @@ const PROBLEM_CODES = [
|
|
|
6254
6367
|
"session_ended",
|
|
6255
6368
|
"email_not_confirmed",
|
|
6256
6369
|
"unsupported_email",
|
|
6257
|
-
"email_not_sent"
|
|
6370
|
+
"email_not_sent",
|
|
6371
|
+
"loops_off",
|
|
6372
|
+
"nothing_to_do",
|
|
6373
|
+
"pr_open"
|
|
6258
6374
|
];
|
|
6259
6375
|
const CODES = new Set(PROBLEM_CODES);
|
|
6260
6376
|
const isString = (v) => typeof v === "string";
|
|
@@ -6861,6 +6977,8 @@ const PageQuerySchema = strictObject({
|
|
|
6861
6977
|
});
|
|
6862
6978
|
/** An agent a runner can run, by name: "agentpipe". */
|
|
6863
6979
|
const AdapterSchema = string().regex(/^[a-z][a-z0-9-]{0,31}$/, "A lowercase name, like agentpipe");
|
|
6980
|
+
/** A loop's recipe a runner can run, by name: "deliver". The server may not know it yet (a newer runner). */
|
|
6981
|
+
const RecipeNameSchema = string().regex(/^[a-z][a-z0-9-]{0,31}$/, "A lowercase name, like deliver");
|
|
6864
6982
|
/** One line of text, no control characters. */
|
|
6865
6983
|
const oneLine$1 = (max) => string().trim().min(1, "Required").max(max).regex(/^[^\u0000-\u001f\u007f]*$/, "One line");
|
|
6866
6984
|
/** A machine that runs agents for you: `monoban runner`, running there (in the background, or in a terminal). */
|
|
@@ -6884,8 +7002,89 @@ strictObject({
|
|
|
6884
7002
|
adapters: array(AdapterSchema).max(8),
|
|
6885
7003
|
version: string().regex(/^[0-9A-Za-z.+-]{1,32}$/).optional(),
|
|
6886
7004
|
/** How often it will ask for work (default 3). */
|
|
6887
|
-
pollSeconds: number$1().int().min(1).max(60).optional()
|
|
7005
|
+
pollSeconds: number$1().int().min(1).max(60).optional(),
|
|
7006
|
+
/** The loops' recipes it can run (docs/PLAN-AGENT-LOOPS.md); none when left out (a runner before loops). */
|
|
7007
|
+
recipes: array(RecipeNameSchema).max(8).optional()
|
|
6888
7008
|
}).meta({ id: "RunnerRegister" });
|
|
7009
|
+
strictObject({
|
|
7010
|
+
recipes: array(RecipeNameSchema).max(8),
|
|
7011
|
+
free: boolean()
|
|
7012
|
+
}).meta({ id: "RunnerHeartbeat" });
|
|
7013
|
+
/**
|
|
7014
|
+
* Agent loops (loops.ts, docs/PLAN-AGENT-LOOPS.md §1.4). A loop's options say how much it takes; each recipe has
|
|
7015
|
+
* its own, and a run of the loop carries a copy of them. The patch shapes have no defaults: the API merges a
|
|
7016
|
+
* patch into the loop's options and checks the result with the full shape.
|
|
7017
|
+
*/
|
|
7018
|
+
const between = ({ min, max }) => number$1().min(min).max(max);
|
|
7019
|
+
const wholeBetween = (limits) => between(limits).int();
|
|
7020
|
+
const loopCommon = {
|
|
7021
|
+
/** Runs it starts per 24 hours. */
|
|
7022
|
+
perDay: wholeBetween(LOOP_LIMITS.perDay),
|
|
7023
|
+
/** What one run may spend, in US dollars. */
|
|
7024
|
+
budgetUsd: between(LOOP_LIMITS.budgetUsd),
|
|
7025
|
+
/** What its runs may spend per 24 hours, in US dollars. */
|
|
7026
|
+
budgetUsdPerDay: between(LOOP_LIMITS.budgetUsdPerDay),
|
|
7027
|
+
/** Runs in a row that failed or need you before it pauses itself. */
|
|
7028
|
+
pauseAfter: wholeBetween(LOOP_LIMITS.pauseAfter)
|
|
7029
|
+
};
|
|
7030
|
+
const deliverFields = {
|
|
7031
|
+
...loopCommon,
|
|
7032
|
+
/** The column it takes tasks from. */
|
|
7033
|
+
column: IdSchema,
|
|
7034
|
+
/** Only tasks with this tag, which it takes off when it takes the task; null: every task in the column. */
|
|
7035
|
+
tag: IdSchema.nullable(),
|
|
7036
|
+
/** Merge each pull request when its checks pass (only a task queued from the browser, plan §1.12). */
|
|
7037
|
+
merge: boolean(),
|
|
7038
|
+
/** Its pull requests that may wait for you before it stops taking tasks. */
|
|
7039
|
+
maxOpen: wholeBetween(LOOP_LIMITS.deliverMaxOpen),
|
|
7040
|
+
/** How long `checks` waits for CI, in minutes. */
|
|
7041
|
+
checksMinutes: wholeBetween(LOOP_LIMITS.checksMinutes),
|
|
7042
|
+
/** The agentpipe tier its review step runs on (`--tier`); null: agentpipe's own. */
|
|
7043
|
+
reviewTier: string().regex(TIER_NAME, "A tier's name, like light").nullable()
|
|
7044
|
+
};
|
|
7045
|
+
const scavengeFields = {
|
|
7046
|
+
...loopCommon,
|
|
7047
|
+
/** What to look for, on one line. */
|
|
7048
|
+
focus: text().min(1, "Required").max(LOOP_LIMITS.focus).regex(/^[^\r\n]*$/, "One line"),
|
|
7049
|
+
/** The column it files tasks in. */
|
|
7050
|
+
column: IdSchema,
|
|
7051
|
+
/** The tag it puts on what it files (and counts its open tasks by). */
|
|
7052
|
+
tag: IdSchema,
|
|
7053
|
+
/** Its open tasks before it stops filing. */
|
|
7054
|
+
maxOpen: wholeBetween(LOOP_LIMITS.scavengeMaxOpen)
|
|
7055
|
+
};
|
|
7056
|
+
/** A run's budget can't be more than the day's, or the loop would never start one. */
|
|
7057
|
+
const budgetFits = (o) => o.budgetUsd === void 0 || o.budgetUsdPerDay === void 0 || o.budgetUsd <= o.budgetUsdPerDay;
|
|
7058
|
+
const BUDGET_FITS = "A run's budget can't be more than the day's";
|
|
7059
|
+
const DeliverOptionsSchema = strictObject({
|
|
7060
|
+
...deliverFields,
|
|
7061
|
+
perDay: deliverFields.perDay.default(LOOP_DEFAULTS.perDay),
|
|
7062
|
+
budgetUsd: deliverFields.budgetUsd.default(LOOP_DEFAULTS.budgetUsd),
|
|
7063
|
+
budgetUsdPerDay: deliverFields.budgetUsdPerDay.default(LOOP_DEFAULTS.budgetUsdPerDay),
|
|
7064
|
+
pauseAfter: deliverFields.pauseAfter.default(LOOP_DEFAULTS.pauseAfter),
|
|
7065
|
+
tag: deliverFields.tag.default(null),
|
|
7066
|
+
merge: deliverFields.merge.default(LOOP_DEFAULTS.merge),
|
|
7067
|
+
maxOpen: deliverFields.maxOpen.default(LOOP_DEFAULTS.deliverMaxOpen),
|
|
7068
|
+
checksMinutes: deliverFields.checksMinutes.default(LOOP_DEFAULTS.checksMinutes),
|
|
7069
|
+
reviewTier: deliverFields.reviewTier.default(LOOP_DEFAULTS.reviewTier)
|
|
7070
|
+
}).refine(budgetFits, {
|
|
7071
|
+
message: BUDGET_FITS,
|
|
7072
|
+
path: ["budgetUsd"]
|
|
7073
|
+
}).meta({ id: "DeliverOptions" });
|
|
7074
|
+
const ScavengeOptionsSchema = strictObject({
|
|
7075
|
+
...scavengeFields,
|
|
7076
|
+
perDay: scavengeFields.perDay.default(LOOP_DEFAULTS.perDay),
|
|
7077
|
+
budgetUsd: scavengeFields.budgetUsd.default(LOOP_DEFAULTS.budgetUsd),
|
|
7078
|
+
budgetUsdPerDay: scavengeFields.budgetUsdPerDay.default(LOOP_DEFAULTS.budgetUsdPerDay),
|
|
7079
|
+
pauseAfter: scavengeFields.pauseAfter.default(LOOP_DEFAULTS.pauseAfter),
|
|
7080
|
+
maxOpen: scavengeFields.maxOpen.default(LOOP_DEFAULTS.scavengeMaxOpen)
|
|
7081
|
+
}).refine(budgetFits, {
|
|
7082
|
+
message: BUDGET_FITS,
|
|
7083
|
+
path: ["budgetUsd"]
|
|
7084
|
+
}).meta({ id: "ScavengeOptions" });
|
|
7085
|
+
/** A loop's options as the API returns them: every one set. */
|
|
7086
|
+
const DeliverOptionsSetSchema = object(deliverFields).meta({ id: "DeliverOptionsSet" });
|
|
7087
|
+
const ScavengeOptionsSetSchema = object(scavengeFields).meta({ id: "ScavengeOptionsSet" });
|
|
6889
7088
|
/** What the agent may do. */
|
|
6890
7089
|
const RunOptionsSchema = strictObject({
|
|
6891
7090
|
/** Open a pull request as a draft, ready for review, or none (finish on a branch). */
|
|
@@ -6918,11 +7117,46 @@ const RunStepSchema = object({
|
|
|
6918
7117
|
/** Why it was skipped or failed. */
|
|
6919
7118
|
message: string().nullable()
|
|
6920
7119
|
}).meta({ id: "RunStep" });
|
|
7120
|
+
/**
|
|
7121
|
+
* What a loop's run was started with (docs/PLAN-AGENT-LOOPS.md §1.4): a copy of the loop's options then, the names
|
|
7122
|
+
* its column and tag had, and for a run that continues a pull request, the step it starts at, the pull request and
|
|
7123
|
+
* the run that opened it. Only the server writes it.
|
|
7124
|
+
*/
|
|
7125
|
+
const LoopRunPlanSchema = object({
|
|
7126
|
+
/** The loop's options when the run was made (its recipe's: DeliverOptionsSet or ScavengeOptionsSet). */
|
|
7127
|
+
options: union([DeliverOptionsSetSchema, ScavengeOptionsSetSchema]),
|
|
7128
|
+
/** deliver: the column it took the task from; scavenge: the column it files in. */
|
|
7129
|
+
columnName: string().nullable(),
|
|
7130
|
+
/** deliver: the tag it took off the task (null: none); scavenge: the tag it puts on what it files. */
|
|
7131
|
+
tagName: string().nullable(),
|
|
7132
|
+
/** The step a continued run starts at; null: from the first. */
|
|
7133
|
+
from: _enum(CONTINUE_STEPS).nullable(),
|
|
7134
|
+
/** The pull request a continued run works on. */
|
|
7135
|
+
prUrl: string().nullable(),
|
|
7136
|
+
/** The run that opened that pull request. */
|
|
7137
|
+
continues: IdSchema.nullable(),
|
|
7138
|
+
/** scavenge: how many tasks it may file (its `maxOpen` less its open tasks); null for deliver. */
|
|
7139
|
+
limit: number$1().int().nonnegative().nullable()
|
|
7140
|
+
}).meta({ id: "LoopRunPlan" });
|
|
6921
7141
|
/** A coding agent working on a task, on one of your runners. */
|
|
6922
7142
|
const TaskRunSchema = object({
|
|
6923
7143
|
id: IdSchema,
|
|
6924
|
-
/** The task ("MON-12"); null once it's deleted. */
|
|
7144
|
+
/** The task ("MON-12"); null once it's deleted, and for a loop's run that has none (a scavenger's). */
|
|
6925
7145
|
ref: string().nullable(),
|
|
7146
|
+
/** The loop it is a pass of (docs/PLAN-AGENT-LOOPS.md); null for a run started on a task, or its loop deleted. */
|
|
7147
|
+
loopId: IdSchema.nullable(),
|
|
7148
|
+
/** The loop's type, which stays after the loop is deleted; null for a run started on a task. */
|
|
7149
|
+
recipe: string().nullable(),
|
|
7150
|
+
/** What a loop's run was started with; null for a run started on a task. */
|
|
7151
|
+
loopRun: LoopRunPlanSchema.nullable(),
|
|
7152
|
+
/**
|
|
7153
|
+
* A deliver loop's run: whether it may merge its pull request on its own (its loop merges, a browser queued its
|
|
7154
|
+
* task, and nothing but a browser has written the task's text since; docs/PLAN-AGENT-LOOPS.md §1.12), read now.
|
|
7155
|
+
* Null for a run that isn't a deliver loop's.
|
|
7156
|
+
*/
|
|
7157
|
+
mayMerge: boolean().nullable(),
|
|
7158
|
+
/** Why it may not (`mergeOff`, `queuedOutside`, `textChanged`); null when it may, or isn't a deliver loop's. */
|
|
7159
|
+
mergeHold: _enum(MERGE_HOLDS).nullable(),
|
|
6926
7160
|
runner: object({
|
|
6927
7161
|
/** Null once the runner is gone. */
|
|
6928
7162
|
id: IdSchema.nullable(),
|
|
@@ -6961,14 +7195,19 @@ const TaskRunSchema = object({
|
|
|
6961
7195
|
}).meta({ id: "TaskRun" });
|
|
6962
7196
|
TaskRunSchema.extend({ steps: array(RunStepSchema) }).meta({ id: "TaskRunDetail" });
|
|
6963
7197
|
/** A run for a runner to start: with what it needs to check the folder (the project's key and repo). */
|
|
6964
|
-
|
|
7198
|
+
/** A run's project, for the runner to check the folder against (its key, and the repository it's linked to). */
|
|
7199
|
+
const RunProjectSchema = object({
|
|
6965
7200
|
key: string(),
|
|
6966
7201
|
repo: string().nullable()
|
|
6967
|
-
}).meta({ id: "RunProject" })
|
|
7202
|
+
}).meta({ id: "RunProject" });
|
|
7203
|
+
const RunToStartSchema = TaskRunSchema.extend({ project: RunProjectSchema }).meta({ id: "RunToStart" });
|
|
7204
|
+
/** Run an agent on a task, on one of your runners. */
|
|
7205
|
+
/** An absolute path on a runner's machine. */
|
|
7206
|
+
const Workdir = string().trim().min(1, "Required").max(RUN_LIMITS.workdir).refine(isAbsolutePath, "An absolute path, like /Users/you/code/project").meta({ pattern: "^/" });
|
|
6968
7207
|
strictObject({
|
|
6969
7208
|
runnerId: IdSchema,
|
|
6970
7209
|
/** An absolute path on the runner's machine: a checkout of the project's linked repository. */
|
|
6971
|
-
workdir:
|
|
7210
|
+
workdir: Workdir,
|
|
6972
7211
|
/** The agent (agents.ts); the runner must have it, and it must take the options (default agentpipe). */
|
|
6973
7212
|
adapter: AdapterSchema.optional(),
|
|
6974
7213
|
mode: _enum(RUN_MODES).default("local"),
|
|
@@ -7035,8 +7274,121 @@ object({
|
|
|
7035
7274
|
/** Queued for it, oldest first (at most 5). */
|
|
7036
7275
|
queued: array(RunToStartSchema),
|
|
7037
7276
|
/** Running on it: one it doesn't know of was left behind; `cancelRequested` asks it to stop. */
|
|
7038
|
-
running: array(TaskRunSchema)
|
|
7277
|
+
running: array(TaskRunSchema),
|
|
7278
|
+
/**
|
|
7279
|
+
* To a runner that runs loops: its deliver loops with pull requests waiting for you, and their folders, where an
|
|
7280
|
+
* idle runner runs `agentpipe ledger sync` (a pull request merged by hand moves its task to Done), once the folder
|
|
7281
|
+
* is a checkout of the project's, as for a run.
|
|
7282
|
+
*/
|
|
7283
|
+
waiting: array(object({
|
|
7284
|
+
loopId: IdSchema,
|
|
7285
|
+
workdir: string(),
|
|
7286
|
+
project: RunProjectSchema
|
|
7287
|
+
}).meta({ id: "LoopWaiting" })).optional()
|
|
7039
7288
|
}).meta({ id: "RunnerWork" });
|
|
7289
|
+
/** At least one option, or the patch would change nothing (the refine, for JSON Schema: minProperties). */
|
|
7290
|
+
const someOption = (o) => Object.keys(o).length > 0;
|
|
7291
|
+
const SOME_OPTION = "Send at least one option to change";
|
|
7292
|
+
const DeliverOptionsPatchSchema = strictObject(deliverFields).partial().refine(someOption, SOME_OPTION).meta({
|
|
7293
|
+
id: "DeliverOptionsPatch",
|
|
7294
|
+
minProperties: 1
|
|
7295
|
+
});
|
|
7296
|
+
const ScavengeOptionsPatchSchema = strictObject(scavengeFields).partial().refine(someOption, SOME_OPTION).meta({
|
|
7297
|
+
id: "ScavengeOptionsPatch",
|
|
7298
|
+
minProperties: 1
|
|
7299
|
+
});
|
|
7300
|
+
/** What a loop is doing (loops.ts `loopState`); the words are @monoban/i18n's `describeLoopState`. */
|
|
7301
|
+
const LoopStateSchema = object({
|
|
7302
|
+
state: _enum(LOOP_STATES),
|
|
7303
|
+
/** When it would start next if nothing else stood in the way. */
|
|
7304
|
+
nextAt: Timestamp.nullable(),
|
|
7305
|
+
why: object({
|
|
7306
|
+
reason: _enum(PAUSE_REASONS).optional(),
|
|
7307
|
+
runner: string().optional(),
|
|
7308
|
+
count: number$1().int().nonnegative().optional(),
|
|
7309
|
+
of: _enum(["pullRequests", "tasks"]).optional(),
|
|
7310
|
+
spent: number$1().nonnegative().optional(),
|
|
7311
|
+
limit: number$1().nonnegative().optional()
|
|
7312
|
+
}).meta({ id: "LoopWhy" })
|
|
7313
|
+
}).meta({ id: "LoopState" });
|
|
7314
|
+
const loopName = text().min(1, "Required").max(LOOP_LIMITS.name);
|
|
7315
|
+
const loopInterval = wholeBetween(LOOP_LIMITS.intervalSeconds);
|
|
7316
|
+
const LoopBase = object({
|
|
7317
|
+
id: IdSchema,
|
|
7318
|
+
name: string(),
|
|
7319
|
+
runner: object({
|
|
7320
|
+
/** Null once the runner is gone (choose another). */
|
|
7321
|
+
id: IdSchema.nullable(),
|
|
7322
|
+
name: string(),
|
|
7323
|
+
online: boolean()
|
|
7324
|
+
}).meta({ id: "LoopRunner" }),
|
|
7325
|
+
workdir: string(),
|
|
7326
|
+
/** Between the starts of its runs. */
|
|
7327
|
+
intervalSeconds: number$1().int(),
|
|
7328
|
+
/** Null: on. Else why it's paused. */
|
|
7329
|
+
paused: _enum(PAUSE_REASONS).nullable(),
|
|
7330
|
+
state: LoopStateSchema,
|
|
7331
|
+
/** Its run going now (queued or running): the step it's in (null before the first) and its task, if it has one. */
|
|
7332
|
+
going: object({
|
|
7333
|
+
runId: IdSchema,
|
|
7334
|
+
step: string().nullable(),
|
|
7335
|
+
ref: string().nullable()
|
|
7336
|
+
}).nullable().meta({ id: "LoopGoing" }),
|
|
7337
|
+
/** Its runs started in the last 24 hours, and what they cost. */
|
|
7338
|
+
last24h: object({
|
|
7339
|
+
runs: number$1().int().nonnegative(),
|
|
7340
|
+
costUsd: number$1().nonnegative()
|
|
7341
|
+
}).meta({ id: "LoopDay" }),
|
|
7342
|
+
version: Version,
|
|
7343
|
+
createdAt: Timestamp,
|
|
7344
|
+
updatedAt: Timestamp
|
|
7345
|
+
});
|
|
7346
|
+
discriminatedUnion("recipe", [LoopBase.extend({
|
|
7347
|
+
recipe: literal("deliver"),
|
|
7348
|
+
options: DeliverOptionsSetSchema
|
|
7349
|
+
}).meta({ id: "DeliverLoop" }), LoopBase.extend({
|
|
7350
|
+
recipe: literal("scavenge"),
|
|
7351
|
+
options: ScavengeOptionsSetSchema
|
|
7352
|
+
}).meta({ id: "ScavengeLoop" })]).meta({ id: "Loop" });
|
|
7353
|
+
const LoopCreateBase = {
|
|
7354
|
+
name: loopName,
|
|
7355
|
+
runnerId: IdSchema,
|
|
7356
|
+
/** A checkout of the project's linked repository on the runner's machine. */
|
|
7357
|
+
workdir: Workdir,
|
|
7358
|
+
intervalSeconds: loopInterval
|
|
7359
|
+
};
|
|
7360
|
+
discriminatedUnion("recipe", [strictObject({
|
|
7361
|
+
...LoopCreateBase,
|
|
7362
|
+
recipe: literal("deliver"),
|
|
7363
|
+
options: DeliverOptionsSchema
|
|
7364
|
+
}), strictObject({
|
|
7365
|
+
...LoopCreateBase,
|
|
7366
|
+
recipe: literal("scavenge"),
|
|
7367
|
+
options: ScavengeOptionsSchema
|
|
7368
|
+
})]).meta({ id: "LoopCreate" });
|
|
7369
|
+
strictObject({
|
|
7370
|
+
name: loopName.optional(),
|
|
7371
|
+
runnerId: IdSchema.optional(),
|
|
7372
|
+
workdir: Workdir.optional(),
|
|
7373
|
+
intervalSeconds: loopInterval.optional(),
|
|
7374
|
+
options: union([DeliverOptionsPatchSchema, ScavengeOptionsPatchSchema]).optional(),
|
|
7375
|
+
paused: boolean().optional()
|
|
7376
|
+
}).refine((patch) => Object.keys(patch).length > 0, "Send at least one field to change").meta({
|
|
7377
|
+
id: "LoopPatch",
|
|
7378
|
+
minProperties: 1
|
|
7379
|
+
});
|
|
7380
|
+
strictObject({
|
|
7381
|
+
/** The task's number in the loop's project (12 for MON-12). */
|
|
7382
|
+
task: number$1().int().min(1).max(2147483647).optional(),
|
|
7383
|
+
/** Continue the task's pull request from this step (`merge` only when the loop merges); needs `task`. */
|
|
7384
|
+
from: _enum(CONTINUE_STEPS).optional()
|
|
7385
|
+
}).refine((body) => body.from === void 0 || body.task !== void 0, {
|
|
7386
|
+
message: "Name the task whose pull request to continue",
|
|
7387
|
+
path: ["from"]
|
|
7388
|
+
}).meta({
|
|
7389
|
+
id: "LoopRunCreate",
|
|
7390
|
+
dependentRequired: { from: ["task"] }
|
|
7391
|
+
});
|
|
7040
7392
|
PageQuerySchema.extend({
|
|
7041
7393
|
from: DaySchema.describe("The first day (the client's today, for Today)"),
|
|
7042
7394
|
to: DaySchema.optional().describe("The last day (`from` when left out); at most 62 days after `from`"),
|
|
@@ -7770,7 +8122,7 @@ function archivedByTime(task, archiveAfterDays, now = Date.now()) {
|
|
|
7770
8122
|
}
|
|
7771
8123
|
// src/version.ts
|
|
7772
8124
|
/** This CLI's version, from package.json (set at build time by tsdown, and by vitest in tests). */
|
|
7773
|
-
const VERSION = "1.
|
|
8125
|
+
const VERSION = "1.9.0";
|
|
7774
8126
|
/** Sent as X-Monoban-Client, and shown in Settings › CLI sessions. */
|
|
7775
8127
|
const CLIENT = `cli/${VERSION}`;
|
|
7776
8128
|
// src/api.ts
|
|
@@ -7856,7 +8208,7 @@ var FileStore = class {
|
|
|
7856
8208
|
}
|
|
7857
8209
|
async write(all) {
|
|
7858
8210
|
if (Object.keys(all).length === 0) {
|
|
7859
|
-
await rm(this.path, { force: true });
|
|
8211
|
+
await rm$1(this.path, { force: true });
|
|
7860
8212
|
return;
|
|
7861
8213
|
}
|
|
7862
8214
|
await mkdir(this.dir, {
|
|
@@ -7940,7 +8292,7 @@ async function openStore(options) {
|
|
|
7940
8292
|
return file;
|
|
7941
8293
|
}
|
|
7942
8294
|
}
|
|
7943
|
-
// ../../node_modules/.pnpm/commander@15.
|
|
8295
|
+
// ../../node_modules/.pnpm/commander@15.1.0/node_modules/commander/lib/error.js
|
|
7944
8296
|
/**
|
|
7945
8297
|
* CommanderError class
|
|
7946
8298
|
*/
|
|
@@ -7974,7 +8326,7 @@ var InvalidArgumentError = class extends CommanderError {
|
|
|
7974
8326
|
this.name = this.constructor.name;
|
|
7975
8327
|
}
|
|
7976
8328
|
};
|
|
7977
|
-
// ../../node_modules/.pnpm/commander@15.
|
|
8329
|
+
// ../../node_modules/.pnpm/commander@15.1.0/node_modules/commander/lib/argument.js
|
|
7978
8330
|
var Argument = class {
|
|
7979
8331
|
/**
|
|
7980
8332
|
* Initialize a new command argument with the given name and description.
|
|
@@ -8092,7 +8444,7 @@ function humanReadableArgName(arg) {
|
|
|
8092
8444
|
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
8093
8445
|
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
8094
8446
|
}
|
|
8095
|
-
// ../../node_modules/.pnpm/commander@15.
|
|
8447
|
+
// ../../node_modules/.pnpm/commander@15.1.0/node_modules/commander/lib/help.js
|
|
8096
8448
|
/**
|
|
8097
8449
|
* TypeScript import types for JSDoc, used by Visual Studio Code IntelliSense and `npm run typescript-checkJS`
|
|
8098
8450
|
* https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#import-types
|
|
@@ -8160,8 +8512,8 @@ var Help = class {
|
|
|
8160
8512
|
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
8161
8513
|
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
8162
8514
|
if (!removeShort && !removeLong) visibleOptions.push(helpOption);
|
|
8163
|
-
else if (helpOption.long && !removeLong) visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
8164
|
-
else if (helpOption.short && !removeShort) visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
8515
|
+
else if (helpOption.long && !removeLong) visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description).helpGroup(helpOption.helpGroupHeading));
|
|
8516
|
+
else if (helpOption.short && !removeShort) visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description).helpGroup(helpOption.helpGroupHeading));
|
|
8165
8517
|
}
|
|
8166
8518
|
if (this.sortOptions) visibleOptions.sort(this.compareOptions);
|
|
8167
8519
|
return visibleOptions;
|
|
@@ -8566,7 +8918,7 @@ var Help = class {
|
|
|
8566
8918
|
return wrappedLines.join("\n");
|
|
8567
8919
|
}
|
|
8568
8920
|
};
|
|
8569
|
-
// ../../node_modules/.pnpm/commander@15.
|
|
8921
|
+
// ../../node_modules/.pnpm/commander@15.1.0/node_modules/commander/lib/option.js
|
|
8570
8922
|
var Option = class {
|
|
8571
8923
|
/**
|
|
8572
8924
|
* Initialize a new `Option` with the given `flags` and `description`.
|
|
@@ -8579,7 +8931,7 @@ var Option = class {
|
|
|
8579
8931
|
this.description = description || "";
|
|
8580
8932
|
this.required = flags.includes("<");
|
|
8581
8933
|
this.optional = flags.includes("[");
|
|
8582
|
-
this.variadic = /\
|
|
8934
|
+
this.variadic = /\p{ID_Continue}\.\.\.[>\]]$/u.test(flags);
|
|
8583
8935
|
this.mandatory = false;
|
|
8584
8936
|
const optionFlags = splitOptionFlags(flags);
|
|
8585
8937
|
this.short = optionFlags.shortFlag;
|
|
@@ -8863,7 +9215,7 @@ function splitOptionFlags(flags) {
|
|
|
8863
9215
|
longFlag
|
|
8864
9216
|
};
|
|
8865
9217
|
}
|
|
8866
|
-
// ../../node_modules/.pnpm/commander@15.
|
|
9218
|
+
// ../../node_modules/.pnpm/commander@15.1.0/node_modules/commander/lib/suggestSimilar.js
|
|
8867
9219
|
const maxDistance = 3;
|
|
8868
9220
|
function editDistance(a, b) {
|
|
8869
9221
|
if (Math.abs(a.length - b.length) > maxDistance) return Math.max(a.length, b.length);
|
|
@@ -8914,7 +9266,7 @@ function suggestSimilar(word, candidates) {
|
|
|
8914
9266
|
if (similar.length === 1) return `\n(Did you mean ${similar[0]}?)`;
|
|
8915
9267
|
return "";
|
|
8916
9268
|
}
|
|
8917
|
-
// ../../node_modules/.pnpm/commander@15.
|
|
9269
|
+
// ../../node_modules/.pnpm/commander@15.1.0/node_modules/commander/lib/command.js
|
|
8918
9270
|
var Command = class Command extends EventEmitter {
|
|
8919
9271
|
/**
|
|
8920
9272
|
* Initialize a new `Command`.
|
|
@@ -9664,7 +10016,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
9664
10016
|
getOptionValueSourceWithGlobals(key) {
|
|
9665
10017
|
let source;
|
|
9666
10018
|
this._getCommandAndAncestors().forEach((cmd) => {
|
|
9667
|
-
if (cmd.
|
|
10019
|
+
if (Object.hasOwn(cmd._optionValueSources, key)) source = cmd.getOptionValueSource(key);
|
|
9668
10020
|
});
|
|
9669
10021
|
return source;
|
|
9670
10022
|
}
|
|
@@ -10173,7 +10525,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
10173
10525
|
return arg.length > 1 && arg[0] === "-";
|
|
10174
10526
|
}
|
|
10175
10527
|
const negativeNumberArg = (arg) => {
|
|
10176
|
-
if (!/^-(\d+|\d*\.\d+)(
|
|
10528
|
+
if (!/^-(\d+|\d*\.\d+)([eE][+-]?\d+)?$/.test(arg)) return false;
|
|
10177
10529
|
return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
|
|
10178
10530
|
};
|
|
10179
10531
|
let activeVariadicOption = null;
|
|
@@ -10573,7 +10925,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
10573
10925
|
* (This does not override a group set directly on the subcommand using .helpGroup().)
|
|
10574
10926
|
*
|
|
10575
10927
|
* @example
|
|
10576
|
-
* program.commandsGroup('Development Commands:);
|
|
10928
|
+
* program.commandsGroup('Development Commands:');
|
|
10577
10929
|
* program.command('watch')...
|
|
10578
10930
|
* program.command('lint')...
|
|
10579
10931
|
* ...
|
|
@@ -10742,7 +11094,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
10742
11094
|
* Pass in false to disable the built-in help option.
|
|
10743
11095
|
*
|
|
10744
11096
|
* @example
|
|
10745
|
-
* program.helpOption('-?, --help' 'show help'); // customise
|
|
11097
|
+
* program.helpOption('-?, --help', 'show help'); // customise
|
|
10746
11098
|
* program.helpOption(false); // disable
|
|
10747
11099
|
*
|
|
10748
11100
|
* @param {(string | boolean)} flags
|
|
@@ -10864,12 +11216,12 @@ function incrementNodeInspectorPort(args) {
|
|
|
10864
11216
|
let debugHost = "127.0.0.1";
|
|
10865
11217
|
let debugPort = "9229";
|
|
10866
11218
|
let match;
|
|
10867
|
-
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) debugOption = match[1];
|
|
10868
|
-
else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
11219
|
+
if ((match = arg.match(/^(--inspect(-brk|-wait)?)$/)) !== null) debugOption = match[1];
|
|
11220
|
+
else if ((match = arg.match(/^(--inspect(-brk|-port|-wait)?)=(\[[^\]]+\]|[^:]+)$/)) !== null) {
|
|
10869
11221
|
debugOption = match[1];
|
|
10870
11222
|
if (/^\d+$/.test(match[3])) debugPort = match[3];
|
|
10871
11223
|
else debugHost = match[3];
|
|
10872
|
-
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
11224
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port|-wait)?)=(\[[^\]]+\]|[^:]+):(\d+)$/)) !== null) {
|
|
10873
11225
|
debugOption = match[1];
|
|
10874
11226
|
debugHost = match[3];
|
|
10875
11227
|
debugPort = match[4];
|
|
@@ -10903,19 +11255,19 @@ async function withLock(path, fn, { staleMs = 3e4, timeoutMs = 45e3, sleep = wai
|
|
|
10903
11255
|
const deadline = Date.now() + timeoutMs;
|
|
10904
11256
|
for (;;) {
|
|
10905
11257
|
try {
|
|
10906
|
-
await (await open(path, "wx", 384)).close();
|
|
11258
|
+
await (await open$3(path, "wx", 384)).close();
|
|
10907
11259
|
break;
|
|
10908
11260
|
} catch (err) {
|
|
10909
11261
|
if (err.code !== "EEXIST") throw err;
|
|
10910
11262
|
}
|
|
10911
|
-
if (await stat(path).then((s) => Date.now() - s.mtimeMs, () => 0) > staleMs) await rm(path, { force: true });
|
|
11263
|
+
if (await stat(path).then((s) => Date.now() - s.mtimeMs, () => 0) > staleMs) await rm$1(path, { force: true });
|
|
10912
11264
|
else if (Date.now() > deadline) throw new Error(busy);
|
|
10913
11265
|
else await sleep(100);
|
|
10914
11266
|
}
|
|
10915
11267
|
try {
|
|
10916
11268
|
return await fn();
|
|
10917
11269
|
} finally {
|
|
10918
|
-
await rm(path, { force: true });
|
|
11270
|
+
await rm$1(path, { force: true });
|
|
10919
11271
|
}
|
|
10920
11272
|
}
|
|
10921
11273
|
const wait$1 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -11055,7 +11407,7 @@ async function editInEditor(text, name, env = process.env) {
|
|
|
11055
11407
|
if (result.error || result.status !== 0) throw new CliError(`The editor (${editor}) didn't exit cleanly, so nothing changed.`);
|
|
11056
11408
|
return await readFile(file, "utf8");
|
|
11057
11409
|
} finally {
|
|
11058
|
-
await rm(dir, {
|
|
11410
|
+
await rm$1(dir, {
|
|
11059
11411
|
recursive: true,
|
|
11060
11412
|
force: true
|
|
11061
11413
|
});
|
|
@@ -11222,10 +11574,10 @@ function style(enabled) {
|
|
|
11222
11574
|
color: (color, s) => sgr(ANSI[color], 39)(s)
|
|
11223
11575
|
};
|
|
11224
11576
|
}
|
|
11225
|
-
const DAY = 864e5;
|
|
11577
|
+
const DAY$1 = 864e5;
|
|
11226
11578
|
/** How long ago, in a few characters: "today", "3d", "5mo", "2y". */
|
|
11227
11579
|
function age$1(iso, now = Date.now()) {
|
|
11228
|
-
const days = Math.floor((now - new Date(iso).getTime()) / DAY);
|
|
11580
|
+
const days = Math.floor((now - new Date(iso).getTime()) / DAY$1);
|
|
11229
11581
|
if (days < 1) return "today";
|
|
11230
11582
|
if (days < 60) return `${days}d`;
|
|
11231
11583
|
if (days < 730) return `${Math.floor(days / 30)}mo`;
|
|
@@ -11315,8 +11667,8 @@ const RELEASES = `https://github.com/thiagodmont/homebrew-tap/releases`;
|
|
|
11315
11667
|
* agentpipe comes with a new monoban: change these three lines (from the release's checksums.txt) and release.
|
|
11316
11668
|
*/
|
|
11317
11669
|
const AGENTPIPE = {
|
|
11318
|
-
version: "0.
|
|
11319
|
-
wheelSha256: "
|
|
11670
|
+
version: "0.8.0",
|
|
11671
|
+
wheelSha256: "e1e92ec985827359abd4fbb71c54ebcbdaf5636e810695b2ef321c64a7e20c26",
|
|
11320
11672
|
requirementsSha256: "41a8d073b0087efb80efafeb6a2b4750340d0f64920159cd4c723ed9167d0a98"
|
|
11321
11673
|
};
|
|
11322
11674
|
const agentpipeWheel = (version) => `agentpipe-${version}-py3-none-any.whl`;
|
|
@@ -11430,7 +11782,7 @@ async function latestVersion(ctx) {
|
|
|
11430
11782
|
async function upgrade(ctx, options, kind = thisInstall()) {
|
|
11431
11783
|
const latest = await latestVersion(ctx);
|
|
11432
11784
|
const { how, command } = UPGRADE[kind];
|
|
11433
|
-
const outdated = latest !== null && newer(latest, "1.
|
|
11785
|
+
const outdated = latest !== null && newer(latest, "1.9.0");
|
|
11434
11786
|
if (options.json) {
|
|
11435
11787
|
ctx.out(JSON.stringify({
|
|
11436
11788
|
version: VERSION,
|
|
@@ -11575,7 +11927,7 @@ async function findUv(ctx, run, home, target, uvPin) {
|
|
|
11575
11927
|
const archive = join(home, "downloads", `uv-${target}.tar.gz`);
|
|
11576
11928
|
await writeFile(archive, await download(ctx, uvArchive(target, uvPin.version), uvPin.sha256[target]));
|
|
11577
11929
|
const unpacked = join(home, "downloads", "uv");
|
|
11578
|
-
await rm(unpacked, {
|
|
11930
|
+
await rm$1(unpacked, {
|
|
11579
11931
|
recursive: true,
|
|
11580
11932
|
force: true
|
|
11581
11933
|
});
|
|
@@ -11634,7 +11986,7 @@ async function installAgentpipe(ctx, options = {}, deps = {}) {
|
|
|
11634
11986
|
await writeFile(lock, `${new TextDecoder().decode(requirements).trimEnd()}\nagentpipe @ ${pathToFileURL(wheel).href} --hash=sha256:${pin.wheelSha256}\n`);
|
|
11635
11987
|
ctx.err("Installing Python 3.12 and agentpipe's dependencies (a minute or two the first time)…");
|
|
11636
11988
|
const dir = join(home, "versions", version);
|
|
11637
|
-
await rm(dir, {
|
|
11989
|
+
await rm$1(dir, {
|
|
11638
11990
|
recursive: true,
|
|
11639
11991
|
force: true
|
|
11640
11992
|
});
|
|
@@ -11662,18 +12014,18 @@ async function installAgentpipe(ctx, options = {}, deps = {}) {
|
|
|
11662
12014
|
});
|
|
11663
12015
|
if (said.code !== 0 || !said.stdout.includes(`agentpipe ${version}`)) throw new CliError(`agentpipe ${version} was installed but doesn't run: ${(said.stderr || said.stdout).trim()}`);
|
|
11664
12016
|
const link = join(home, "current.new");
|
|
11665
|
-
await rm(link, { force: true });
|
|
12017
|
+
await rm$1(link, { force: true });
|
|
11666
12018
|
await symlink(join("versions", version), link);
|
|
11667
12019
|
await rename(link, join(home, "current"));
|
|
11668
|
-
for (const old of await readdir(join(home, "versions"))) if (old !== version && old !== before) await rm(join(home, "versions", old), {
|
|
12020
|
+
for (const old of await readdir(join(home, "versions"))) if (old !== version && old !== before) await rm$1(join(home, "versions", old), {
|
|
11669
12021
|
recursive: true,
|
|
11670
12022
|
force: true
|
|
11671
12023
|
});
|
|
11672
|
-
await rm(join(home, "cache"), {
|
|
12024
|
+
await rm$1(join(home, "cache"), {
|
|
11673
12025
|
recursive: true,
|
|
11674
12026
|
force: true
|
|
11675
12027
|
});
|
|
11676
|
-
await rm(join(home, "downloads"), {
|
|
12028
|
+
await rm$1(join(home, "downloads"), {
|
|
11677
12029
|
recursive: true,
|
|
11678
12030
|
force: true
|
|
11679
12031
|
});
|
|
@@ -11738,7 +12090,7 @@ async function uninstall(ctx, options) {
|
|
|
11738
12090
|
const home = agentpipeHome(ctx.env);
|
|
11739
12091
|
if (!existsSync(home)) return ctx.out("agentpipe isn't installed by monoban: nothing to remove.");
|
|
11740
12092
|
if (!options.yes && !await ctx.confirm(`Remove agentpipe (${home})?`)) throw new CliError("Left as it is (--yes removes it without asking).", EXIT.usage);
|
|
11741
|
-
await rm(home, {
|
|
12093
|
+
await rm$1(home, {
|
|
11742
12094
|
recursive: true,
|
|
11743
12095
|
force: true
|
|
11744
12096
|
});
|
|
@@ -11771,7 +12123,8 @@ function fileProblem(v) {
|
|
|
11771
12123
|
"allow",
|
|
11772
12124
|
"confirm",
|
|
11773
12125
|
"agents",
|
|
11774
|
-
"adapters"
|
|
12126
|
+
"adapters",
|
|
12127
|
+
"loops"
|
|
11775
12128
|
];
|
|
11776
12129
|
const unknown = Object.keys(f).find((k) => !known.includes(k));
|
|
11777
12130
|
if (unknown) return `${unknown} isn't a setting (${known.join(", ")})`;
|
|
@@ -11800,6 +12153,20 @@ function fileProblem(v) {
|
|
|
11800
12153
|
if (agent.args !== void 0 && !(Array.isArray(agent.args) && agent.args.every((a) => typeof a === "string"))) return `adapters.${name}.args: a list of arguments`;
|
|
11801
12154
|
}
|
|
11802
12155
|
}
|
|
12156
|
+
if (f.loops !== void 0) {
|
|
12157
|
+
if (!f.loops || typeof f.loops !== "object" || Array.isArray(f.loops)) return "loops: an object";
|
|
12158
|
+
const loops = f.loops;
|
|
12159
|
+
const settings = [
|
|
12160
|
+
"enabled",
|
|
12161
|
+
"merge",
|
|
12162
|
+
"maxUsdPerDay"
|
|
12163
|
+
];
|
|
12164
|
+
const extra = Object.keys(loops).find((k) => !settings.includes(k));
|
|
12165
|
+
if (extra) return `loops.${extra} isn't a setting (${settings.join(", ")})`;
|
|
12166
|
+
for (const key of ["enabled", "merge"]) if (loops[key] !== void 0 && typeof loops[key] !== "boolean") return `loops.${key}: true or false`;
|
|
12167
|
+
const max = loops.maxUsdPerDay;
|
|
12168
|
+
if (max !== void 0 && !(typeof max === "number" && max >= 1 && max <= 1e4)) return "loops.maxUsdPerDay: US dollars, 1 to 10000";
|
|
12169
|
+
}
|
|
11803
12170
|
return null;
|
|
11804
12171
|
}
|
|
11805
12172
|
const RUNNER_FILE = "runner.json";
|
|
@@ -11853,9 +12220,109 @@ async function runnerSettings(dir, flags, env, hostname) {
|
|
|
11853
12220
|
commands,
|
|
11854
12221
|
args,
|
|
11855
12222
|
allowFullAccess: flags.allowFullAccess ?? file.adapters?.codex?.allowFullAccess ?? false,
|
|
11856
|
-
agentpipeBudgetUsd: file.adapters?.agentpipe?.budgetUsd ?? 10
|
|
12223
|
+
agentpipeBudgetUsd: file.adapters?.agentpipe?.budgetUsd ?? 10,
|
|
12224
|
+
loops: {
|
|
12225
|
+
enabled: flags.loops !== false && (file.loops?.enabled ?? true),
|
|
12226
|
+
merge: file.loops?.merge ?? true,
|
|
12227
|
+
maxUsdPerDay: file.loops?.maxUsdPerDay ?? 100
|
|
12228
|
+
}
|
|
12229
|
+
};
|
|
12230
|
+
}
|
|
12231
|
+
// src/runner/process.ts
|
|
12232
|
+
const defaultSpawn = spawn;
|
|
12233
|
+
const TAIL = 20;
|
|
12234
|
+
function startProcess({ command, args, cwd, env, stdin, onLine, spawn = defaultSpawn, graceMs = 1e4 }) {
|
|
12235
|
+
let child;
|
|
12236
|
+
let exited = false;
|
|
12237
|
+
const timers = [];
|
|
12238
|
+
const signal = (sig) => {
|
|
12239
|
+
if (!child || exited) return;
|
|
12240
|
+
try {
|
|
12241
|
+
if (child.pid) process.kill(-child.pid, sig);
|
|
12242
|
+
else child.kill(sig);
|
|
12243
|
+
} catch {
|
|
12244
|
+
child.kill(sig);
|
|
12245
|
+
}
|
|
12246
|
+
};
|
|
12247
|
+
return {
|
|
12248
|
+
done: new Promise((resolve) => {
|
|
12249
|
+
try {
|
|
12250
|
+
child = spawn(command, args, {
|
|
12251
|
+
cwd,
|
|
12252
|
+
env,
|
|
12253
|
+
detached: true
|
|
12254
|
+
});
|
|
12255
|
+
} catch (err) {
|
|
12256
|
+
resolve({
|
|
12257
|
+
code: null,
|
|
12258
|
+
spawnError: `Couldn't start ${command}: ${err.message}`,
|
|
12259
|
+
lastError: null
|
|
12260
|
+
});
|
|
12261
|
+
return;
|
|
12262
|
+
}
|
|
12263
|
+
let spawnError = null;
|
|
12264
|
+
const tail = [];
|
|
12265
|
+
child.on("error", (err) => {
|
|
12266
|
+
spawnError = err.code === "ENOENT" ? `${command} isn't installed here (or isn't on the runner's PATH).` : `${command} failed: ${err.message}`;
|
|
12267
|
+
});
|
|
12268
|
+
if (child.stdin) {
|
|
12269
|
+
child.stdin.on("error", () => {});
|
|
12270
|
+
child.stdin.end(stdin ?? "");
|
|
12271
|
+
}
|
|
12272
|
+
if (child.stdout) createInterface$1({ input: child.stdout }).on("line", onLine);
|
|
12273
|
+
if (child.stderr) createInterface$1({ input: child.stderr }).on("line", (line) => {
|
|
12274
|
+
if (!line.trim()) return;
|
|
12275
|
+
tail.push(line.trim());
|
|
12276
|
+
if (tail.length > TAIL) tail.shift();
|
|
12277
|
+
});
|
|
12278
|
+
child.on("close", (code) => {
|
|
12279
|
+
exited = true;
|
|
12280
|
+
for (const t of timers) clearTimeout(t);
|
|
12281
|
+
resolve({
|
|
12282
|
+
code,
|
|
12283
|
+
spawnError,
|
|
12284
|
+
lastError: tail.at(-1) ?? null
|
|
12285
|
+
});
|
|
12286
|
+
});
|
|
12287
|
+
}),
|
|
12288
|
+
stop: () => {
|
|
12289
|
+
signal("SIGINT");
|
|
12290
|
+
timers.push(setTimeout(() => signal("SIGTERM"), graceMs));
|
|
12291
|
+
timers.push(setTimeout(() => signal("SIGKILL"), graceMs * 2));
|
|
12292
|
+
},
|
|
12293
|
+
interrupt: () => {
|
|
12294
|
+
if (child && !exited) child.kill("SIGINT");
|
|
12295
|
+
},
|
|
12296
|
+
terminate: () => {
|
|
12297
|
+
if (!child || exited) return;
|
|
12298
|
+
child.kill("SIGTERM");
|
|
12299
|
+
timers.push(setTimeout(() => signal("SIGKILL"), graceMs * 3));
|
|
12300
|
+
},
|
|
12301
|
+
pid: () => child?.pid ?? null
|
|
11857
12302
|
};
|
|
11858
12303
|
}
|
|
12304
|
+
/** The first version number a command prints for `--version` ("2.1.300 (Claude Code)" → 2.1.300), or null. */
|
|
12305
|
+
function versionOf(command, env = process.env) {
|
|
12306
|
+
return new Promise((resolve) => {
|
|
12307
|
+
execFile(command, ["--version"], {
|
|
12308
|
+
timeout: 15e3,
|
|
12309
|
+
env
|
|
12310
|
+
}, (err, stdout, stderr) => {
|
|
12311
|
+
if (err) return resolve(null);
|
|
12312
|
+
resolve(/\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?/.exec(`${stdout} ${stderr}`)?.[0] ?? null);
|
|
12313
|
+
});
|
|
12314
|
+
});
|
|
12315
|
+
}
|
|
12316
|
+
/** Whether version `a` is at least `b` (numbers only: 2.1.259). */
|
|
12317
|
+
function atLeast(a, b) {
|
|
12318
|
+
const parts = (v) => v.split(/[-+]/)[0]?.split(".").map(Number) ?? [];
|
|
12319
|
+
const [x, y] = [parts(a), parts(b)];
|
|
12320
|
+
for (let i = 0; i < Math.max(x.length, y.length); i++) {
|
|
12321
|
+
const d = (x[i] ?? 0) - (y[i] ?? 0);
|
|
12322
|
+
if (d) return d > 0;
|
|
12323
|
+
}
|
|
12324
|
+
return true;
|
|
12325
|
+
}
|
|
11859
12326
|
// src/runner/agents/agentpipe.ts
|
|
11860
12327
|
/** agentpipe's step statuses that monoban has too; the others (budget_exceeded, max_turns…) are failures. */
|
|
11861
12328
|
const SAME = [
|
|
@@ -11876,6 +12343,26 @@ const SAYS = {
|
|
|
11876
12343
|
refused: "It couldn't start",
|
|
11877
12344
|
nothing_to_do: "There was nothing to do"
|
|
11878
12345
|
};
|
|
12346
|
+
/**
|
|
12347
|
+
* What `ship.end`'s state means for the step (`ship --no-merge`, and `address --ship`): it hands back a green pull
|
|
12348
|
+
* request (`ready_to_merge`), or parks it for a person, or was stopped. `merged` only without `--no-merge`.
|
|
12349
|
+
*/
|
|
12350
|
+
const SHIP_ENDINGS = {
|
|
12351
|
+
merged: "succeeded",
|
|
12352
|
+
ready_to_merge: "succeeded",
|
|
12353
|
+
needs_human: "needs_human",
|
|
12354
|
+
cancelled: "cancelled"
|
|
12355
|
+
};
|
|
12356
|
+
/** What CI's state reads as, by `ci.check`'s trigger; another trigger reads as its words. */
|
|
12357
|
+
const CI_SAYS = {
|
|
12358
|
+
checks_green: "CI is green",
|
|
12359
|
+
checks_red: "CI failed",
|
|
12360
|
+
checks_pending: "CI is running",
|
|
12361
|
+
no_checks: "The pull request has no CI checks",
|
|
12362
|
+
blocked: "CI is green; GitHub reports the pull request blocked (a required review, or another rule)",
|
|
12363
|
+
behind_base: "The pull request is behind its base",
|
|
12364
|
+
conflicted: "The pull request conflicts with its base"
|
|
12365
|
+
};
|
|
11879
12366
|
const str = (v) => typeof v === "string" && v.trim() ? v.trim() : null;
|
|
11880
12367
|
const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : null;
|
|
11881
12368
|
/** A message the API takes: one line or more, at most 2000 characters. */
|
|
@@ -11890,8 +12377,17 @@ function agentpipeMapper(report) {
|
|
|
11890
12377
|
const started = /* @__PURE__ */ new Set();
|
|
11891
12378
|
const attempts = /* @__PURE__ */ new Map();
|
|
11892
12379
|
let pending = null;
|
|
12380
|
+
/** What the model steps cost (their `step.end`s), and what the ship loop after them spent (its own count). */
|
|
11893
12381
|
let total = 0;
|
|
12382
|
+
let shipped = 0;
|
|
11894
12383
|
let ending = null;
|
|
12384
|
+
/** agentpipe's own word for how it ended: `run.end`'s status, then `ship.end`'s state. */
|
|
12385
|
+
let said = null;
|
|
12386
|
+
/** `run.end` came: what follows is `address --ship`'s ship loop, which `agentpipe cancel` can't reach. */
|
|
12387
|
+
let runEnded = false;
|
|
12388
|
+
/** CI's state as last said (`ci.check`), so only a change is reported: the loop polls every few seconds. */
|
|
12389
|
+
let ci = null;
|
|
12390
|
+
const spent = () => report.update({ costUsd: Math.round((total + shipped) * 1e4) / 1e4 });
|
|
11895
12391
|
const flush = (cost) => {
|
|
11896
12392
|
if (!pending) return;
|
|
11897
12393
|
const { step, attempt, status, message, at } = pending;
|
|
@@ -11969,9 +12465,9 @@ function agentpipeMapper(report) {
|
|
|
11969
12465
|
}
|
|
11970
12466
|
if (costShaped) {
|
|
11971
12467
|
const costUsd = num(d.cost_usd);
|
|
11972
|
-
if (costUsd) {
|
|
12468
|
+
if (costUsd && !runEnded && ci === null) {
|
|
11973
12469
|
total += costUsd;
|
|
11974
|
-
|
|
12470
|
+
spent();
|
|
11975
12471
|
}
|
|
11976
12472
|
flush({
|
|
11977
12473
|
durationMs: num(d.duration_ms),
|
|
@@ -11980,6 +12476,72 @@ function agentpipeMapper(report) {
|
|
|
11980
12476
|
}
|
|
11981
12477
|
return;
|
|
11982
12478
|
}
|
|
12479
|
+
case "ci.check": {
|
|
12480
|
+
const trigger = str(d.trigger);
|
|
12481
|
+
if (!trigger) return;
|
|
12482
|
+
const failing = Array.isArray(d.failing) ? d.failing.filter((f) => typeof f === "string") : [];
|
|
12483
|
+
const words = CI_SAYS[trigger] ?? trigger.replace(/_/g, " ");
|
|
12484
|
+
const now = trigger === "checks_red" && failing.length ? `${words}: ${failing.join(", ")}` : words;
|
|
12485
|
+
const blocked = trigger === "blocked";
|
|
12486
|
+
if (ci?.said !== now) report.event({
|
|
12487
|
+
kind: "activity",
|
|
12488
|
+
...step && { step },
|
|
12489
|
+
message: clip$1(now),
|
|
12490
|
+
...at && { at }
|
|
12491
|
+
});
|
|
12492
|
+
ci = {
|
|
12493
|
+
said: now,
|
|
12494
|
+
blocked
|
|
12495
|
+
};
|
|
12496
|
+
return;
|
|
12497
|
+
}
|
|
12498
|
+
case "ci.repair_attempt": {
|
|
12499
|
+
const sofar = num(d.spent_usd);
|
|
12500
|
+
if (sofar !== null && sofar > shipped) {
|
|
12501
|
+
shipped = sofar;
|
|
12502
|
+
spent();
|
|
12503
|
+
}
|
|
12504
|
+
const attempt = num(d.attempt);
|
|
12505
|
+
const message = `${d.succeeded === true ? "Pushed a repair" : "A repair didn't work"}${attempt ? ` (attempt ${attempt})` : ""}`;
|
|
12506
|
+
report.event({
|
|
12507
|
+
kind: "activity",
|
|
12508
|
+
...step && { step },
|
|
12509
|
+
message,
|
|
12510
|
+
...at && { at }
|
|
12511
|
+
});
|
|
12512
|
+
return;
|
|
12513
|
+
}
|
|
12514
|
+
case "review.findings": {
|
|
12515
|
+
const found = Array.isArray(d.candidates) ? d.candidates.length : 0;
|
|
12516
|
+
const message = found === 1 ? "Found 1 thing to look at" : `Found ${found} things to look at`;
|
|
12517
|
+
report.event({
|
|
12518
|
+
kind: "activity",
|
|
12519
|
+
...step && { step },
|
|
12520
|
+
message,
|
|
12521
|
+
...at && { at }
|
|
12522
|
+
});
|
|
12523
|
+
return;
|
|
12524
|
+
}
|
|
12525
|
+
case "review.posted":
|
|
12526
|
+
report.event({
|
|
12527
|
+
kind: "activity",
|
|
12528
|
+
...step && { step },
|
|
12529
|
+
message: "Posted its review",
|
|
12530
|
+
...at && { at }
|
|
12531
|
+
});
|
|
12532
|
+
return;
|
|
12533
|
+
case "review.answered":
|
|
12534
|
+
case "feedback.intake": {
|
|
12535
|
+
const n = Array.isArray(d.answers) ? d.answers.length : Array.isArray(d.comments) ? d.comments.length : 0;
|
|
12536
|
+
const what = e.kind === "review.answered" ? "Answered" : "Comments to answer:";
|
|
12537
|
+
report.event({
|
|
12538
|
+
kind: "activity",
|
|
12539
|
+
...step && { step },
|
|
12540
|
+
message: `${what} ${n}`,
|
|
12541
|
+
...at && { at }
|
|
12542
|
+
});
|
|
12543
|
+
return;
|
|
12544
|
+
}
|
|
11983
12545
|
case "pr.created": {
|
|
11984
12546
|
const url = str(d.url);
|
|
11985
12547
|
if (!url) return;
|
|
@@ -12016,6 +12578,15 @@ function agentpipeMapper(report) {
|
|
|
12016
12578
|
}
|
|
12017
12579
|
case "question.asked":
|
|
12018
12580
|
case "escalation": {
|
|
12581
|
+
if (e.kind === "escalation" && ci?.blocked) {
|
|
12582
|
+
report.event({
|
|
12583
|
+
kind: "activity",
|
|
12584
|
+
...step && { step },
|
|
12585
|
+
message: "Waiting for a required review",
|
|
12586
|
+
...at && { at }
|
|
12587
|
+
});
|
|
12588
|
+
return;
|
|
12589
|
+
}
|
|
12019
12590
|
const text = str(d.question) ?? str(d.text) ?? str(d.message) ?? str(d.reason) ?? "It needs an answer.";
|
|
12020
12591
|
report.event({
|
|
12021
12592
|
kind: "question",
|
|
@@ -12037,7 +12608,9 @@ function agentpipeMapper(report) {
|
|
|
12037
12608
|
}
|
|
12038
12609
|
case "run.end": {
|
|
12039
12610
|
flush();
|
|
12611
|
+
runEnded = true;
|
|
12040
12612
|
const status = str(d.status) ?? "failed";
|
|
12613
|
+
said = status;
|
|
12041
12614
|
const reason = str(d.reason);
|
|
12042
12615
|
const says = SAYS[status];
|
|
12043
12616
|
ending = {
|
|
@@ -12050,12 +12623,72 @@ function agentpipeMapper(report) {
|
|
|
12050
12623
|
});
|
|
12051
12624
|
return;
|
|
12052
12625
|
}
|
|
12626
|
+
case "merge.completed": {
|
|
12627
|
+
said = "merged";
|
|
12628
|
+
const sha = str(d.sha);
|
|
12629
|
+
ending = {
|
|
12630
|
+
status: "succeeded",
|
|
12631
|
+
reason: sha ? `Merged (${sha.slice(0, 7)}).` : "Merged."
|
|
12632
|
+
};
|
|
12633
|
+
return;
|
|
12634
|
+
}
|
|
12635
|
+
case "merge.blocked": {
|
|
12636
|
+
said = "blocked";
|
|
12637
|
+
const reason = str(d.reason);
|
|
12638
|
+
ending = {
|
|
12639
|
+
status: "needs_human",
|
|
12640
|
+
reason: clip$1(reason ?? "agentpipe didn't merge it.")
|
|
12641
|
+
};
|
|
12642
|
+
report.event({
|
|
12643
|
+
kind: "question",
|
|
12644
|
+
...step && { step },
|
|
12645
|
+
message: ending.reason ?? "",
|
|
12646
|
+
...at && { at }
|
|
12647
|
+
});
|
|
12648
|
+
return;
|
|
12649
|
+
}
|
|
12650
|
+
case "ship.end": {
|
|
12651
|
+
flush();
|
|
12652
|
+
const state = str(d.state) ?? "failed";
|
|
12653
|
+
const reason = str(d.reason);
|
|
12654
|
+
said = state;
|
|
12655
|
+
const cost = num(d.cost_usd);
|
|
12656
|
+
if (cost !== null && cost > shipped) {
|
|
12657
|
+
shipped = cost;
|
|
12658
|
+
spent();
|
|
12659
|
+
}
|
|
12660
|
+
if (state === "needs_human" && ci?.blocked) ending = {
|
|
12661
|
+
status: "succeeded",
|
|
12662
|
+
reason: "CI is green; GitHub is waiting for a required review."
|
|
12663
|
+
};
|
|
12664
|
+
else if (state === "ready_to_merge") ending = {
|
|
12665
|
+
status: "succeeded",
|
|
12666
|
+
reason: "CI is green: ready for you to merge."
|
|
12667
|
+
};
|
|
12668
|
+
else if (state === "refused") ending = {
|
|
12669
|
+
status: "failed",
|
|
12670
|
+
reason: clip$1(`${SAYS.refused}${reason ? `: ${reason}` : "."}`)
|
|
12671
|
+
};
|
|
12672
|
+
else ending = {
|
|
12673
|
+
status: SHIP_ENDINGS[state] ?? "failed",
|
|
12674
|
+
reason: reason ? clip$1(reason) : SHIP_ENDINGS[state] ? null : `It ended ${state.replace(/_/g, " ")}.`
|
|
12675
|
+
};
|
|
12676
|
+
if (ending.status === "failed" && ending.reason) report.event({
|
|
12677
|
+
kind: "error",
|
|
12678
|
+
message: clip$1(ending.reason)
|
|
12679
|
+
});
|
|
12680
|
+
return;
|
|
12681
|
+
}
|
|
12053
12682
|
}
|
|
12054
12683
|
};
|
|
12055
12684
|
return {
|
|
12056
12685
|
take,
|
|
12057
12686
|
/** How agentpipe said the run ended (null: it didn't). */
|
|
12058
12687
|
ending: () => ending,
|
|
12688
|
+
/** agentpipe's own word for it (`nothing_to_do`, `ready_to_merge`…; null: it didn't say). */
|
|
12689
|
+
said: () => said,
|
|
12690
|
+
/** Its `run.end` came: anything after is a ship loop's (`address --ship`). */
|
|
12691
|
+
runEnded: () => runEnded,
|
|
12059
12692
|
flush: () => flush()
|
|
12060
12693
|
};
|
|
12061
12694
|
}
|
|
@@ -12135,13 +12768,43 @@ function agentpipeEnv(env, monobanBin) {
|
|
|
12135
12768
|
if (monobanBin) kept.MONOBAN_BIN = monobanBin;
|
|
12136
12769
|
return kept;
|
|
12137
12770
|
}
|
|
12771
|
+
/**
|
|
12772
|
+
* One agentpipe command (`run`, and the loops' recipes' `review`, `ship`, `address`, `merge`, `scout`…): in its own
|
|
12773
|
+
* process group, with only the environment it needs (agentpipeEnv), each `--json` event line it prints given to
|
|
12774
|
+
* `map` (its plain lines skipped), its stderr's last line kept to say why it stopped. `stop()` and `interrupt()`
|
|
12775
|
+
* end it from outside; `agentpipe cancel <run id>` is the polite way, once there is one.
|
|
12776
|
+
*/
|
|
12777
|
+
function agentpipeCommand({ command = "agentpipe", args, cwd, env, monobanBin = null, map, spawn = defaultSpawn, graceMs }) {
|
|
12778
|
+
return startProcess({
|
|
12779
|
+
command,
|
|
12780
|
+
args,
|
|
12781
|
+
cwd,
|
|
12782
|
+
env: agentpipeEnv(env, monobanBin),
|
|
12783
|
+
spawn,
|
|
12784
|
+
...graceMs !== void 0 && { graceMs },
|
|
12785
|
+
onLine: (line) => {
|
|
12786
|
+
const event = parseLine(line);
|
|
12787
|
+
if (event) map(event);
|
|
12788
|
+
}
|
|
12789
|
+
});
|
|
12790
|
+
}
|
|
12791
|
+
/** Runs a short agentpipe command (`cancel`) to its end, whatever it says. */
|
|
12138
12792
|
const exec = (command, args, env) => new Promise((resolve) => execFile(command, args, {
|
|
12139
12793
|
timeout: 3e4,
|
|
12140
12794
|
env
|
|
12141
12795
|
}, () => resolve()));
|
|
12142
|
-
/**
|
|
12143
|
-
|
|
12144
|
-
|
|
12796
|
+
/**
|
|
12797
|
+
* `agentpipe ledger sync <folder>`: asks GitHub what became of the pull requests its runs opened there (read-only),
|
|
12798
|
+
* and a merged one's task goes to Done (agentpipe calls this monoban back). No model, no cost; whatever it says.
|
|
12799
|
+
*/
|
|
12800
|
+
function ledgerSync(deps, workdir) {
|
|
12801
|
+
return (deps.execCommand ?? exec)(deps.command, [
|
|
12802
|
+
"ledger",
|
|
12803
|
+
"sync",
|
|
12804
|
+
workdir
|
|
12805
|
+
], agentpipeEnv(deps.env, deps.monobanBin));
|
|
12806
|
+
}
|
|
12807
|
+
function agentpipe({ command = "agentpipe", args = [], spawn = defaultSpawn, execCommand = exec, env: runnerEnv = process.env, monobanBin = null, budgetUsd = 10 } = {}) {
|
|
12145
12808
|
const env = agentpipeEnv(runnerEnv, monobanBin);
|
|
12146
12809
|
return {
|
|
12147
12810
|
name: "agentpipe",
|
|
@@ -12154,50 +12817,28 @@ function agentpipe({ command = "agentpipe", args = [], spawn: spawn$1 = spawn, e
|
|
|
12154
12817
|
report.update(u);
|
|
12155
12818
|
}
|
|
12156
12819
|
});
|
|
12157
|
-
const
|
|
12158
|
-
|
|
12820
|
+
const started = agentpipeCommand({
|
|
12821
|
+
command,
|
|
12822
|
+
args: [...agentpipeArgs(run, budgetUsd), ...args],
|
|
12823
|
+
cwd: run.workdir,
|
|
12824
|
+
env: runnerEnv,
|
|
12825
|
+
monobanBin,
|
|
12826
|
+
map: feed.take,
|
|
12827
|
+
spawn
|
|
12828
|
+
});
|
|
12159
12829
|
return {
|
|
12160
|
-
done:
|
|
12161
|
-
|
|
12162
|
-
|
|
12163
|
-
|
|
12164
|
-
|
|
12165
|
-
|
|
12166
|
-
|
|
12167
|
-
}
|
|
12168
|
-
|
|
12169
|
-
|
|
12170
|
-
|
|
12171
|
-
|
|
12172
|
-
return;
|
|
12173
|
-
}
|
|
12174
|
-
let spawnError = null;
|
|
12175
|
-
child.on("error", (err) => {
|
|
12176
|
-
spawnError = err.code === "ENOENT" ? `${command} isn't installed here (or isn't on the runner's PATH).` : `${command} failed: ${err.message}`;
|
|
12177
|
-
});
|
|
12178
|
-
if (child.stdout) createInterface$1({ input: child.stdout }).on("line", (line) => {
|
|
12179
|
-
const event = parseLine(line);
|
|
12180
|
-
if (event) feed.take(event);
|
|
12181
|
-
});
|
|
12182
|
-
if (child.stderr) createInterface$1({ input: child.stderr }).on("line", (line) => {
|
|
12183
|
-
if (!line.trim()) return;
|
|
12184
|
-
tail.push(line.trim());
|
|
12185
|
-
if (tail.length > TAIL$1) tail.shift();
|
|
12186
|
-
});
|
|
12187
|
-
child.on("close", (code) => {
|
|
12188
|
-
feed.flush();
|
|
12189
|
-
const said = feed.ending();
|
|
12190
|
-
if (said) return resolve(said);
|
|
12191
|
-
if (spawnError) return resolve({
|
|
12192
|
-
status: "failed",
|
|
12193
|
-
reason: spawnError
|
|
12194
|
-
});
|
|
12195
|
-
const last = tail.at(-1);
|
|
12196
|
-
resolve({
|
|
12197
|
-
status: "failed",
|
|
12198
|
-
reason: `${command} stopped (exit code ${code ?? "none"}) without saying how it ended${last ? `: ${last}` : "."}`
|
|
12199
|
-
});
|
|
12200
|
-
});
|
|
12830
|
+
done: started.done.then(({ code, spawnError, lastError }) => {
|
|
12831
|
+
feed.flush();
|
|
12832
|
+
const said = feed.ending();
|
|
12833
|
+
if (said) return said;
|
|
12834
|
+
if (spawnError) return {
|
|
12835
|
+
status: "failed",
|
|
12836
|
+
reason: spawnError
|
|
12837
|
+
};
|
|
12838
|
+
return {
|
|
12839
|
+
status: "failed",
|
|
12840
|
+
reason: `${command} stopped (exit code ${code ?? "none"}) without saying how it ended${lastError ? `: ${lastError}` : "."}`
|
|
12841
|
+
};
|
|
12201
12842
|
}),
|
|
12202
12843
|
cancel: async () => {
|
|
12203
12844
|
if (externalId) await execCommand(command, [
|
|
@@ -12206,12 +12847,61 @@ function agentpipe({ command = "agentpipe", args = [], spawn: spawn$1 = spawn, e
|
|
|
12206
12847
|
"--reason",
|
|
12207
12848
|
"Cancelled from monoban"
|
|
12208
12849
|
], env);
|
|
12209
|
-
else
|
|
12850
|
+
else started.interrupt();
|
|
12210
12851
|
}
|
|
12211
12852
|
};
|
|
12212
12853
|
}
|
|
12213
12854
|
};
|
|
12214
12855
|
}
|
|
12856
|
+
/** What each loop's recipe needs of agentpipe: its commands and their flags (docs/PLAN-AGENT-LOOPS.md §1.6). */
|
|
12857
|
+
const RECIPE_NEEDS = {
|
|
12858
|
+
deliver: [
|
|
12859
|
+
"run.json",
|
|
12860
|
+
"run.dry_run_json",
|
|
12861
|
+
"run.fresh_base",
|
|
12862
|
+
"review.json",
|
|
12863
|
+
"ship.json",
|
|
12864
|
+
"address.json",
|
|
12865
|
+
"address.no_merge",
|
|
12866
|
+
"merge.json",
|
|
12867
|
+
"merge.expect_run"
|
|
12868
|
+
],
|
|
12869
|
+
scavenge: ["scout.json", "scout.track"]
|
|
12870
|
+
};
|
|
12871
|
+
/** The recipes an agentpipe can run, from what it says it has. */
|
|
12872
|
+
function recipesOf(capabilities) {
|
|
12873
|
+
const has = (need) => {
|
|
12874
|
+
const [command = "", flag = ""] = need.split(".");
|
|
12875
|
+
return capabilities?.commands?.[command]?.[flag] === true;
|
|
12876
|
+
};
|
|
12877
|
+
return RECIPE_NAMES.filter((recipe) => RECIPE_NEEDS[recipe].every(has));
|
|
12878
|
+
}
|
|
12879
|
+
/**
|
|
12880
|
+
* Asks agentpipe what it can do (`capabilities --json`: it spends nothing and needs no repository; given a folder,
|
|
12881
|
+
* its tiers are that repository's too). Null when it can't say: an agentpipe before the command (AGE-127), or one
|
|
12882
|
+
* that doesn't answer.
|
|
12883
|
+
*/
|
|
12884
|
+
function agentpipeCapabilities(command, env, folder) {
|
|
12885
|
+
return new Promise((resolve) => {
|
|
12886
|
+
execFile(command, [
|
|
12887
|
+
"capabilities",
|
|
12888
|
+
...folder ? [folder] : [],
|
|
12889
|
+
"--json"
|
|
12890
|
+
], {
|
|
12891
|
+
timeout: 15e3,
|
|
12892
|
+
env: agentpipeEnv(env, null),
|
|
12893
|
+
maxBuffer: 1048576
|
|
12894
|
+
}, (err, stdout) => {
|
|
12895
|
+
if (err) return resolve(null);
|
|
12896
|
+
try {
|
|
12897
|
+
const parsed = JSON.parse(stdout);
|
|
12898
|
+
resolve(parsed && typeof parsed === "object" ? parsed : null);
|
|
12899
|
+
} catch {
|
|
12900
|
+
resolve(null);
|
|
12901
|
+
}
|
|
12902
|
+
});
|
|
12903
|
+
});
|
|
12904
|
+
}
|
|
12215
12905
|
// src/board.ts
|
|
12216
12906
|
/** Every project you have, in sidebar order. */
|
|
12217
12907
|
async function allProjects$1(api) {
|
|
@@ -12424,7 +13114,7 @@ const strategies = {
|
|
|
12424
13114
|
variadic: strategyVariadic,
|
|
12425
13115
|
monadic: strategyMonadic
|
|
12426
13116
|
};
|
|
12427
|
-
// ../../node_modules/.pnpm/use-intl@4.14.
|
|
13117
|
+
// ../../node_modules/.pnpm/use-intl@4.14.10_@types+react@19.3.0_react@19.3.1/node_modules/use-intl/dist/esm/production/formatters-CJcico0N.js
|
|
12428
13118
|
var a = class extends Error {
|
|
12429
13119
|
constructor(e, t) {
|
|
12430
13120
|
let a = e;
|
|
@@ -16360,7 +17050,7 @@ var IntlMessageFormat = class IntlMessageFormat {
|
|
|
16360
17050
|
};
|
|
16361
17051
|
}
|
|
16362
17052
|
};
|
|
16363
|
-
// ../../node_modules/.pnpm/use-intl@4.14.
|
|
17053
|
+
// ../../node_modules/.pnpm/use-intl@4.14.10_@types+react@19.3.0_react@19.3.1/node_modules/use-intl/dist/esm/production/format-message/index.js
|
|
16364
17054
|
var import_react = require_react();
|
|
16365
17055
|
function m$1(...[m, s, i, n]) {
|
|
16366
17056
|
if (Array.isArray(s)) throw new a(r.INVALID_MESSAGE, void 0);
|
|
@@ -16419,7 +17109,7 @@ function m$1(...[m, s, i, n]) {
|
|
|
16419
17109
|
return (0, import_react.isValidElement)(w) || Array.isArray(w) || "string" == typeof w ? w : String(w);
|
|
16420
17110
|
}
|
|
16421
17111
|
m$1.raw = !0;
|
|
16422
|
-
// ../../node_modules/.pnpm/use-intl@4.14.
|
|
17112
|
+
// ../../node_modules/.pnpm/use-intl@4.14.10_@types+react@19.3.0_react@19.3.1/node_modules/use-intl/dist/esm/production/initializeConfig-CHgjheii.js
|
|
16423
17113
|
function c(...e) {
|
|
16424
17114
|
return e.filter(Boolean).join(".");
|
|
16425
17115
|
}
|
|
@@ -16536,7 +17226,7 @@ function f(a$1) {
|
|
|
16536
17226
|
function l(e, t) {
|
|
16537
17227
|
return e === t ? void 0 : e.slice((t + ".").length);
|
|
16538
17228
|
}
|
|
16539
|
-
// ../../node_modules/.pnpm/use-intl@4.14.
|
|
17229
|
+
// ../../node_modules/.pnpm/use-intl@4.14.10_@types+react@19.3.0_react@19.3.1/node_modules/use-intl/dist/esm/production/core.js
|
|
16540
17230
|
function n({ _cache: a = s(), _formatters: i$2 = l$1(a), getMessageFallback: n = i, messages: c, namespace: f$1, onError: g = u, ...l$2 }) {
|
|
16541
17231
|
return function({ messages: e, namespace: a, ...r }, o) {
|
|
16542
17232
|
return e = e[o], a = l(a, o), f({
|
|
@@ -16787,10 +17477,12 @@ var en_US_default = {
|
|
|
16787
17477
|
"label": "Project views",
|
|
16788
17478
|
"board": "board",
|
|
16789
17479
|
"notes": "notes.md",
|
|
17480
|
+
"loops": "loops",
|
|
16790
17481
|
"archive": "archive"
|
|
16791
17482
|
},
|
|
16792
17483
|
status: {
|
|
16793
17484
|
"notes": "notes.md",
|
|
17485
|
+
"loops": "loops · {count}",
|
|
16794
17486
|
"archiveTask": "{ref} · archive",
|
|
16795
17487
|
"archive": "archive · {count}",
|
|
16796
17488
|
"task": "{ref} · {column}",
|
|
@@ -16945,7 +17637,8 @@ var en_US_default = {
|
|
|
16945
17637
|
"view": "view",
|
|
16946
17638
|
"account": "account",
|
|
16947
17639
|
"goTo": "go to",
|
|
16948
|
-
"projectList": "project list"
|
|
17640
|
+
"projectList": "project list",
|
|
17641
|
+
"loop": "loop"
|
|
16949
17642
|
},
|
|
16950
17643
|
unavailable: "{command}: {needs}.",
|
|
16951
17644
|
palette: {
|
|
@@ -17233,6 +17926,10 @@ var en_US_default = {
|
|
|
17233
17926
|
"label": "Notes of {project}",
|
|
17234
17927
|
"keywords": "notes scratch memo text"
|
|
17235
17928
|
},
|
|
17929
|
+
"loops": {
|
|
17930
|
+
"label": "Loops of {project}",
|
|
17931
|
+
"keywords": "loops agents automation schedule deliver scavenge runner"
|
|
17932
|
+
},
|
|
17236
17933
|
"archive": {
|
|
17237
17934
|
"label": "Archive of {project}: done and won't-do tasks",
|
|
17238
17935
|
"keywords": "archive archived old done wont history unarchive"
|
|
@@ -17278,6 +17975,41 @@ var en_US_default = {
|
|
|
17278
17975
|
"showWeek": { "label": "Show the next 7 days" },
|
|
17279
17976
|
"pickDay": { "label": "Show another day…" }
|
|
17280
17977
|
},
|
|
17978
|
+
loops: {
|
|
17979
|
+
"down": { "label": "Next loop" },
|
|
17980
|
+
"up": { "label": "Previous loop" },
|
|
17981
|
+
"open": {
|
|
17982
|
+
"label": "Open {name}",
|
|
17983
|
+
"help": "Open loop"
|
|
17984
|
+
},
|
|
17985
|
+
"back": { "label": "Back to the loops" },
|
|
17986
|
+
"runDown": { "label": "Next run" },
|
|
17987
|
+
"runUp": { "label": "Previous run" },
|
|
17988
|
+
"new": {
|
|
17989
|
+
"label": "New loop in {project}",
|
|
17990
|
+
"keywords": "loop create add agent schedule"
|
|
17991
|
+
},
|
|
17992
|
+
"edit": {
|
|
17993
|
+
"label": "Edit {name}",
|
|
17994
|
+
"help": "Edit loop"
|
|
17995
|
+
},
|
|
17996
|
+
"pause": {
|
|
17997
|
+
"label": "Pause {name}",
|
|
17998
|
+
"help": "Pause loop"
|
|
17999
|
+
},
|
|
18000
|
+
"resume": {
|
|
18001
|
+
"label": "Resume {name}",
|
|
18002
|
+
"help": "Resume loop"
|
|
18003
|
+
},
|
|
18004
|
+
"runNow": {
|
|
18005
|
+
"label": "Run {name} now",
|
|
18006
|
+
"help": "Run loop now"
|
|
18007
|
+
},
|
|
18008
|
+
"delete": {
|
|
18009
|
+
"label": "Delete {name}",
|
|
18010
|
+
"help": "Delete loop"
|
|
18011
|
+
}
|
|
18012
|
+
},
|
|
17281
18013
|
archive: {
|
|
17282
18014
|
"down": { "label": "Next archived task" },
|
|
17283
18015
|
"up": { "label": "Previous archived task" },
|
|
@@ -17327,6 +18059,149 @@ var en_US_default = {
|
|
|
17327
18059
|
"attach": "Attach"
|
|
17328
18060
|
}
|
|
17329
18061
|
},
|
|
18062
|
+
loops: {
|
|
18063
|
+
label: "Loops",
|
|
18064
|
+
recipe: {
|
|
18065
|
+
"deliver": "deliver",
|
|
18066
|
+
"scavenge": "scavenge"
|
|
18067
|
+
},
|
|
18068
|
+
empty: "No loops in {project} yet. A loop runs an agent on your runner, on a schedule: it takes tasks and delivers them as merged pull requests, or finds problems and files them as tasks.",
|
|
18069
|
+
loading: "loading loops…",
|
|
18070
|
+
loadFailed: "Couldn't load the loops.",
|
|
18071
|
+
tryAgain: "Try again",
|
|
18072
|
+
heading: {
|
|
18073
|
+
"name": "loop",
|
|
18074
|
+
"type": "type",
|
|
18075
|
+
"state": "state",
|
|
18076
|
+
"now": "now",
|
|
18077
|
+
"day": "24 h"
|
|
18078
|
+
},
|
|
18079
|
+
now: "{step} · {ref}",
|
|
18080
|
+
starting: "starting",
|
|
18081
|
+
day: "{runs, plural, one {# run} other {# runs}} · {cost}",
|
|
18082
|
+
row: "{name}, {type}: {state}",
|
|
18083
|
+
detail: {
|
|
18084
|
+
"label": "{name}: its steps and runs",
|
|
18085
|
+
"back": "All loops",
|
|
18086
|
+
"on": "{type} on {runner}",
|
|
18087
|
+
"steps": "Steps",
|
|
18088
|
+
"stepState": {
|
|
18089
|
+
"done": "done",
|
|
18090
|
+
"current": "now",
|
|
18091
|
+
"next": "to come",
|
|
18092
|
+
"skipped": "skipped"
|
|
18093
|
+
},
|
|
18094
|
+
"now": "now",
|
|
18095
|
+
"task": "task",
|
|
18096
|
+
"pr": "PR",
|
|
18097
|
+
"hold": "{going, select, yes {Stops before merge} other {Stopped before merge}}: {why, select, mergeOff {merge is off for this loop} queuedOutside {its task was queued outside the browser} other {its text was changed outside the browser after you queued it}}.",
|
|
18098
|
+
"waiting": "Waiting for you",
|
|
18099
|
+
"waits": "<pr>{ref}'s pull request</pr> is ready for you to merge: {why, select, mergeOff {merge is off for this loop} queuedOutside {its task was queued outside the browser} other {its text was changed outside the browser after you queued it}}.",
|
|
18100
|
+
"waitsOpen": "<pr>{ref}'s pull request</pr> waits for you."
|
|
18101
|
+
},
|
|
18102
|
+
runs: {
|
|
18103
|
+
"heading": "Runs",
|
|
18104
|
+
"label": "Runs of {name}",
|
|
18105
|
+
"when": "started",
|
|
18106
|
+
"task": "task",
|
|
18107
|
+
"result": "result",
|
|
18108
|
+
"took": "took",
|
|
18109
|
+
"cost": "cost",
|
|
18110
|
+
"noTask": "no task",
|
|
18111
|
+
"row": "{date}, {task}: {result}",
|
|
18112
|
+
"none": "No runs yet.",
|
|
18113
|
+
"loading": "loading its runs…"
|
|
18114
|
+
},
|
|
18115
|
+
dialog: {
|
|
18116
|
+
"newTitle": "New loop in {project}",
|
|
18117
|
+
"editTitle": "Edit {name}",
|
|
18118
|
+
"description": "A loop runs an agent on your runner, through agentpipe, again and again. It starts at its runner's next check-in.",
|
|
18119
|
+
"name": "Name",
|
|
18120
|
+
"namePlaceholder": "Ship the To do column",
|
|
18121
|
+
"type": "Type",
|
|
18122
|
+
"recipeHint": {
|
|
18123
|
+
"deliver": "Takes tasks from a column, one at a time, and delivers each as a pull request.",
|
|
18124
|
+
"scavenge": "Looks for problems in the code and files them as tasks."
|
|
18125
|
+
},
|
|
18126
|
+
"typeFixed": "A loop's type can't change.",
|
|
18127
|
+
"runner": "Runner",
|
|
18128
|
+
"folder": "Folder",
|
|
18129
|
+
"folderHint": "A checkout of the project's repository, on the runner's machine.",
|
|
18130
|
+
"every": "Every",
|
|
18131
|
+
"interval": "{unit, select, seconds {{n, plural, one {# second} other {# seconds}}} minutes {{n, plural, one {# minute} other {# minutes}}} hours {{n, plural, one {# hour} other {# hours}}} days {{n, plural, one {# day} other {# days}}} other {{n, plural, one {# week} other {# weeks}}}}",
|
|
18132
|
+
"takesFrom": "Takes tasks from",
|
|
18133
|
+
"onlyTagged": "Only tasks tagged",
|
|
18134
|
+
"anyTag": "any tag: every task in the column",
|
|
18135
|
+
"merge": "Merge each pull request when its checks pass",
|
|
18136
|
+
"mergeHint": "Only the tasks you queued from the browser. The others wait for you to merge.",
|
|
18137
|
+
"deliverMaxOpen": "Pull requests that may wait for you",
|
|
18138
|
+
"checksMinutes": "Wait for checks (minutes)",
|
|
18139
|
+
"reviewTier": "Review on",
|
|
18140
|
+
"reviewTierHint": "The models agentpipe reviews the pull request with: its tier (--tier).",
|
|
18141
|
+
"reviewTierDefault": "agentpipe's own tier",
|
|
18142
|
+
"focus": "What to look for",
|
|
18143
|
+
"focusPlaceholder": "Tests that fail now and then, and why",
|
|
18144
|
+
"filesIn": "Files tasks in",
|
|
18145
|
+
"tagsWith": "Tags them",
|
|
18146
|
+
"pickTag": "pick a tag",
|
|
18147
|
+
"scavengeMaxOpen": "Its open tasks, at most",
|
|
18148
|
+
"limits": "How much it may do",
|
|
18149
|
+
"perDay": "Runs a day",
|
|
18150
|
+
"budgetUsd": "Budget per run (US$)",
|
|
18151
|
+
"budgetUsdPerDay": "Budget per day (US$)",
|
|
18152
|
+
"pauseAfter": "Pause after runs in a row",
|
|
18153
|
+
"summary": {
|
|
18154
|
+
"deliver": "Every {interval}, on {runner}, it takes {tagged, select, yes {the tasks tagged #{tag} in {column}} other {every task in {column}}}, one at a time, up to {perDay} a day, and opens a pull request for each. {merge, select, yes {It merges each one when its checks pass, for the tasks you queued from the browser; the others wait for you to merge.} other {It leaves each one for you to merge.}} It stops taking tasks while {maxOpen, plural, one {# pull request waits} other {# pull requests wait}} for you, spends at most {budget} a run and {budgetDay} a day, and pauses after {pauseAfter, plural, one {a run that fails or needs you} other {# runs in a row that fail or need you}}.",
|
|
18155
|
+
"scavenge": "Every {interval}, on {runner}, it looks for: {focus}. It files what it finds in {column}, tagged #{tag}, and stops filing while {maxOpen, plural, one {# of those tasks is} other {# of those tasks are}} open. It spends at most {budget} a run and {budgetDay} a day, and pauses after {pauseAfter, plural, one {a run that fails or needs you} other {# runs in a row that fail or need you}}.",
|
|
18156
|
+
"incomplete": "Fill in the fields above to see what the loop will do."
|
|
18157
|
+
},
|
|
18158
|
+
"create": "Create loop",
|
|
18159
|
+
"creating": "Creating…",
|
|
18160
|
+
"save": "Save",
|
|
18161
|
+
"saving": "Saving…",
|
|
18162
|
+
"cancel": "Cancel",
|
|
18163
|
+
"couldntSave": "Couldn't save the loop.",
|
|
18164
|
+
"problem": {
|
|
18165
|
+
"required": "Required.",
|
|
18166
|
+
"tooLong": "At most {max} characters.",
|
|
18167
|
+
"runner": "Pick a runner.",
|
|
18168
|
+
"absolute": "An absolute path, like /Users/you/code/project.",
|
|
18169
|
+
"number": "A number.",
|
|
18170
|
+
"whole": "A whole number.",
|
|
18171
|
+
"between": "From {min} to {max}.",
|
|
18172
|
+
"overDay": "No more than the budget per day.",
|
|
18173
|
+
"oneLine": "One line.",
|
|
18174
|
+
"tag": "Pick the tag it puts on what it files.",
|
|
18175
|
+
"nul": "Can't contain NUL characters."
|
|
18176
|
+
},
|
|
18177
|
+
"pauseAfterHint": "That fail or need you."
|
|
18178
|
+
},
|
|
18179
|
+
"delete": {
|
|
18180
|
+
"title": "Delete {name}?",
|
|
18181
|
+
"about": "Its runs stay on their tasks. A run that's queued is cancelled; a run that's going has to end first.",
|
|
18182
|
+
"confirm": "Delete",
|
|
18183
|
+
"deleting": "Deleting…",
|
|
18184
|
+
"cancel": "Cancel",
|
|
18185
|
+
"couldnt": "Couldn't delete the loop."
|
|
18186
|
+
},
|
|
18187
|
+
controls: {
|
|
18188
|
+
"new": "New loop",
|
|
18189
|
+
"runNow": "Run now",
|
|
18190
|
+
"pause": "Pause",
|
|
18191
|
+
"resume": "Resume",
|
|
18192
|
+
"edit": "Edit",
|
|
18193
|
+
"delete": "Delete"
|
|
18194
|
+
},
|
|
18195
|
+
toast: {
|
|
18196
|
+
"created": "Created {name}.",
|
|
18197
|
+
"saved": "Saved {name}.",
|
|
18198
|
+
"paused": "Paused {name}.",
|
|
18199
|
+
"resumed": "Resumed {name}.",
|
|
18200
|
+
"queued": "{name} runs at its runner's next check-in.",
|
|
18201
|
+
"deleted": "Deleted {name}.",
|
|
18202
|
+
"failed": "That didn't work: try again."
|
|
18203
|
+
}
|
|
18204
|
+
},
|
|
17330
18205
|
notes: {
|
|
17331
18206
|
find: {
|
|
17332
18207
|
"label": "Find in notes",
|
|
@@ -17511,7 +18386,10 @@ var en_US_default = {
|
|
|
17511
18386
|
"startingRun": "Starting a run",
|
|
17512
18387
|
"loadingRuns": "Loading the runs",
|
|
17513
18388
|
"deletingAccount": "Deleting your account",
|
|
17514
|
-
"changingLanguage": "Changing the language"
|
|
18389
|
+
"changingLanguage": "Changing the language",
|
|
18390
|
+
"loadingLoops": "Loading the loops",
|
|
18391
|
+
"savingLoop": "Saving the loop",
|
|
18392
|
+
"deletingLoop": "Deleting the loop"
|
|
17515
18393
|
},
|
|
17516
18394
|
keptNotRemoved: "Could not remove what's kept. Try again.",
|
|
17517
18395
|
saveState: {
|
|
@@ -17545,6 +18423,9 @@ var en_US_default = {
|
|
|
17545
18423
|
email_not_confirmed: "Confirm your email first: open the link we sent you, or ask for a new one on the sign-in page.",
|
|
17546
18424
|
unsupported_email: "monoban doesn't send this kind of email.",
|
|
17547
18425
|
email_not_sent: "The email couldn't be sent. Try again in a moment.",
|
|
18426
|
+
loops_off: "Agent loops aren't on for your account yet.",
|
|
18427
|
+
nothing_to_do: "No task is waiting for this loop: its column has none it can take.",
|
|
18428
|
+
pr_open: "This task's pull request may still be open: continue it from a step, or close it first.",
|
|
17548
18429
|
unreachable: "Couldn't reach monoban. Try again.",
|
|
17549
18430
|
unreachableShort: "Couldn't reach monoban.",
|
|
17550
18431
|
cantDeleteAccount: "Couldn't delete your account. Try again."
|
|
@@ -17752,6 +18633,7 @@ var en_US_default = {
|
|
|
17752
18633
|
"queuedOffline": "{runner} is offline: it starts once <code>monoban runner</code> runs there.",
|
|
17753
18634
|
"steps": "Steps",
|
|
17754
18635
|
"stepsHeading": "steps",
|
|
18636
|
+
"innerSteps": "{step}'s steps",
|
|
17755
18637
|
"noneYet": "none yet",
|
|
17756
18638
|
"none": "none",
|
|
17757
18639
|
"now": "now",
|
|
@@ -17909,6 +18791,33 @@ var en_US_default = {
|
|
|
17909
18791
|
"thousandTokens": "{n}k tokens",
|
|
17910
18792
|
"millionTokens": "{n}M tokens"
|
|
17911
18793
|
},
|
|
18794
|
+
loop: {
|
|
18795
|
+
"state": {
|
|
18796
|
+
"paused": {
|
|
18797
|
+
"you": "paused",
|
|
18798
|
+
"failures": "paused: its last runs failed or needed you",
|
|
18799
|
+
"unstartable": "paused: a run couldn't start"
|
|
18800
|
+
},
|
|
18801
|
+
"noRunner": "no runner: choose one",
|
|
18802
|
+
"runnerOffline": "{runner} is offline",
|
|
18803
|
+
"runnerOutdated": "{runner} can't run it: update agentpipe there",
|
|
18804
|
+
"running": "running",
|
|
18805
|
+
"waitingForYou": {
|
|
18806
|
+
"pullRequests": "{count, plural, one {a pull request waits for you} other {# pull requests wait for you}}",
|
|
18807
|
+
"tasks": "{count, plural, one {a task it filed waits for you} other {# tasks it filed wait for you}}"
|
|
18808
|
+
},
|
|
18809
|
+
"dailyLimit": "{count, plural, one {# run} other {# runs}} in 24 hours: its daily limit",
|
|
18810
|
+
"budget": "{spent} of {limit} spent in 24 hours: its daily budget",
|
|
18811
|
+
"waitingForTask": "waiting for a task",
|
|
18812
|
+
"due": "starting",
|
|
18813
|
+
"next": "next at {time}"
|
|
18814
|
+
},
|
|
18815
|
+
"hold": {
|
|
18816
|
+
"mergeOff": "merge is off for this loop",
|
|
18817
|
+
"queuedOutside": "its task was queued outside the browser",
|
|
18818
|
+
"textChanged": "its text was changed outside the browser after you queued it"
|
|
18819
|
+
}
|
|
18820
|
+
},
|
|
17912
18821
|
history: {
|
|
17913
18822
|
"verb": {
|
|
17914
18823
|
"created": "created",
|
|
@@ -18002,7 +18911,9 @@ var en_US_default = {
|
|
|
18002
18911
|
"wide": "wide",
|
|
18003
18912
|
"tags": "tags",
|
|
18004
18913
|
"link": "link",
|
|
18005
|
-
"move": "move"
|
|
18914
|
+
"move": "move",
|
|
18915
|
+
"nextRun": "next run",
|
|
18916
|
+
"back": "back"
|
|
18006
18917
|
},
|
|
18007
18918
|
"backOnline": "online again"
|
|
18008
18919
|
},
|
|
@@ -18039,6 +18950,7 @@ var en_US_default = {
|
|
|
18039
18950
|
"switchProject": "switch project",
|
|
18040
18951
|
"open": "open",
|
|
18041
18952
|
"views": "notes · archive · board",
|
|
18953
|
+
"viewsWithLoops": "notes · loops · archive · board",
|
|
18042
18954
|
"commands": "commands",
|
|
18043
18955
|
"everything": "everything"
|
|
18044
18956
|
}
|
|
@@ -18049,6 +18961,7 @@ var en_US_default = {
|
|
|
18049
18961
|
"location": "Location",
|
|
18050
18962
|
"today": "today",
|
|
18051
18963
|
"notes": "notes.md",
|
|
18964
|
+
"loops": "loops",
|
|
18052
18965
|
"board": "board",
|
|
18053
18966
|
"search": "› search tasks or run a command…",
|
|
18054
18967
|
"account": "Account and settings",
|
|
@@ -18746,6 +19659,14 @@ function formatCost(usd, { locale }) {
|
|
|
18746
19659
|
maximumFractionDigits: digits
|
|
18747
19660
|
}).format(usd);
|
|
18748
19661
|
}
|
|
19662
|
+
// ../../packages/i18n/src/loops.ts
|
|
19663
|
+
/**
|
|
19664
|
+
* Why a deliver run won't merge on its own (contract's `mergeHoldOf`, plan §1.12), in a few words: "its task was
|
|
19665
|
+
* queued outside the browser". The loops tab says the same in its own sentences (loops.json `detail.waits`).
|
|
19666
|
+
*/
|
|
19667
|
+
function describeMergeHold(hold, { t }) {
|
|
19668
|
+
return t(`loop.hold.${hold}`);
|
|
19669
|
+
}
|
|
18749
19670
|
// src/commands/comments.ts
|
|
18750
19671
|
/** `monoban comment MON-12 TEXT…`: a comment on the task (`-` reads it from stdin, Markdown and all). */
|
|
18751
19672
|
async function comment(ctx, ref, words, options) {
|
|
@@ -19398,7 +20319,7 @@ async function edit(ctx, ref, options) {
|
|
|
19398
20319
|
ctx.out(`Updated ${task.ref}.`);
|
|
19399
20320
|
}
|
|
19400
20321
|
/** `monoban rm MON-12`: asks first, unless -y. */
|
|
19401
|
-
async function rm
|
|
20322
|
+
async function rm(ctx, ref, options) {
|
|
19402
20323
|
const api = apis(ctx).signedIn;
|
|
19403
20324
|
const task = await taskByRef(api, ref, ctx);
|
|
19404
20325
|
if (!options.yes) {
|
|
@@ -19420,7 +20341,7 @@ async function rm$1(ctx, ref, options) {
|
|
|
19420
20341
|
ctx.out(`Deleted ${task.ref}.`);
|
|
19421
20342
|
}
|
|
19422
20343
|
/** `monoban open [MON-12]`: the task, or the board, in the browser (and the link on stdout). */
|
|
19423
|
-
async function open
|
|
20344
|
+
async function open(ctx, ref, options) {
|
|
19424
20345
|
let url;
|
|
19425
20346
|
if (ref) {
|
|
19426
20347
|
const { key, number } = taskRefOf(ref);
|
|
@@ -19686,92 +20607,6 @@ async function start(ctx, ref, options) {
|
|
|
19686
20607
|
}
|
|
19687
20608
|
for (const line of lines) ctx.out(line);
|
|
19688
20609
|
}
|
|
19689
|
-
// src/runner/process.ts
|
|
19690
|
-
const defaultSpawn = spawn;
|
|
19691
|
-
const TAIL = 20;
|
|
19692
|
-
function startProcess({ command, args, cwd, env, stdin, onLine, spawn = defaultSpawn, graceMs = 1e4 }) {
|
|
19693
|
-
let child;
|
|
19694
|
-
let exited = false;
|
|
19695
|
-
const timers = [];
|
|
19696
|
-
const signal = (sig) => {
|
|
19697
|
-
if (!child || exited) return;
|
|
19698
|
-
try {
|
|
19699
|
-
if (child.pid) process.kill(-child.pid, sig);
|
|
19700
|
-
else child.kill(sig);
|
|
19701
|
-
} catch {
|
|
19702
|
-
child.kill(sig);
|
|
19703
|
-
}
|
|
19704
|
-
};
|
|
19705
|
-
return {
|
|
19706
|
-
done: new Promise((resolve) => {
|
|
19707
|
-
try {
|
|
19708
|
-
child = spawn(command, args, {
|
|
19709
|
-
cwd,
|
|
19710
|
-
env,
|
|
19711
|
-
detached: true
|
|
19712
|
-
});
|
|
19713
|
-
} catch (err) {
|
|
19714
|
-
resolve({
|
|
19715
|
-
code: null,
|
|
19716
|
-
spawnError: `Couldn't start ${command}: ${err.message}`,
|
|
19717
|
-
lastError: null
|
|
19718
|
-
});
|
|
19719
|
-
return;
|
|
19720
|
-
}
|
|
19721
|
-
let spawnError = null;
|
|
19722
|
-
const tail = [];
|
|
19723
|
-
child.on("error", (err) => {
|
|
19724
|
-
spawnError = err.code === "ENOENT" ? `${command} isn't installed here (or isn't on the runner's PATH).` : `${command} failed: ${err.message}`;
|
|
19725
|
-
});
|
|
19726
|
-
if (child.stdin) {
|
|
19727
|
-
child.stdin.on("error", () => {});
|
|
19728
|
-
child.stdin.end(stdin ?? "");
|
|
19729
|
-
}
|
|
19730
|
-
if (child.stdout) createInterface$1({ input: child.stdout }).on("line", onLine);
|
|
19731
|
-
if (child.stderr) createInterface$1({ input: child.stderr }).on("line", (line) => {
|
|
19732
|
-
if (!line.trim()) return;
|
|
19733
|
-
tail.push(line.trim());
|
|
19734
|
-
if (tail.length > TAIL) tail.shift();
|
|
19735
|
-
});
|
|
19736
|
-
child.on("close", (code) => {
|
|
19737
|
-
exited = true;
|
|
19738
|
-
for (const t of timers) clearTimeout(t);
|
|
19739
|
-
resolve({
|
|
19740
|
-
code,
|
|
19741
|
-
spawnError,
|
|
19742
|
-
lastError: tail.at(-1) ?? null
|
|
19743
|
-
});
|
|
19744
|
-
});
|
|
19745
|
-
}),
|
|
19746
|
-
stop: () => {
|
|
19747
|
-
signal("SIGINT");
|
|
19748
|
-
timers.push(setTimeout(() => signal("SIGTERM"), graceMs));
|
|
19749
|
-
timers.push(setTimeout(() => signal("SIGKILL"), graceMs * 2));
|
|
19750
|
-
}
|
|
19751
|
-
};
|
|
19752
|
-
}
|
|
19753
|
-
/** The first version number a command prints for `--version` ("2.1.300 (Claude Code)" → 2.1.300), or null. */
|
|
19754
|
-
function versionOf(command, env = process.env) {
|
|
19755
|
-
return new Promise((resolve) => {
|
|
19756
|
-
execFile(command, ["--version"], {
|
|
19757
|
-
timeout: 15e3,
|
|
19758
|
-
env
|
|
19759
|
-
}, (err, stdout, stderr) => {
|
|
19760
|
-
if (err) return resolve(null);
|
|
19761
|
-
resolve(/\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?/.exec(`${stdout} ${stderr}`)?.[0] ?? null);
|
|
19762
|
-
});
|
|
19763
|
-
});
|
|
19764
|
-
}
|
|
19765
|
-
/** Whether version `a` is at least `b` (numbers only: 2.1.259). */
|
|
19766
|
-
function atLeast(a, b) {
|
|
19767
|
-
const parts = (v) => v.split(/[-+]/)[0]?.split(".").map(Number) ?? [];
|
|
19768
|
-
const [x, y] = [parts(a), parts(b)];
|
|
19769
|
-
for (let i = 0; i < Math.max(x.length, y.length); i++) {
|
|
19770
|
-
const d = (x[i] ?? 0) - (y[i] ?? 0);
|
|
19771
|
-
if (d) return d > 0;
|
|
19772
|
-
}
|
|
19773
|
-
return true;
|
|
19774
|
-
}
|
|
19775
20610
|
// src/runner/prompt.ts
|
|
19776
20611
|
/** The JSON Schema the agent's last message follows (strict, as Codex's --output-schema needs). */
|
|
19777
20612
|
const OUTCOME_SCHEMA = {
|
|
@@ -19847,6 +20682,109 @@ function buildPrompt({ task, comments, branch }) {
|
|
|
19847
20682
|
lines.push("", "## How to work", "", `- You're in a git checkout of the project, on the branch ${branch}, made for this task. Stay on it.`, "- Do what the task asks, and only that. Follow the repository's own instructions (CLAUDE.md, AGENTS.md, CONTRIBUTING, the README) and run its checks (tests, lint, typecheck) before you finish.", "- Commit your work on this branch with clear messages (if git won't let you, leave the changes: they're committed for you). Don't push, don't open a pull request and don't change the monoban board: that's done for you when you finish.", "- Nobody is watching to answer questions. When something is unclear, make a reasonable choice and say so in your summary. Stop as blocked only when you can't go on without an answer.", "", "End with a JSON object, and nothing after it: {\"status\": \"done\" or \"blocked\", \"summary\": what you changed and how you checked it, \"prTitle\": a pull request title, \"question\": what you need to know when blocked, else \"\"}.");
|
|
19848
20683
|
return lines.join("\n");
|
|
19849
20684
|
}
|
|
20685
|
+
// src/runner/redact.ts
|
|
20686
|
+
/**
|
|
20687
|
+
* What the runner sends the board from an agent's output, secrets out: a command line, an error, a step's message.
|
|
20688
|
+
* Every message a run reports goes through `clip()` (docs/PLAN-AGENT-LOOPS.md §1.6: agentpipe's too).
|
|
20689
|
+
*/
|
|
20690
|
+
/** Secrets a command line or an error might carry, kept out of what the board shows. */
|
|
20691
|
+
const SECRETS = [
|
|
20692
|
+
[/\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})/g, "…"],
|
|
20693
|
+
[/\bsk-[A-Za-z0-9_-]{16,}/g, "…"],
|
|
20694
|
+
[/\bmbn_[A-Za-z0-9_]{8,}/g, "…"],
|
|
20695
|
+
[/\bxox[abprs]-[A-Za-z0-9-]{10,}/g, "…"],
|
|
20696
|
+
[/\bAKIA[0-9A-Z]{16}\b/g, "…"],
|
|
20697
|
+
[/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi, "$1…"],
|
|
20698
|
+
[/((?:token|secret|passw(?:or)?d|api[_-]?key|auth)[A-Za-z_]*["']?\s*[=:]\s*["']?)(?!Bearer\b|Basic\b)[^\s"']+/gi, "$1…"]
|
|
20699
|
+
];
|
|
20700
|
+
function redact(text) {
|
|
20701
|
+
return SECRETS.reduce((t, [pattern, by]) => t.replace(pattern, by), text);
|
|
20702
|
+
}
|
|
20703
|
+
/** A message the API takes (and the board shows), secrets out. */
|
|
20704
|
+
function clip(text, max = 2e3) {
|
|
20705
|
+
const clean = redact(text).trim();
|
|
20706
|
+
return clean.length > max ? `${clean.slice(0, max - 1)}…` : clean;
|
|
20707
|
+
}
|
|
20708
|
+
// src/runner/steps.ts
|
|
20709
|
+
const ok = (value, data) => ({
|
|
20710
|
+
status: "ok",
|
|
20711
|
+
...value !== void 0 && { value },
|
|
20712
|
+
...data && { data }
|
|
20713
|
+
});
|
|
20714
|
+
const skipped = (message, data) => ({
|
|
20715
|
+
status: "skipped",
|
|
20716
|
+
message,
|
|
20717
|
+
...data && { data }
|
|
20718
|
+
});
|
|
20719
|
+
const failed = (message, value, data) => ({
|
|
20720
|
+
status: "failed",
|
|
20721
|
+
message,
|
|
20722
|
+
...value !== void 0 && { value },
|
|
20723
|
+
...data && { data }
|
|
20724
|
+
});
|
|
20725
|
+
function steps(report, isCancelled = () => false) {
|
|
20726
|
+
const attempts = /* @__PURE__ */ new Map();
|
|
20727
|
+
let stoppedBy = null;
|
|
20728
|
+
/**
|
|
20729
|
+
* Runs step `name`: unless the run was cancelled or an earlier step stopped it (`always` runs it anyway). A step
|
|
20730
|
+
* that throws finishes `failed`, saying why, and the error goes on to the caller.
|
|
20731
|
+
*/
|
|
20732
|
+
async function step(name, fn, { always = false } = {}) {
|
|
20733
|
+
if (!always && isCancelled()) return {
|
|
20734
|
+
ran: false,
|
|
20735
|
+
why: "cancelled"
|
|
20736
|
+
};
|
|
20737
|
+
if (!always && stoppedBy) return {
|
|
20738
|
+
ran: false,
|
|
20739
|
+
why: "stopped"
|
|
20740
|
+
};
|
|
20741
|
+
const attempt = (attempts.get(name) ?? 0) + 1;
|
|
20742
|
+
attempts.set(name, attempt);
|
|
20743
|
+
const started = Date.now();
|
|
20744
|
+
report.event({
|
|
20745
|
+
kind: "step_started",
|
|
20746
|
+
step: name,
|
|
20747
|
+
attempt,
|
|
20748
|
+
status: "running"
|
|
20749
|
+
});
|
|
20750
|
+
const finish = ({ status, message, data }) => {
|
|
20751
|
+
if (status !== "ok" && status !== "skipped") stoppedBy ??= name;
|
|
20752
|
+
report.event({
|
|
20753
|
+
kind: "step_finished",
|
|
20754
|
+
step: name,
|
|
20755
|
+
attempt,
|
|
20756
|
+
status,
|
|
20757
|
+
...message && { message: clip(message) },
|
|
20758
|
+
data: {
|
|
20759
|
+
durationMs: Date.now() - started,
|
|
20760
|
+
...data
|
|
20761
|
+
}
|
|
20762
|
+
});
|
|
20763
|
+
};
|
|
20764
|
+
let end;
|
|
20765
|
+
try {
|
|
20766
|
+
end = await fn();
|
|
20767
|
+
} catch (err) {
|
|
20768
|
+
finish({
|
|
20769
|
+
status: "failed",
|
|
20770
|
+
message: err.message
|
|
20771
|
+
});
|
|
20772
|
+
throw err;
|
|
20773
|
+
}
|
|
20774
|
+
finish(end);
|
|
20775
|
+
return {
|
|
20776
|
+
ran: true,
|
|
20777
|
+
status: end.status,
|
|
20778
|
+
message: end.message ?? null,
|
|
20779
|
+
value: end.value
|
|
20780
|
+
};
|
|
20781
|
+
}
|
|
20782
|
+
return {
|
|
20783
|
+
step,
|
|
20784
|
+
/** The step that stopped the run, if one did. */
|
|
20785
|
+
stoppedBy: () => stoppedBy
|
|
20786
|
+
};
|
|
20787
|
+
}
|
|
19850
20788
|
// src/runner/workspace.ts
|
|
19851
20789
|
var WorkspaceError = class extends Error {};
|
|
19852
20790
|
/** Runs a command in `cwd`: its stdout, or a WorkspaceError with what it said on stderr. */
|
|
@@ -19946,24 +20884,6 @@ function workspace(cwd, env = process.env) {
|
|
|
19946
20884
|
};
|
|
19947
20885
|
}
|
|
19948
20886
|
// src/runner/agents/coding.ts
|
|
19949
|
-
/** Secrets a command line or an error might carry, kept out of what the board shows. */
|
|
19950
|
-
const SECRETS = [
|
|
19951
|
-
[/\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})/g, "…"],
|
|
19952
|
-
[/\bsk-[A-Za-z0-9_-]{16,}/g, "…"],
|
|
19953
|
-
[/\bmbn_[A-Za-z0-9_]{8,}/g, "…"],
|
|
19954
|
-
[/\bxox[abprs]-[A-Za-z0-9-]{10,}/g, "…"],
|
|
19955
|
-
[/\bAKIA[0-9A-Z]{16}\b/g, "…"],
|
|
19956
|
-
[/(Bearer\s+)[A-Za-z0-9._~+/=-]+/gi, "$1…"],
|
|
19957
|
-
[/((?:token|secret|passw(?:or)?d|api[_-]?key|auth)[A-Za-z_]*["']?\s*[=:]\s*["']?)(?!Bearer\b|Basic\b)[^\s"']+/gi, "$1…"]
|
|
19958
|
-
];
|
|
19959
|
-
function redact(text) {
|
|
19960
|
-
return SECRETS.reduce((t, [pattern, by]) => t.replace(pattern, by), text);
|
|
19961
|
-
}
|
|
19962
|
-
/** A message the API takes (and the board shows), secrets out. */
|
|
19963
|
-
function clip(text, max = 2e3) {
|
|
19964
|
-
const clean = redact(text).trim();
|
|
19965
|
-
return clean.length > max ? `${clean.slice(0, max - 1)}…` : clean;
|
|
19966
|
-
}
|
|
19967
20887
|
/** A command's first line ("pnpm test"), for "$ pnpm test". */
|
|
19968
20888
|
function firstLine(command) {
|
|
19969
20889
|
const text = typeof command === "string" ? command.trim() : "";
|
|
@@ -20023,26 +20943,7 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
20023
20943
|
start(run, report) {
|
|
20024
20944
|
let cancelled = false;
|
|
20025
20945
|
let agent = null;
|
|
20026
|
-
const
|
|
20027
|
-
const started = Date.now();
|
|
20028
|
-
report.event({
|
|
20029
|
-
kind: "step_started",
|
|
20030
|
-
step,
|
|
20031
|
-
attempt: 1,
|
|
20032
|
-
status: "running"
|
|
20033
|
-
});
|
|
20034
|
-
return (status, message, data = {}) => report.event({
|
|
20035
|
-
kind: "step_finished",
|
|
20036
|
-
step,
|
|
20037
|
-
attempt: 1,
|
|
20038
|
-
status,
|
|
20039
|
-
...message && { message: clip(message) },
|
|
20040
|
-
data: {
|
|
20041
|
-
durationMs: Date.now() - started,
|
|
20042
|
-
...data
|
|
20043
|
-
}
|
|
20044
|
-
});
|
|
20045
|
-
};
|
|
20946
|
+
const { step } = steps(report, () => cancelled);
|
|
20046
20947
|
const warn = (message) => report.event({
|
|
20047
20948
|
kind: "warning",
|
|
20048
20949
|
message: clip(message)
|
|
@@ -20052,146 +20953,169 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
20052
20953
|
const tell = (body) => board.comment(ref, body).catch((err) => warn(`Couldn't comment on ${ref}: ${err.message}`));
|
|
20053
20954
|
const flow = async () => {
|
|
20054
20955
|
const ws = open(run.workdir, env);
|
|
20055
|
-
|
|
20056
|
-
|
|
20057
|
-
|
|
20058
|
-
|
|
20059
|
-
|
|
20060
|
-
|
|
20061
|
-
|
|
20062
|
-
|
|
20063
|
-
|
|
20064
|
-
|
|
20065
|
-
|
|
20066
|
-
|
|
20067
|
-
|
|
20068
|
-
};
|
|
20956
|
+
const prepared = await step("prepare", async () => {
|
|
20957
|
+
try {
|
|
20958
|
+
if (await ws.dirty()) return failed(`${run.workdir} has uncommitted changes: commit or stash them, then run it again.`);
|
|
20959
|
+
const { task, comments } = await board.task(run.ref);
|
|
20960
|
+
ref = task.ref;
|
|
20961
|
+
const base = await ws.baseBranch();
|
|
20962
|
+
if (!await ws.fetch(base)) warn(`Couldn't fetch ${base} from origin: it starts from the copy here.`);
|
|
20963
|
+
const branch = branchName(task.ref, task.title);
|
|
20964
|
+
await ws.checkout(branch, base);
|
|
20965
|
+
const startSha = await ws.head();
|
|
20966
|
+
const moved = await board.startWork(ref).catch((err) => {
|
|
20967
|
+
warn(`Couldn't move ${ref}: ${err.message}`);
|
|
20968
|
+
return null;
|
|
20969
|
+
});
|
|
20970
|
+
if (moved) report.event({
|
|
20971
|
+
kind: "board",
|
|
20972
|
+
message: clip(moved)
|
|
20973
|
+
});
|
|
20974
|
+
return ok({
|
|
20975
|
+
branch,
|
|
20976
|
+
base,
|
|
20977
|
+
startSha,
|
|
20978
|
+
title: task.title,
|
|
20979
|
+
prompt: buildPrompt({
|
|
20980
|
+
task,
|
|
20981
|
+
comments,
|
|
20982
|
+
branch
|
|
20983
|
+
})
|
|
20984
|
+
});
|
|
20985
|
+
} catch (err) {
|
|
20986
|
+
return failed(clip(`Couldn't get the folder ready: ${err.message}`, 1e3));
|
|
20069
20987
|
}
|
|
20070
|
-
|
|
20071
|
-
|
|
20072
|
-
|
|
20073
|
-
|
|
20074
|
-
|
|
20075
|
-
|
|
20076
|
-
await ws.checkout(branch, base);
|
|
20077
|
-
startSha = await ws.head();
|
|
20078
|
-
const moved = await board.startWork(ref).catch((err) => {
|
|
20079
|
-
warn(`Couldn't move ${ref}: ${err.message}`);
|
|
20080
|
-
return null;
|
|
20081
|
-
});
|
|
20082
|
-
if (moved) report.event({
|
|
20083
|
-
kind: "board",
|
|
20084
|
-
message: clip(moved)
|
|
20085
|
-
});
|
|
20086
|
-
prompt = buildPrompt({
|
|
20087
|
-
task,
|
|
20088
|
-
comments,
|
|
20089
|
-
branch
|
|
20090
|
-
});
|
|
20091
|
-
end("ok");
|
|
20092
|
-
} catch (err) {
|
|
20093
|
-
const reason = clip(`Couldn't get the folder ready: ${err.message}`, 1e3);
|
|
20094
|
-
end("failed", reason);
|
|
20095
|
-
return {
|
|
20096
|
-
status: "failed",
|
|
20097
|
-
reason
|
|
20098
|
-
};
|
|
20099
|
-
}
|
|
20988
|
+
}, { always: true });
|
|
20989
|
+
if (!prepared.ran || !prepared.value) return {
|
|
20990
|
+
status: "failed",
|
|
20991
|
+
reason: prepared.ran ? prepared.message : null
|
|
20992
|
+
};
|
|
20993
|
+
const { branch, base, startSha, title, prompt } = prepared.value;
|
|
20100
20994
|
if (cancelled) return {
|
|
20101
20995
|
status: "cancelled",
|
|
20102
20996
|
reason: "Cancelled before the agent started."
|
|
20103
20997
|
};
|
|
20104
|
-
|
|
20105
|
-
|
|
20106
|
-
|
|
20107
|
-
kind: "warning",
|
|
20108
|
-
step: "code",
|
|
20109
|
-
message: clip(limited.warning)
|
|
20110
|
-
});
|
|
20111
|
-
const asked = limited ? {
|
|
20112
|
-
...run,
|
|
20113
|
-
options: limited.options
|
|
20114
|
-
} : run;
|
|
20115
|
-
const dir = await mkdtemp(join(tmpdir(), "monoban-run-"));
|
|
20116
|
-
const schemaFile = join(dir, "outcome.schema.json");
|
|
20117
|
-
const schema = JSON.stringify(OUTCOME_SCHEMA);
|
|
20118
|
-
await writeFile(schemaFile, schema);
|
|
20119
|
-
const reader = spec.reader([run.workdir, await realpath(run.workdir).catch(() => run.workdir)]);
|
|
20120
|
-
const activity = throttled((message) => report.event({
|
|
20121
|
-
kind: "activity",
|
|
20122
|
-
step: "code",
|
|
20123
|
-
message: clip(message, 200)
|
|
20124
|
-
}), activityMs);
|
|
20125
|
-
const out = {
|
|
20126
|
-
activity: (m) => m.trim() && activity.push(m),
|
|
20127
|
-
warning: (m) => report.event({
|
|
20998
|
+
const coded = await step("code", async () => {
|
|
20999
|
+
const limited = spec.limit?.(run.options);
|
|
21000
|
+
if (limited) report.event({
|
|
20128
21001
|
kind: "warning",
|
|
20129
21002
|
step: "code",
|
|
20130
|
-
message: clip(
|
|
20131
|
-
})
|
|
20132
|
-
|
|
21003
|
+
message: clip(limited.warning)
|
|
21004
|
+
});
|
|
21005
|
+
const asked = limited ? {
|
|
21006
|
+
...run,
|
|
21007
|
+
options: limited.options
|
|
21008
|
+
} : run;
|
|
21009
|
+
const dir = await mkdtemp(join(tmpdir(), "monoban-run-"));
|
|
21010
|
+
const schemaFile = join(dir, "outcome.schema.json");
|
|
21011
|
+
const schema = JSON.stringify(OUTCOME_SCHEMA);
|
|
21012
|
+
await writeFile(schemaFile, schema);
|
|
21013
|
+
const reader = spec.reader([run.workdir, await realpath(run.workdir).catch(() => run.workdir)]);
|
|
21014
|
+
const activity = throttled((message) => report.event({
|
|
21015
|
+
kind: "activity",
|
|
21016
|
+
step: "code",
|
|
21017
|
+
message: clip(message, 200)
|
|
21018
|
+
}), activityMs);
|
|
21019
|
+
const out = {
|
|
21020
|
+
activity: (m) => m.trim() && activity.push(m),
|
|
21021
|
+
warning: (m) => report.event({
|
|
21022
|
+
kind: "warning",
|
|
21023
|
+
step: "code",
|
|
21024
|
+
message: clip(m)
|
|
21025
|
+
}),
|
|
21026
|
+
externalId: (id) => report.update({ externalId: id.slice(0, 128) })
|
|
21027
|
+
};
|
|
21028
|
+
agent = startProcess({
|
|
21029
|
+
command,
|
|
21030
|
+
args: spec.args(asked, {
|
|
21031
|
+
schema,
|
|
21032
|
+
schemaFile
|
|
21033
|
+
}, extra),
|
|
21034
|
+
cwd: run.workdir,
|
|
21035
|
+
env,
|
|
21036
|
+
stdin: prompt,
|
|
21037
|
+
onLine: (line) => {
|
|
21038
|
+
try {
|
|
21039
|
+
reader.line(line, out);
|
|
21040
|
+
} catch {}
|
|
21041
|
+
},
|
|
21042
|
+
...spawn && { spawn },
|
|
21043
|
+
...graceMs !== void 0 && { graceMs }
|
|
21044
|
+
});
|
|
21045
|
+
if (cancelled) agent.stop();
|
|
21046
|
+
const exit = await agent.done;
|
|
21047
|
+
agent = null;
|
|
21048
|
+
activity.stop();
|
|
21049
|
+
await rm$1(dir, {
|
|
21050
|
+
recursive: true,
|
|
21051
|
+
force: true
|
|
21052
|
+
});
|
|
21053
|
+
const result = reader.result();
|
|
21054
|
+
const data = {};
|
|
21055
|
+
if (result.costUsd !== null) {
|
|
21056
|
+
data.costUsd = result.costUsd;
|
|
21057
|
+
report.update({ costUsd: Math.round(result.costUsd * 1e4) / 1e4 });
|
|
21058
|
+
}
|
|
21059
|
+
if (result.tokens !== null) data.tokens = result.tokens;
|
|
21060
|
+
const outcome = parseOutcome(result.answer);
|
|
21061
|
+
const value = {
|
|
21062
|
+
spawnError: exit.spawnError,
|
|
21063
|
+
result,
|
|
21064
|
+
outcome,
|
|
21065
|
+
failure: null
|
|
21066
|
+
};
|
|
21067
|
+
if (cancelled) return {
|
|
21068
|
+
status: "cancelled",
|
|
21069
|
+
data,
|
|
21070
|
+
value
|
|
21071
|
+
};
|
|
21072
|
+
value.failure = exit.spawnError ?? result.failure ?? (exit.code === 0 ? null : `${label} stopped (exit code ${exit.code ?? "none"})${exit.lastError ? `: ${exit.lastError}` : "."}`);
|
|
21073
|
+
if (value.failure) return failed(value.failure, value, data);
|
|
21074
|
+
if (outcome?.status === "blocked") return {
|
|
21075
|
+
status: "needs_human",
|
|
21076
|
+
message: outcome.question || outcome.summary,
|
|
21077
|
+
data,
|
|
21078
|
+
value
|
|
21079
|
+
};
|
|
21080
|
+
return ok(value, data);
|
|
21081
|
+
}, { always: true });
|
|
21082
|
+
if (!coded.ran || !coded.value) return {
|
|
21083
|
+
status: "failed",
|
|
21084
|
+
reason: null
|
|
20133
21085
|
};
|
|
20134
|
-
|
|
20135
|
-
|
|
20136
|
-
|
|
20137
|
-
schema,
|
|
20138
|
-
schemaFile
|
|
20139
|
-
}, extra),
|
|
20140
|
-
cwd: run.workdir,
|
|
20141
|
-
env,
|
|
20142
|
-
stdin: prompt,
|
|
20143
|
-
onLine: (line) => {
|
|
20144
|
-
try {
|
|
20145
|
-
reader.line(line, out);
|
|
20146
|
-
} catch {}
|
|
20147
|
-
},
|
|
20148
|
-
...spawn && { spawn },
|
|
20149
|
-
...graceMs !== void 0 && { graceMs }
|
|
20150
|
-
});
|
|
20151
|
-
if (cancelled) agent.stop();
|
|
20152
|
-
const exit = await agent.done;
|
|
20153
|
-
agent = null;
|
|
20154
|
-
activity.stop();
|
|
20155
|
-
await rm(dir, {
|
|
20156
|
-
recursive: true,
|
|
20157
|
-
force: true
|
|
20158
|
-
});
|
|
20159
|
-
const result = reader.result();
|
|
20160
|
-
const data = {};
|
|
20161
|
-
if (result.costUsd !== null) {
|
|
20162
|
-
data.costUsd = result.costUsd;
|
|
20163
|
-
report.update({ costUsd: Math.round(result.costUsd * 1e4) / 1e4 });
|
|
20164
|
-
}
|
|
20165
|
-
if (result.tokens !== null) data.tokens = result.tokens;
|
|
20166
|
-
const outcome = parseOutcome(result.answer);
|
|
20167
|
-
let failure = null;
|
|
20168
|
-
if (cancelled) end("cancelled", null, data);
|
|
20169
|
-
else {
|
|
20170
|
-
failure = exit.spawnError ?? result.failure ?? (exit.code === 0 ? null : `${label} stopped (exit code ${exit.code ?? "none"})${exit.lastError ? `: ${exit.lastError}` : "."}`);
|
|
20171
|
-
if (failure) end("failed", failure, data);
|
|
20172
|
-
else if (outcome?.status === "blocked") end("needs_human", outcome.question || outcome.summary, data);
|
|
20173
|
-
else end("ok", null, data);
|
|
20174
|
-
}
|
|
20175
|
-
if (exit.spawnError) return {
|
|
21086
|
+
const { spawnError, result, outcome } = coded.value;
|
|
21087
|
+
let { failure } = coded.value;
|
|
21088
|
+
if (spawnError) return {
|
|
20176
21089
|
status: "failed",
|
|
20177
|
-
reason: clip(
|
|
21090
|
+
reason: clip(spawnError, 1e3)
|
|
20178
21091
|
};
|
|
20179
|
-
end = begin("commit");
|
|
20180
21092
|
const unfinished = cancelled || failure !== null;
|
|
20181
|
-
|
|
20182
|
-
|
|
20183
|
-
|
|
20184
|
-
|
|
20185
|
-
|
|
20186
|
-
|
|
20187
|
-
|
|
20188
|
-
|
|
20189
|
-
|
|
20190
|
-
|
|
20191
|
-
|
|
20192
|
-
|
|
20193
|
-
|
|
20194
|
-
|
|
21093
|
+
const committed = await step("commit", async () => {
|
|
21094
|
+
try {
|
|
21095
|
+
const message = unfinished ? `${ref}: work in progress (the ${label} run ${cancelled ? "was cancelled" : "failed"})` : `${ref}: ${outcome?.prTitle || title}`;
|
|
21096
|
+
const left = await ws.commitAll(message);
|
|
21097
|
+
const commits = await ws.commitsSince(startSha);
|
|
21098
|
+
const value = {
|
|
21099
|
+
commits,
|
|
21100
|
+
left
|
|
21101
|
+
};
|
|
21102
|
+
return commits ? ok(value, { commits }) : {
|
|
21103
|
+
...skipped("nothing changed", { commits }),
|
|
21104
|
+
value
|
|
21105
|
+
};
|
|
21106
|
+
} catch (err) {
|
|
21107
|
+
failure ??= `Couldn't commit its work: ${err.message}`;
|
|
21108
|
+
return failed(err.message, {
|
|
21109
|
+
commits: 0,
|
|
21110
|
+
left: false
|
|
21111
|
+
});
|
|
21112
|
+
}
|
|
21113
|
+
}, { always: true });
|
|
21114
|
+
const { commits = 0, left = false } = committed.ran ? committed.value ?? {} : {};
|
|
21115
|
+
if (left && unfinished) report.event({
|
|
21116
|
+
kind: "board",
|
|
21117
|
+
message: `kept its unfinished work on ${branch}`
|
|
21118
|
+
});
|
|
20195
21119
|
const kept = commits ? `\n\nIts work so far is on the branch \`${branch}\`.` : "";
|
|
20196
21120
|
if (cancelled) return {
|
|
20197
21121
|
status: "cancelled",
|
|
@@ -20227,13 +21151,18 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
20227
21151
|
}
|
|
20228
21152
|
let url = null;
|
|
20229
21153
|
const prTitle = clip(outcome?.prTitle || `${ref}: ${title}`, 200);
|
|
20230
|
-
if (run.options.pr === "none")
|
|
21154
|
+
if (run.options.pr === "none") await step("pr", async () => skipped(`none asked for: the work is on ${branch}`));
|
|
20231
21155
|
else {
|
|
20232
|
-
|
|
20233
|
-
|
|
20234
|
-
|
|
20235
|
-
|
|
20236
|
-
|
|
21156
|
+
const up = async (fn) => {
|
|
21157
|
+
try {
|
|
21158
|
+
await fn();
|
|
21159
|
+
return ok();
|
|
21160
|
+
} catch (err) {
|
|
21161
|
+
return failed(clip(err.message, 1e3));
|
|
21162
|
+
}
|
|
21163
|
+
};
|
|
21164
|
+
const pushed = await step("push", () => up(() => ws.push(branch)));
|
|
21165
|
+
const opened = pushed.ran && pushed.status === "ok" ? await step("pr", () => up(async () => {
|
|
20237
21166
|
url = await ws.pullRequestOf(branch) ?? await ws.openPullRequest({
|
|
20238
21167
|
base,
|
|
20239
21168
|
branch,
|
|
@@ -20248,10 +21177,9 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
20248
21177
|
message: url,
|
|
20249
21178
|
data: { url }
|
|
20250
21179
|
});
|
|
20251
|
-
|
|
20252
|
-
|
|
20253
|
-
const reason =
|
|
20254
|
-
end("failed", reason);
|
|
21180
|
+
})) : pushed;
|
|
21181
|
+
if (!opened.ran || opened.status !== "ok") {
|
|
21182
|
+
const reason = opened.ran && opened.message || "";
|
|
20255
21183
|
await tell(`${label} finished, but couldn't put it up for review: ${reason}${kept}`);
|
|
20256
21184
|
return {
|
|
20257
21185
|
status: "failed",
|
|
@@ -20259,18 +21187,19 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
20259
21187
|
};
|
|
20260
21188
|
}
|
|
20261
21189
|
}
|
|
20262
|
-
|
|
20263
|
-
|
|
20264
|
-
|
|
20265
|
-
|
|
20266
|
-
|
|
20267
|
-
|
|
20268
|
-
|
|
20269
|
-
|
|
20270
|
-
|
|
20271
|
-
|
|
20272
|
-
|
|
20273
|
-
|
|
21190
|
+
await step("report", async () => {
|
|
21191
|
+
try {
|
|
21192
|
+
if (url) await board.attach(ref, url, prTitle, run.options.pr === "draft");
|
|
21193
|
+
await board.comment(ref, `${label} finished${url ? `: ${url}` : `, on the branch \`${branch}\``}.${summary ? `\n\n${clip(summary, 6e3)}` : ""}`);
|
|
21194
|
+
report.event({
|
|
21195
|
+
kind: "board",
|
|
21196
|
+
message: url ? "attached the pull request, and commented" : "commented"
|
|
21197
|
+
});
|
|
21198
|
+
return ok();
|
|
21199
|
+
} catch (err) {
|
|
21200
|
+
return failed(err.message);
|
|
21201
|
+
}
|
|
21202
|
+
});
|
|
20274
21203
|
return {
|
|
20275
21204
|
status: "succeeded",
|
|
20276
21205
|
reason: null
|
|
@@ -20486,6 +21415,482 @@ const codexSpec = ({ allowFullAccess = false } = {}) => ({
|
|
|
20486
21415
|
reader: codexReader
|
|
20487
21416
|
});
|
|
20488
21417
|
codexSpec();
|
|
21418
|
+
// src/runner/recipes/deliver.ts
|
|
21419
|
+
/**
|
|
21420
|
+
* `deliver` (docs/PLAN-AGENT-LOOPS.md §1.6): takes a task and delivers it as a pull request: `implement` opens it
|
|
21421
|
+
* (a draft), `review` reviews and fixes it, `checks` sees CI green (repairing it) and marks it ready, `feedback`
|
|
21422
|
+
* answers its review comments, and `merge` merges it when the run may (plan §1.12: the loop merges, a browser queued
|
|
21423
|
+
* the task, nothing but a browser rewrote it since, and this machine allows it). Otherwise the run ends with its pull
|
|
21424
|
+
* request ready for you to merge, saying why.
|
|
21425
|
+
*/
|
|
21426
|
+
/** A deliver loop's options this recipe reads (the run's plan has them as the loop had them). */
|
|
21427
|
+
function options(run) {
|
|
21428
|
+
const o = run.plan.options;
|
|
21429
|
+
return {
|
|
21430
|
+
checksMinutes: o.checksMinutes ?? LOOP_DEFAULTS.checksMinutes,
|
|
21431
|
+
reviewTier: o.reviewTier ?? null
|
|
21432
|
+
};
|
|
21433
|
+
}
|
|
21434
|
+
/** The loop's review tier, if it names one: the preflight checks the folder's agentpipe has it. */
|
|
21435
|
+
const reviewTierOf = (run) => options(run).reviewTier;
|
|
21436
|
+
/** Money as agentpipe takes it: dollars, to the cent. */
|
|
21437
|
+
const usd = (n) => (Math.floor(n * 100) / 100).toFixed(2);
|
|
21438
|
+
/**
|
|
21439
|
+
* `agentpipe run` on the run's task: always `--autonomous` (nobody is there to answer), from an up-to-date base
|
|
21440
|
+
* (`--fresh-base`), opening a draft pull request (`checks` marks it ready once it's green), on what is left of the
|
|
21441
|
+
* budget. The dry run is the same command with `--dry-run`, so it checks what the run will do.
|
|
21442
|
+
*/
|
|
21443
|
+
function implementArgs(run, budgetUsd) {
|
|
21444
|
+
return [
|
|
21445
|
+
"run",
|
|
21446
|
+
run.workdir,
|
|
21447
|
+
"--from-issue",
|
|
21448
|
+
run.ref ?? "",
|
|
21449
|
+
"--json",
|
|
21450
|
+
"--autonomous",
|
|
21451
|
+
"--fresh-base",
|
|
21452
|
+
"--draft",
|
|
21453
|
+
"--budget",
|
|
21454
|
+
usd(budgetUsd)
|
|
21455
|
+
];
|
|
21456
|
+
}
|
|
21457
|
+
/** `agentpipe review` on the pull request, fixing what it finds, on the loop's tier when it names one. */
|
|
21458
|
+
function reviewArgs(run, pr, budgetUsd) {
|
|
21459
|
+
const tier = options(run).reviewTier;
|
|
21460
|
+
return [
|
|
21461
|
+
"review",
|
|
21462
|
+
String(pr.number),
|
|
21463
|
+
run.workdir,
|
|
21464
|
+
"--fix",
|
|
21465
|
+
"--json",
|
|
21466
|
+
"--budget",
|
|
21467
|
+
usd(budgetUsd),
|
|
21468
|
+
...tier ? ["--tier", tier] : []
|
|
21469
|
+
];
|
|
21470
|
+
}
|
|
21471
|
+
/**
|
|
21472
|
+
* `agentpipe ship --no-merge`: watches CI until it is green (re-running flakes, repairing what fails, within what
|
|
21473
|
+
* is left of the run's budget, on top of what earlier ships of this pull request spent) and marks it ready, giving
|
|
21474
|
+
* up at the loop's `checksMinutes`. `--force` takes over a lease an earlier ship left behind (leases.ts).
|
|
21475
|
+
*/
|
|
21476
|
+
function checksArgs(run, pr, budgetUsd, { force = false } = {}) {
|
|
21477
|
+
return [
|
|
21478
|
+
"ship",
|
|
21479
|
+
String(pr.number),
|
|
21480
|
+
run.workdir,
|
|
21481
|
+
"--no-merge",
|
|
21482
|
+
"--json",
|
|
21483
|
+
"--deadline",
|
|
21484
|
+
String(options(run).checksMinutes * 60),
|
|
21485
|
+
"--additional-budget",
|
|
21486
|
+
usd(budgetUsd),
|
|
21487
|
+
...force ? ["--force"] : []
|
|
21488
|
+
];
|
|
21489
|
+
}
|
|
21490
|
+
/** `agentpipe address --apply --ship --no-merge`: answers the review comments, then sees CI green again. */
|
|
21491
|
+
function feedbackArgs(run, pr, budgetUsd) {
|
|
21492
|
+
return [
|
|
21493
|
+
"address",
|
|
21494
|
+
String(pr.number),
|
|
21495
|
+
run.workdir,
|
|
21496
|
+
"--apply",
|
|
21497
|
+
"--ship",
|
|
21498
|
+
"--no-merge",
|
|
21499
|
+
"--json",
|
|
21500
|
+
"--budget",
|
|
21501
|
+
usd(budgetUsd)
|
|
21502
|
+
];
|
|
21503
|
+
}
|
|
21504
|
+
/**
|
|
21505
|
+
* `agentpipe merge --expect-run`: merges the pull request only if it is the one this machine's run opened (its
|
|
21506
|
+
* store has the run, the branch is the run's, the author is the `gh` user), refusing a required review or a blocked
|
|
21507
|
+
* one (§1.7). A refusal says the command that unblocks it.
|
|
21508
|
+
*/
|
|
21509
|
+
function mergeArgs(run, pr, runId) {
|
|
21510
|
+
return [
|
|
21511
|
+
"merge",
|
|
21512
|
+
String(pr.number),
|
|
21513
|
+
run.workdir,
|
|
21514
|
+
"--expect-run",
|
|
21515
|
+
runId,
|
|
21516
|
+
"--json"
|
|
21517
|
+
];
|
|
21518
|
+
}
|
|
21519
|
+
/** A step on the run's pull request, skipped when it has none (`implement` found nothing to change). */
|
|
21520
|
+
const onPr = (fn) => (ctx) => ctx.pr ? fn(ctx, ctx.pr) : Promise.resolve(skipped("There's no pull request."));
|
|
21521
|
+
/** A step's ending from how its command ended: agentpipe's word, else why it stopped without one. */
|
|
21522
|
+
/**
|
|
21523
|
+
* What a refused merge says: agentpipe's reason, with the command that unblocks it. agentpipe names one for most
|
|
21524
|
+
* (`agentpipe merge 42 --force-merge-on-green` past a review objection, `agentpipe merge 42` once a required review
|
|
21525
|
+
* is given); where it doesn't (checks failing or still running, a pull request this run didn't open), the person
|
|
21526
|
+
* merges it.
|
|
21527
|
+
*/
|
|
21528
|
+
function unblocking(reason, pr) {
|
|
21529
|
+
const said = reason ?? "not merged";
|
|
21530
|
+
if (said.includes("`")) return said;
|
|
21531
|
+
return `${said}: merge #${pr.number} yourself once that's settled (\`gh pr merge ${pr.number}\`)`;
|
|
21532
|
+
}
|
|
21533
|
+
function endOf(result, what) {
|
|
21534
|
+
const value = {
|
|
21535
|
+
externalId: result.externalId,
|
|
21536
|
+
prUrl: result.prUrl
|
|
21537
|
+
};
|
|
21538
|
+
const data = result.costUsd ? { costUsd: result.costUsd } : void 0;
|
|
21539
|
+
const { ending, exit } = result;
|
|
21540
|
+
if (!ending) {
|
|
21541
|
+
if (exit.spawnError) return failed(exit.spawnError, value, data);
|
|
21542
|
+
const last = exit.lastError ? `: ${exit.lastError}` : ".";
|
|
21543
|
+
return failed(`${what} stopped (exit code ${exit.code ?? "none"}) without saying how it ended${last}`, value, data);
|
|
21544
|
+
}
|
|
21545
|
+
if (ending.status === "succeeded") return {
|
|
21546
|
+
status: "ok",
|
|
21547
|
+
...ending.reason && { message: ending.reason },
|
|
21548
|
+
value,
|
|
21549
|
+
...data && { data }
|
|
21550
|
+
};
|
|
21551
|
+
return {
|
|
21552
|
+
status: ending.status,
|
|
21553
|
+
...ending.reason && { message: ending.reason },
|
|
21554
|
+
value,
|
|
21555
|
+
...data && { data }
|
|
21556
|
+
};
|
|
21557
|
+
}
|
|
21558
|
+
const deliver = {
|
|
21559
|
+
steps: {
|
|
21560
|
+
implement: {
|
|
21561
|
+
pollSeconds: 15,
|
|
21562
|
+
run: async (ctx) => {
|
|
21563
|
+
if (!ctx.run.ref) return failed("A deliver run needs its task.");
|
|
21564
|
+
return endOf(await ctx.agentpipe(implementArgs(ctx.run, ctx.budgetUsd)), "agentpipe run");
|
|
21565
|
+
}
|
|
21566
|
+
},
|
|
21567
|
+
review: {
|
|
21568
|
+
pollSeconds: 15,
|
|
21569
|
+
run: onPr(async (ctx, pr) => endOf(await ctx.agentpipe(reviewArgs(ctx.run, pr, ctx.budgetUsd)), "agentpipe review"))
|
|
21570
|
+
},
|
|
21571
|
+
checks: {
|
|
21572
|
+
pollSeconds: null,
|
|
21573
|
+
run: onPr(async (ctx, pr) => {
|
|
21574
|
+
const args = checksArgs(ctx.run, pr, ctx.budgetUsd, { force: ctx.stranded(pr) });
|
|
21575
|
+
return endOf(await ctx.agentpipe(args), "agentpipe ship");
|
|
21576
|
+
})
|
|
21577
|
+
},
|
|
21578
|
+
feedback: {
|
|
21579
|
+
pollSeconds: 15,
|
|
21580
|
+
run: onPr(async (ctx, pr) => {
|
|
21581
|
+
const result = await ctx.agentpipe(feedbackArgs(ctx.run, pr, ctx.budgetUsd));
|
|
21582
|
+
if (result.said === "nothing_to_do") {
|
|
21583
|
+
const data = result.costUsd ? { costUsd: result.costUsd } : void 0;
|
|
21584
|
+
return skipped("There were no review comments to answer.", data);
|
|
21585
|
+
}
|
|
21586
|
+
return endOf(result, "agentpipe address");
|
|
21587
|
+
})
|
|
21588
|
+
},
|
|
21589
|
+
merge: {
|
|
21590
|
+
pollSeconds: 15,
|
|
21591
|
+
free: true,
|
|
21592
|
+
finishes: true,
|
|
21593
|
+
run: onPr(async (ctx, pr) => {
|
|
21594
|
+
if (!ctx.runId) return skipped("Ready for you to merge: agentpipe didn't say which run opened it.");
|
|
21595
|
+
const why = await ctx.mayMerge();
|
|
21596
|
+
if (why) return skipped(`Ready for you to merge: ${why}.`);
|
|
21597
|
+
const end = endOf(await ctx.agentpipe(mergeArgs(ctx.run, pr, ctx.runId)), "agentpipe merge");
|
|
21598
|
+
return end.status === "needs_human" ? {
|
|
21599
|
+
...end,
|
|
21600
|
+
message: unblocking(end.message, pr)
|
|
21601
|
+
} : end;
|
|
21602
|
+
})
|
|
21603
|
+
}
|
|
21604
|
+
},
|
|
21605
|
+
dryRun: (run) => run.ref ? [...implementArgs(run, run.budgetUsd), "--dry-run"] : null,
|
|
21606
|
+
tier: reviewTierOf,
|
|
21607
|
+
finished: ({ pr, last }) => {
|
|
21608
|
+
if (!pr) return null;
|
|
21609
|
+
if (last?.step === "merge" && last.status === "ok") return last.message ?? "Merged.";
|
|
21610
|
+
if (last?.step === "merge" && last.message) return last.message;
|
|
21611
|
+
return "Ready for you to merge.";
|
|
21612
|
+
}
|
|
21613
|
+
};
|
|
21614
|
+
// src/runner/recipes/leases.ts
|
|
21615
|
+
/**
|
|
21616
|
+
* `agentpipe ship` holds a lease on its pull request while it runs. Stopped with SIGTERM it frees it and says
|
|
21617
|
+
* `ship.end`; killed outright (or the machine restarted) it keeps it, and the next `ship` on that pull request is
|
|
21618
|
+
* refused unless it passes `--force` (docs/PLAN-AGENT-LOOPS.md §1.7, spike S8). So this machine notes each ship it
|
|
21619
|
+
* starts (agentpipe's pid, by pull request, in <config dir>/ships) and forgets it at `ship.end`: a note left with
|
|
21620
|
+
* its process gone is a lease nobody frees, the one case for `--force`.
|
|
21621
|
+
*/
|
|
21622
|
+
function shipLeases(env) {
|
|
21623
|
+
const dir = join(configDir(env), "ships");
|
|
21624
|
+
const file = (prUrl) => join(dir, `${createHash("sha256").update(prUrl).digest("hex").slice(0, 32)}.json`);
|
|
21625
|
+
return {
|
|
21626
|
+
/** A ship on `prUrl` started, as process `pid`. */
|
|
21627
|
+
started(prUrl, pid) {
|
|
21628
|
+
mkdirSync(dir, {
|
|
21629
|
+
recursive: true,
|
|
21630
|
+
mode: 448
|
|
21631
|
+
});
|
|
21632
|
+
writeFileSync(file(prUrl), JSON.stringify({
|
|
21633
|
+
prUrl,
|
|
21634
|
+
pid
|
|
21635
|
+
}), { mode: 384 });
|
|
21636
|
+
},
|
|
21637
|
+
/** It said `ship.end`: it freed its lease. */
|
|
21638
|
+
ended(prUrl) {
|
|
21639
|
+
rmSync(file(prUrl), { force: true });
|
|
21640
|
+
},
|
|
21641
|
+
/** A ship on `prUrl` ended without freeing its lease, and its process is gone: the next one passes `--force`. */
|
|
21642
|
+
stranded(prUrl) {
|
|
21643
|
+
let pid;
|
|
21644
|
+
try {
|
|
21645
|
+
pid = JSON.parse(readFileSync(file(prUrl), "utf8")).pid;
|
|
21646
|
+
} catch {
|
|
21647
|
+
return false;
|
|
21648
|
+
}
|
|
21649
|
+
if (typeof pid !== "number") return true;
|
|
21650
|
+
return !alive(pid);
|
|
21651
|
+
}
|
|
21652
|
+
};
|
|
21653
|
+
}
|
|
21654
|
+
function alive(pid) {
|
|
21655
|
+
try {
|
|
21656
|
+
process.kill(pid, 0);
|
|
21657
|
+
return true;
|
|
21658
|
+
} catch (err) {
|
|
21659
|
+
return err.code === "EPERM";
|
|
21660
|
+
}
|
|
21661
|
+
}
|
|
21662
|
+
// src/runner/recipes/index.ts
|
|
21663
|
+
/** A pull request's number, from its URL (…/pull/42), or null. */
|
|
21664
|
+
function prOf(url) {
|
|
21665
|
+
const n = url?.match(/\/pull\/(\d+)(?:[/?#]|$)/)?.[1];
|
|
21666
|
+
return url && n ? {
|
|
21667
|
+
url,
|
|
21668
|
+
number: Number(n)
|
|
21669
|
+
} : null;
|
|
21670
|
+
}
|
|
21671
|
+
const RECIPES = {
|
|
21672
|
+
deliver,
|
|
21673
|
+
scavenge: null
|
|
21674
|
+
};
|
|
21675
|
+
/** The recipes this monoban runs: a runner names these, of those its agentpipe can run (MON-202). */
|
|
21676
|
+
const RECIPES_HERE = RECIPE_NAMES.filter((name) => RECIPES[name] !== null);
|
|
21677
|
+
/** A step's name for an event: agentpipe's inner step under the recipe's (`implement.plan`), as the API takes it. */
|
|
21678
|
+
function innerStep(outer, inner) {
|
|
21679
|
+
if (!inner) return outer;
|
|
21680
|
+
return `${outer}.${inner.toLowerCase().replace(/[^a-z0-9_.-]+/g, "-")}`.slice(0, 40);
|
|
21681
|
+
}
|
|
21682
|
+
/** A note about a lease, which mustn't stop the run when this machine's config folder can't be written. */
|
|
21683
|
+
function safely(fn) {
|
|
21684
|
+
try {
|
|
21685
|
+
fn();
|
|
21686
|
+
return true;
|
|
21687
|
+
} catch {
|
|
21688
|
+
return false;
|
|
21689
|
+
}
|
|
21690
|
+
}
|
|
21691
|
+
/** A loop's run through its recipe: its steps in order, each confirmed with the server first. */
|
|
21692
|
+
function runRecipe(name, run, report, deps) {
|
|
21693
|
+
const recipe = RECIPES[name];
|
|
21694
|
+
let cancelled = false;
|
|
21695
|
+
let current = null;
|
|
21696
|
+
/** The step running now lets a cancel wait for it (RecipeStepRun.finishes). */
|
|
21697
|
+
let finishing = false;
|
|
21698
|
+
const { step } = steps(report, () => cancelled);
|
|
21699
|
+
/** What the run has spent so far, over all its commands. */
|
|
21700
|
+
let spent = 0;
|
|
21701
|
+
/** Its pull request, and the run id the server keeps: the first agentpipe run's (`merge --expect-run` needs it). */
|
|
21702
|
+
let pr = prOf(run.plan.prUrl);
|
|
21703
|
+
let runId = null;
|
|
21704
|
+
const leases = deps.leases ?? shipLeases(deps.env);
|
|
21705
|
+
const command = (outer) => async (args) => {
|
|
21706
|
+
if (cancelled) return {
|
|
21707
|
+
ending: {
|
|
21708
|
+
status: "cancelled",
|
|
21709
|
+
reason: "Cancelled."
|
|
21710
|
+
},
|
|
21711
|
+
exit: {
|
|
21712
|
+
code: null,
|
|
21713
|
+
spawnError: null,
|
|
21714
|
+
lastError: null
|
|
21715
|
+
},
|
|
21716
|
+
externalId: null,
|
|
21717
|
+
prUrl: null,
|
|
21718
|
+
costUsd: 0,
|
|
21719
|
+
said: null
|
|
21720
|
+
};
|
|
21721
|
+
let externalId = null;
|
|
21722
|
+
let prUrl = null;
|
|
21723
|
+
let cost = 0;
|
|
21724
|
+
const before = spent;
|
|
21725
|
+
const known = (url) => typeof url === "string" && url === pr?.url;
|
|
21726
|
+
const feed = agentpipeMapper({
|
|
21727
|
+
event: (e) => {
|
|
21728
|
+
if (e.kind === "pr_opened" && known(e.data?.url)) return;
|
|
21729
|
+
report.event({
|
|
21730
|
+
...e,
|
|
21731
|
+
...e.step !== void 0 && e.step !== null && { step: innerStep(outer, e.step) },
|
|
21732
|
+
...e.message && { message: clip(e.message) }
|
|
21733
|
+
});
|
|
21734
|
+
},
|
|
21735
|
+
update: (u) => {
|
|
21736
|
+
const { externalId: id, prUrl: url, costUsd, ...rest } = u;
|
|
21737
|
+
if (id) externalId = id;
|
|
21738
|
+
if (url) prUrl = url;
|
|
21739
|
+
if (costUsd !== void 0) {
|
|
21740
|
+
cost = costUsd;
|
|
21741
|
+
spent = before + cost;
|
|
21742
|
+
}
|
|
21743
|
+
const first = id && !runId ? id : null;
|
|
21744
|
+
if (first) runId = first;
|
|
21745
|
+
const said = {
|
|
21746
|
+
...rest,
|
|
21747
|
+
...first && { externalId: first },
|
|
21748
|
+
...url && !known(url) && { prUrl: url },
|
|
21749
|
+
...costUsd !== void 0 && { costUsd: Math.round(spent * 1e4) / 1e4 }
|
|
21750
|
+
};
|
|
21751
|
+
if (Object.keys(said).length) report.update(said);
|
|
21752
|
+
}
|
|
21753
|
+
});
|
|
21754
|
+
const ships = args[0] === "ship" || args[0] === "address" && args.includes("--ship");
|
|
21755
|
+
const shipping = () => args[0] === "ship" || ships && feed.runEnded() && feed.said() === "ok";
|
|
21756
|
+
const leased = ships ? pr : null;
|
|
21757
|
+
let noted = false;
|
|
21758
|
+
let stopping = false;
|
|
21759
|
+
/**
|
|
21760
|
+
* Once its ship loop says something (it holds the lease by then; a refused one says only `ship.end`, and must
|
|
21761
|
+
* not overwrite a note of the process that does hold it), note the lease. And a cancel that came while
|
|
21762
|
+
* `address` was finishing reaches the ship loop that follows: it's stopped as soon as it starts.
|
|
21763
|
+
*/
|
|
21764
|
+
const watch = (event) => {
|
|
21765
|
+
if (!shipping() || event.kind === "run.end") return;
|
|
21766
|
+
if (cancelled && !stopping) {
|
|
21767
|
+
stopping = true;
|
|
21768
|
+
started.terminate();
|
|
21769
|
+
}
|
|
21770
|
+
const pid = started.pid();
|
|
21771
|
+
if (noted || !leased || !pid || event.kind === "ship.end") return;
|
|
21772
|
+
noted = safely(() => leases.started(leased.url, pid));
|
|
21773
|
+
};
|
|
21774
|
+
const started = agentpipeCommand({
|
|
21775
|
+
command: deps.command,
|
|
21776
|
+
args,
|
|
21777
|
+
cwd: run.workdir,
|
|
21778
|
+
env: deps.env,
|
|
21779
|
+
monobanBin: deps.monobanBin,
|
|
21780
|
+
map: (event) => {
|
|
21781
|
+
feed.take(event);
|
|
21782
|
+
if (current) current.externalId = externalId;
|
|
21783
|
+
watch(event);
|
|
21784
|
+
},
|
|
21785
|
+
...deps.spawn && { spawn: deps.spawn }
|
|
21786
|
+
});
|
|
21787
|
+
current = {
|
|
21788
|
+
process: started,
|
|
21789
|
+
externalId: null,
|
|
21790
|
+
shipping,
|
|
21791
|
+
finishes: finishing
|
|
21792
|
+
};
|
|
21793
|
+
if (cancelled && !finishing) (shipping() ? started.terminate : started.interrupt)();
|
|
21794
|
+
const exit = await started.done;
|
|
21795
|
+
current = null;
|
|
21796
|
+
feed.flush();
|
|
21797
|
+
const said = feed.said();
|
|
21798
|
+
if (noted && leased && said !== null && said !== "ok") safely(() => leases.ended(leased.url));
|
|
21799
|
+
if (prUrl && !pr) pr = prOf(prUrl);
|
|
21800
|
+
return {
|
|
21801
|
+
ending: feed.ending(),
|
|
21802
|
+
exit,
|
|
21803
|
+
externalId,
|
|
21804
|
+
prUrl,
|
|
21805
|
+
costUsd: cost,
|
|
21806
|
+
said
|
|
21807
|
+
};
|
|
21808
|
+
};
|
|
21809
|
+
return {
|
|
21810
|
+
done: (async () => {
|
|
21811
|
+
if (!recipe) return {
|
|
21812
|
+
status: "failed",
|
|
21813
|
+
reason: `This monoban can't run ${name} loops yet.`
|
|
21814
|
+
};
|
|
21815
|
+
if (run.plan.from) return {
|
|
21816
|
+
status: "failed",
|
|
21817
|
+
reason: `This monoban can't continue a run from ${run.plan.from} yet.`
|
|
21818
|
+
};
|
|
21819
|
+
const order = RECIPES$1[name].steps;
|
|
21820
|
+
let last = null;
|
|
21821
|
+
for (const stepName of order) {
|
|
21822
|
+
const s = recipe.steps[stepName];
|
|
21823
|
+
if (!s) continue;
|
|
21824
|
+
const stop = await deps.recheck?.() ?? null;
|
|
21825
|
+
if (stop) return {
|
|
21826
|
+
status: "cancelled",
|
|
21827
|
+
reason: stop
|
|
21828
|
+
};
|
|
21829
|
+
if (cancelled) return {
|
|
21830
|
+
status: "cancelled",
|
|
21831
|
+
reason: "Cancelled."
|
|
21832
|
+
};
|
|
21833
|
+
const left = Math.max(0, Math.round((run.budgetUsd - spent) * 100) / 100);
|
|
21834
|
+
if (left < .1 && !s.free) return {
|
|
21835
|
+
status: "failed",
|
|
21836
|
+
reason: `Its budget (US$${run.budgetUsd}) is spent.`
|
|
21837
|
+
};
|
|
21838
|
+
deps.onStep?.(s.pollSeconds);
|
|
21839
|
+
const ctx = {
|
|
21840
|
+
run,
|
|
21841
|
+
budgetUsd: left,
|
|
21842
|
+
pr,
|
|
21843
|
+
agentpipe: command(stepName),
|
|
21844
|
+
stranded: (p) => leases.stranded(p.url),
|
|
21845
|
+
runId,
|
|
21846
|
+
mayMerge: async () => deps.mayMerge ? deps.mayMerge() : "this runner can't ask whether it may merge"
|
|
21847
|
+
};
|
|
21848
|
+
finishing = Boolean(s.finishes);
|
|
21849
|
+
const out = await step(stepName, () => s.run(ctx));
|
|
21850
|
+
finishing = false;
|
|
21851
|
+
if (!out.ran) return {
|
|
21852
|
+
status: "cancelled",
|
|
21853
|
+
reason: "Cancelled."
|
|
21854
|
+
};
|
|
21855
|
+
last = {
|
|
21856
|
+
step: stepName,
|
|
21857
|
+
status: out.status,
|
|
21858
|
+
message: out.message
|
|
21859
|
+
};
|
|
21860
|
+
if (out.status === "ok" || out.status === "skipped") continue;
|
|
21861
|
+
return {
|
|
21862
|
+
status: out.status === "needs_human" || out.status === "cancelled" ? out.status : "failed",
|
|
21863
|
+
reason: out.message ? clip(out.message, 1e3) : null
|
|
21864
|
+
};
|
|
21865
|
+
}
|
|
21866
|
+
return {
|
|
21867
|
+
status: "succeeded",
|
|
21868
|
+
reason: recipe.finished?.({
|
|
21869
|
+
pr,
|
|
21870
|
+
last
|
|
21871
|
+
}) ?? null
|
|
21872
|
+
};
|
|
21873
|
+
})().catch((err) => ({
|
|
21874
|
+
status: "failed",
|
|
21875
|
+
reason: clip(`The run stopped: ${err.message}`, 1e3)
|
|
21876
|
+
})),
|
|
21877
|
+
cancel: async () => {
|
|
21878
|
+
cancelled = true;
|
|
21879
|
+
const now = current;
|
|
21880
|
+
if (!now || now.finishes) return;
|
|
21881
|
+
if (now.shipping()) now.process.terminate();
|
|
21882
|
+
else if (now.externalId) {
|
|
21883
|
+
const env = agentpipeEnv(deps.env, deps.monobanBin);
|
|
21884
|
+
await (deps.execCommand ?? exec)(deps.command, [
|
|
21885
|
+
"cancel",
|
|
21886
|
+
now.externalId,
|
|
21887
|
+
"--reason",
|
|
21888
|
+
"Cancelled from monoban"
|
|
21889
|
+
], env);
|
|
21890
|
+
} else now.process.interrupt();
|
|
21891
|
+
}
|
|
21892
|
+
};
|
|
21893
|
+
}
|
|
20489
21894
|
// src/runner/agents/index.ts
|
|
20490
21895
|
const DEFINITIONS = {
|
|
20491
21896
|
agentpipe: { create: (d) => agentpipe({
|
|
@@ -20547,6 +21952,34 @@ function adaptersFor(found, settings, board, env, monobanBin = null) {
|
|
|
20547
21952
|
monobanBin
|
|
20548
21953
|
})]));
|
|
20549
21954
|
}
|
|
21955
|
+
/**
|
|
21956
|
+
* The recipes this runner can run (docs/PLAN-AGENT-LOOPS.md §1.6): the ones this monoban runs whose agentpipe
|
|
21957
|
+
* commands the agentpipe here has (`agentpipe capabilities --json`). None with loops off, without agentpipe, or
|
|
21958
|
+
* with an agentpipe too old to say.
|
|
21959
|
+
*/
|
|
21960
|
+
async function detectLoops(settings, found, env, { capabilities = agentpipeCapabilities, here = RECIPES_HERE } = {}) {
|
|
21961
|
+
if (!settings.loops.enabled) return {
|
|
21962
|
+
recipes: [],
|
|
21963
|
+
why: "off here (--no-loops, or loops.enabled in runner.json)"
|
|
21964
|
+
};
|
|
21965
|
+
if (!found.some((a) => a.name === "agentpipe")) return {
|
|
21966
|
+
recipes: [],
|
|
21967
|
+
why: "they need agentpipe (`monoban agentpipe install`)"
|
|
21968
|
+
};
|
|
21969
|
+
const said = await capabilities(settings.commands.agentpipe, env);
|
|
21970
|
+
if (!said) return {
|
|
21971
|
+
recipes: [],
|
|
21972
|
+
why: "this agentpipe can't say what it runs (`monoban agentpipe update`)"
|
|
21973
|
+
};
|
|
21974
|
+
const recipes = recipesOf(said).filter((r) => here.includes(r));
|
|
21975
|
+
return recipes.length ? {
|
|
21976
|
+
recipes,
|
|
21977
|
+
why: null
|
|
21978
|
+
} : {
|
|
21979
|
+
recipes,
|
|
21980
|
+
why: "none this monoban and agentpipe both run yet"
|
|
21981
|
+
};
|
|
21982
|
+
}
|
|
20550
21983
|
// src/runner/board.ts
|
|
20551
21984
|
function runBoard(api) {
|
|
20552
21985
|
return {
|
|
@@ -20588,6 +22021,106 @@ function runBoard(api) {
|
|
|
20588
22021
|
}
|
|
20589
22022
|
};
|
|
20590
22023
|
}
|
|
22024
|
+
// src/runner/recipes/preflight.ts
|
|
22025
|
+
/**
|
|
22026
|
+
* Before a loop's run starts, while it is still queued (docs/PLAN-AGENT-LOOPS.md §1.6): the recipe's dry run
|
|
22027
|
+
* (`agentpipe … --dry-run --json`), which spends nothing and says every precondition that would refuse it. Its
|
|
22028
|
+
* exit code is the verdict, its `run.preview` line the words. "Cannot finish on that budget" isn't a refusal
|
|
22029
|
+
* (agentpipe exits 0: it says so for any budget under the sum of its steps' ceilings, spike MON-194). The folder
|
|
22030
|
+
* check comes first, in the runner, as for every run.
|
|
22031
|
+
*
|
|
22032
|
+
* A loop's run goes on with nobody watching, so the preview must also say agentpipe's sandbox is on: for each model
|
|
22033
|
+
* step (its `boundary`) and for the repository's own commands (`commands.sandbox`, `[commands] sandbox`), spike S9,
|
|
22034
|
+
* AGE-157. A preview that doesn't say refuses it too. And a tier the recipe names (`--tier`) must be one the folder's
|
|
22035
|
+
* agentpipe has (`capabilities <folder> --json`, AGE-127).
|
|
22036
|
+
*/
|
|
22037
|
+
async function preflight(run, recipe, deps) {
|
|
22038
|
+
const args = recipe.dryRun(run);
|
|
22039
|
+
if (args) {
|
|
22040
|
+
const refused = await dryRun(run, args, deps);
|
|
22041
|
+
if (refused) return refused;
|
|
22042
|
+
}
|
|
22043
|
+
const tier = recipe.tier?.(run) ?? null;
|
|
22044
|
+
if (tier) {
|
|
22045
|
+
const said = await (deps.capabilities ?? ((folder) => agentpipeCapabilities(deps.command, deps.env, folder)))(run.workdir);
|
|
22046
|
+
if (!said?.tiers) return `agentpipe couldn't say which tiers ${run.workdir} has, so the review tier ${tier} can't be checked.`;
|
|
22047
|
+
if (!said.tiers.includes(tier)) return clip(`agentpipe has no tier ${tier} in ${run.workdir} (it has ${said.tiers.join(", ") || "none"}).`, 1e3);
|
|
22048
|
+
}
|
|
22049
|
+
return null;
|
|
22050
|
+
}
|
|
22051
|
+
async function dryRun(run, args, deps) {
|
|
22052
|
+
let preview = null;
|
|
22053
|
+
const exit = await agentpipeCommand({
|
|
22054
|
+
command: deps.command,
|
|
22055
|
+
args,
|
|
22056
|
+
cwd: run.workdir,
|
|
22057
|
+
env: deps.env,
|
|
22058
|
+
monobanBin: deps.monobanBin,
|
|
22059
|
+
map: (event) => {
|
|
22060
|
+
if (event.kind === "run.preview") preview = event.data ?? {};
|
|
22061
|
+
},
|
|
22062
|
+
...deps.spawn && { spawn: deps.spawn }
|
|
22063
|
+
}).done;
|
|
22064
|
+
if (exit.spawnError) return exit.spawnError;
|
|
22065
|
+
const said = preview;
|
|
22066
|
+
if (exit.code !== 0) {
|
|
22067
|
+
const refusals = (said?.refusals ?? []).map((r) => typeof r.message === "string" ? r.message : "").filter(Boolean);
|
|
22068
|
+
if (refusals.length) return clip(`agentpipe won't start it: ${refusals.join("; ")}`, 1e3);
|
|
22069
|
+
const last = exit.lastError ? `: ${exit.lastError}` : ".";
|
|
22070
|
+
return clip(`agentpipe's dry run refused it (exit code ${exit.code ?? "none"})${last}`, 1e3);
|
|
22071
|
+
}
|
|
22072
|
+
if (!said) return "agentpipe's dry run didn't say what the run would do, so its sandbox can't be checked.";
|
|
22073
|
+
const off = (said.steps ?? []).filter((s) => s.boundary && s.boundary.sandbox !== true).map((s) => typeof s.name === "string" ? s.name : "a step");
|
|
22074
|
+
if (off.length) return clip(`agentpipe's sandbox is off for ${off.join(", ")}: a loop runs only with it on (each step's sandbox in .agentpipe/config.toml).`, 1e3);
|
|
22075
|
+
if (said.commands?.sandbox !== true) return "agentpipe's sandbox is off for the repository's own commands: a loop runs only with it on ([commands] sandbox = true in .agentpipe/config.toml).";
|
|
22076
|
+
return null;
|
|
22077
|
+
}
|
|
22078
|
+
// src/runner/spend.ts
|
|
22079
|
+
const DAY = 864e5;
|
|
22080
|
+
function spendFile(path, now = Date.now) {
|
|
22081
|
+
const read = async () => {
|
|
22082
|
+
try {
|
|
22083
|
+
const parsed = JSON.parse(await readFile(path, "utf8"));
|
|
22084
|
+
if (!Array.isArray(parsed)) return [];
|
|
22085
|
+
return parsed.filter((e) => typeof e?.at === "number" && typeof e?.usd === "number" && e.usd >= 0 && e.at > now() - DAY);
|
|
22086
|
+
} catch {
|
|
22087
|
+
return [];
|
|
22088
|
+
}
|
|
22089
|
+
};
|
|
22090
|
+
return {
|
|
22091
|
+
total: async () => (await read()).reduce((sum, e) => sum + e.usd, 0),
|
|
22092
|
+
add: async (usd) => {
|
|
22093
|
+
if (!(usd > 0)) return;
|
|
22094
|
+
const entries = [...await read(), {
|
|
22095
|
+
at: now(),
|
|
22096
|
+
usd
|
|
22097
|
+
}];
|
|
22098
|
+
await mkdir(dirname(path), {
|
|
22099
|
+
recursive: true,
|
|
22100
|
+
mode: 448
|
|
22101
|
+
});
|
|
22102
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
22103
|
+
await writeFile(temporary, `${JSON.stringify(entries)}\n`, { mode: 384 });
|
|
22104
|
+
await rename(temporary, path);
|
|
22105
|
+
}
|
|
22106
|
+
};
|
|
22107
|
+
}
|
|
22108
|
+
/** The same, kept only while this runner runs (tests, and a runner with nowhere to write). */
|
|
22109
|
+
function spendInMemory(now = Date.now) {
|
|
22110
|
+
let entries = [];
|
|
22111
|
+
return {
|
|
22112
|
+
total: async () => {
|
|
22113
|
+
entries = entries.filter((e) => e.at > now() - DAY);
|
|
22114
|
+
return entries.reduce((sum, e) => sum + e.usd, 0);
|
|
22115
|
+
},
|
|
22116
|
+
add: async (usd) => {
|
|
22117
|
+
if (usd > 0) entries.push({
|
|
22118
|
+
at: now(),
|
|
22119
|
+
usd
|
|
22120
|
+
});
|
|
22121
|
+
}
|
|
22122
|
+
};
|
|
22123
|
+
}
|
|
20591
22124
|
const sleepFor = (ms, signal) => new Promise((resolve) => {
|
|
20592
22125
|
if (signal.aborted) return resolve();
|
|
20593
22126
|
const timer = setTimeout(resolve, ms);
|
|
@@ -20610,12 +22143,32 @@ async function runRunner(ctx, settings, deps, options = {}) {
|
|
|
20610
22143
|
const status = deps.onStatus ?? (() => {});
|
|
20611
22144
|
let installed = deps.adapters;
|
|
20612
22145
|
let adapters = Object.keys(installed);
|
|
20613
|
-
|
|
20614
|
-
|
|
20615
|
-
|
|
20616
|
-
|
|
20617
|
-
|
|
20618
|
-
|
|
22146
|
+
let recipes = settings.loops.enabled ? [...deps.recipes ?? []] : [];
|
|
22147
|
+
const spend = deps.spend ?? spendInMemory();
|
|
22148
|
+
/** When each folder's ledger was last synced (syncLedgers). */
|
|
22149
|
+
const synced = /* @__PURE__ */ new Map();
|
|
22150
|
+
/** What this machine's day has left for loops' runs, in US dollars. */
|
|
22151
|
+
const dayLeft = async () => settings.loops.maxUsdPerDay - await spend.total();
|
|
22152
|
+
const register = async () => {
|
|
22153
|
+
const body = {
|
|
22154
|
+
name: settings.name,
|
|
22155
|
+
adapters,
|
|
22156
|
+
version: VERSION,
|
|
22157
|
+
pollSeconds: settings.pollSeconds
|
|
22158
|
+
};
|
|
22159
|
+
if (recipes.length) try {
|
|
22160
|
+
return await unwrap(api.POST("/v1/runners", { body: {
|
|
22161
|
+
...body,
|
|
22162
|
+
recipes
|
|
22163
|
+
} }));
|
|
22164
|
+
} catch (err) {
|
|
22165
|
+
if (!(err instanceof ApiProblem && err.status === 400)) throw err;
|
|
22166
|
+
recipes = [];
|
|
22167
|
+
status({ recipes });
|
|
22168
|
+
ctx.err("The API doesn't take agent loops yet: this runner runs only the runs you start.");
|
|
22169
|
+
}
|
|
22170
|
+
return unwrap(api.POST("/v1/runners", { body }));
|
|
22171
|
+
};
|
|
20619
22172
|
const redetectMs = deps.redetectMs ?? 6e4;
|
|
20620
22173
|
let detectedAt = Date.now();
|
|
20621
22174
|
/** Offers the agents installed now, when they changed (registering again tells the board). */
|
|
@@ -20640,10 +22193,13 @@ async function runRunner(ctx, settings, deps, options = {}) {
|
|
|
20640
22193
|
let runner = await register();
|
|
20641
22194
|
status({
|
|
20642
22195
|
runnerId: runner.id,
|
|
20643
|
-
agents: adapters
|
|
22196
|
+
agents: adapters,
|
|
22197
|
+
recipes
|
|
20644
22198
|
});
|
|
20645
22199
|
const stopWith = options.background ? "`monoban runner stop` stops it" : "Ctrl-C to stop";
|
|
20646
22200
|
ctx.err(`Runner ${runner.name} is online with ${adapters.join(", ")}: waiting for runs (checking every ${settings.pollSeconds}s, every ${Math.min(settings.pollSeconds, 5)}s while one runs; ${stopWith}).`);
|
|
22201
|
+
if (recipes.length) ctx.err(`Agent loops: ${recipes.join(", ")}.`);
|
|
22202
|
+
else if (deps.loopsWhy) ctx.err(`Agent loops: ${deps.loopsWhy}.`);
|
|
20647
22203
|
let active = null;
|
|
20648
22204
|
let stopping = false;
|
|
20649
22205
|
let interrupted = false;
|
|
@@ -20676,7 +22232,11 @@ async function runRunner(ctx, settings, deps, options = {}) {
|
|
|
20676
22232
|
while (!leave && (!stopping || active)) {
|
|
20677
22233
|
let work = null;
|
|
20678
22234
|
try {
|
|
20679
|
-
|
|
22235
|
+
const free = !active && !stopping && !(options.once && took) && (!recipes.length || await dayLeft() >= 1);
|
|
22236
|
+
work = await heartbeat(api, runner.id, recipes.length ? {
|
|
22237
|
+
recipes,
|
|
22238
|
+
free
|
|
22239
|
+
} : void 0);
|
|
20680
22240
|
if (unreachable) ctx.err("Reached the API again.");
|
|
20681
22241
|
unreachable = false;
|
|
20682
22242
|
status({
|
|
@@ -20684,7 +22244,7 @@ async function runRunner(ctx, settings, deps, options = {}) {
|
|
|
20684
22244
|
unreachable: null
|
|
20685
22245
|
});
|
|
20686
22246
|
} catch (err) {
|
|
20687
|
-
if (err instanceof NotSignedIn || err instanceof ApiProblem && err.status === 401) throw err;
|
|
22247
|
+
if (err instanceof NotSignedIn || err instanceof ApiProblem && (err.status === 401 || err.status === 426)) throw err;
|
|
20688
22248
|
if (err instanceof ApiProblem && err.status === 404) {
|
|
20689
22249
|
runner = await register();
|
|
20690
22250
|
status({ runnerId: runner.id });
|
|
@@ -20703,10 +22263,13 @@ async function runRunner(ctx, settings, deps, options = {}) {
|
|
|
20703
22263
|
ctx.err(`Cancelling ${active.ref}: asked from the board.`);
|
|
20704
22264
|
active.cancel();
|
|
20705
22265
|
}
|
|
20706
|
-
} else if (first)
|
|
20707
|
-
status: "failed"
|
|
20708
|
-
|
|
20709
|
-
|
|
22266
|
+
} else if (first) {
|
|
22267
|
+
const status = run.recipe ? "cancelled" : "failed";
|
|
22268
|
+
await patch(api, run.id, {
|
|
22269
|
+
status,
|
|
22270
|
+
reason: "The runner stopped while it ran."
|
|
22271
|
+
}).catch(() => {});
|
|
22272
|
+
}
|
|
20710
22273
|
first = false;
|
|
20711
22274
|
const next = work.queued[0];
|
|
20712
22275
|
if (!active && !stopping && next && !(options.once && took)) {
|
|
@@ -20723,11 +22286,12 @@ async function runRunner(ctx, settings, deps, options = {}) {
|
|
|
20723
22286
|
}
|
|
20724
22287
|
}
|
|
20725
22288
|
}
|
|
22289
|
+
if (!active && !stopping && work?.waiting?.length && deps.agentpipe) await syncLedgers(work.waiting);
|
|
20726
22290
|
await active?.flush();
|
|
20727
22291
|
if (options.once && !active && (took || !work?.queued.length)) break;
|
|
20728
22292
|
if (!active && !stopping) await redetect().catch(() => {});
|
|
20729
22293
|
if (!leave && (!stopping || active)) {
|
|
20730
|
-
const seconds = active ? Math.min(settings.pollSeconds,
|
|
22294
|
+
const seconds = active ? Math.min(settings.pollSeconds, active.pollSeconds) : settings.pollSeconds;
|
|
20731
22295
|
await deps.sleep(seconds * 1e3, wake.signal);
|
|
20732
22296
|
wake = new AbortController();
|
|
20733
22297
|
}
|
|
@@ -20750,7 +22314,8 @@ async function runRunner(ctx, settings, deps, options = {}) {
|
|
|
20750
22314
|
cancelled = true;
|
|
20751
22315
|
await cancel();
|
|
20752
22316
|
},
|
|
20753
|
-
flush: () => outbox.flush()
|
|
22317
|
+
flush: () => outbox.flush(),
|
|
22318
|
+
pollSeconds: 5
|
|
20754
22319
|
};
|
|
20755
22320
|
return {
|
|
20756
22321
|
active: self,
|
|
@@ -20762,12 +22327,32 @@ async function runRunner(ctx, settings, deps, options = {}) {
|
|
|
20762
22327
|
reason
|
|
20763
22328
|
}, run.version).catch(() => {});
|
|
20764
22329
|
};
|
|
20765
|
-
|
|
22330
|
+
const recipe = run.recipe ? RECIPES[run.recipe] ?? null : null;
|
|
22331
|
+
let loopRun = null;
|
|
22332
|
+
if (run.recipe) {
|
|
22333
|
+
if (!recipe || !run.loopRun || !deps.agentpipe) return refuse("failed", `${runner.name} can't run ${run.recipe} loops.`);
|
|
22334
|
+
if (run.recipe === "deliver" && !ref) return refuse("cancelled", "Its task was deleted.");
|
|
22335
|
+
const left = await dayLeft();
|
|
22336
|
+
if (left < 1) return refuse("cancelled", `${runner.name} has spent its day for loops (US$${settings.loops.maxUsdPerDay}, loops.maxUsdPerDay).`);
|
|
22337
|
+
const budget = run.options.budgetUsd ?? run.loopRun.options.budgetUsd;
|
|
22338
|
+
loopRun = {
|
|
22339
|
+
id: run.id,
|
|
22340
|
+
ref,
|
|
22341
|
+
workdir: run.workdir,
|
|
22342
|
+
plan: run.loopRun,
|
|
22343
|
+
budgetUsd: Math.min(budget, left)
|
|
22344
|
+
};
|
|
22345
|
+
} else if (!ref) return refuse("failed", "Its task was deleted.");
|
|
20766
22346
|
const adapter = installed[run.adapter];
|
|
20767
22347
|
if (!adapter) return refuse("failed", `${runner.name} can't run ${run.adapter}.`);
|
|
20768
22348
|
const problem = await deps.workdirProblem(run.workdir, run.project);
|
|
20769
22349
|
if (problem) return refuse("failed", problem);
|
|
20770
|
-
if (
|
|
22350
|
+
if (loopRun && recipe && deps.agentpipe) {
|
|
22351
|
+
const refused = await preflight(loopRun, recipe, deps.agentpipe);
|
|
22352
|
+
if (refused) return refuse("failed", refused);
|
|
22353
|
+
}
|
|
22354
|
+
const what = ref ?? `a ${run.recipe} run`;
|
|
22355
|
+
if (settings.confirm && !await ctx.confirm(`Run ${what} with ${run.adapter} in ${run.workdir}?`)) return refuse("cancelled", `Declined on ${runner.name}.`);
|
|
20771
22356
|
if (cancelled) return refuse("cancelled", "Cancelled before it started.");
|
|
20772
22357
|
try {
|
|
20773
22358
|
await patch(api, run.id, { status: "running" }, run.version);
|
|
@@ -20775,43 +22360,106 @@ async function runRunner(ctx, settings, deps, options = {}) {
|
|
|
20775
22360
|
if (err instanceof ApiProblem && (err.status === 412 || err.status === 409)) return;
|
|
20776
22361
|
throw err;
|
|
20777
22362
|
}
|
|
20778
|
-
ctx.err(`▶ ${
|
|
22363
|
+
ctx.err(`▶ ${what} in ${run.workdir} (${run.recipe ? `${run.recipe} loop` : run.adapter})`);
|
|
20779
22364
|
status({ run: {
|
|
20780
22365
|
id: run.id,
|
|
20781
|
-
ref,
|
|
22366
|
+
ref: what,
|
|
20782
22367
|
workdir: run.workdir,
|
|
20783
22368
|
adapter: run.adapter,
|
|
20784
22369
|
startedAt: now()
|
|
20785
22370
|
} });
|
|
20786
|
-
const
|
|
20787
|
-
ref,
|
|
20788
|
-
workdir: run.workdir,
|
|
20789
|
-
options: run.options
|
|
20790
|
-
}, {
|
|
22371
|
+
const report = {
|
|
20791
22372
|
event: (e) => {
|
|
20792
22373
|
outbox.push(e);
|
|
20793
22374
|
const line = describe$1(e);
|
|
20794
22375
|
if (line) ctx.err(` ${line}`);
|
|
20795
22376
|
},
|
|
20796
22377
|
update: (u) => outbox.update(u)
|
|
20797
|
-
}
|
|
22378
|
+
};
|
|
22379
|
+
const started = loopRun && deps.agentpipe ? runRecipe(run.recipe, loopRun, report, {
|
|
22380
|
+
...deps.agentpipe,
|
|
22381
|
+
recheck: () => recheck(run.id),
|
|
22382
|
+
mayMerge: () => mayMerge(run.id),
|
|
22383
|
+
onStep: (seconds) => {
|
|
22384
|
+
self.pollSeconds = seconds ?? settings.pollSeconds;
|
|
22385
|
+
}
|
|
22386
|
+
}) : adapter.start({
|
|
22387
|
+
ref,
|
|
22388
|
+
workdir: run.workdir,
|
|
22389
|
+
options: run.options
|
|
22390
|
+
}, report);
|
|
20798
22391
|
cancel = started.cancel;
|
|
20799
22392
|
if (cancelled) started.cancel();
|
|
20800
22393
|
const ending = await started.done;
|
|
20801
22394
|
await outbox.flush();
|
|
22395
|
+
if (loopRun) await spend.add(outbox.updates().costUsd ?? 0).catch(() => {});
|
|
20802
22396
|
await patch(api, run.id, {
|
|
20803
22397
|
...outbox.updates(),
|
|
20804
22398
|
status: ending.status,
|
|
20805
22399
|
reason: ending.reason
|
|
20806
22400
|
}).catch((err) => ctx.err(`Couldn't record how ${ref} ended: ${err.message}`));
|
|
20807
22401
|
const pr = outbox.updates().prUrl;
|
|
20808
|
-
ctx.err(`${ENDINGS[ending.status]}: ${
|
|
22402
|
+
ctx.err(`${ENDINGS[ending.status]}: ${what}${ending.reason ? ` (${ending.reason})` : ""}${pr ? ` ${pr}` : ""}`);
|
|
20809
22403
|
})().catch((err) => ctx.err(`✗ ${self.ref}: ${err.message}`))
|
|
20810
22404
|
};
|
|
20811
22405
|
}
|
|
22406
|
+
/**
|
|
22407
|
+
* `agentpipe ledger sync` in the folders of its deliver loops with pull requests waiting for you (plan §1.4): it asks
|
|
22408
|
+
* GitHub what became of them, read-only, and a pull request merged by hand moves its task to Done. Once a folder
|
|
22409
|
+
* per check-in at most (an early wake doesn't repeat it), and only in a folder a run may work in (workdirProblem).
|
|
22410
|
+
*/
|
|
22411
|
+
async function syncLedgers(waiting) {
|
|
22412
|
+
const agentpipe = deps.agentpipe;
|
|
22413
|
+
if (!agentpipe) return;
|
|
22414
|
+
const at = Date.parse(now());
|
|
22415
|
+
for (const loop of waiting) {
|
|
22416
|
+
if (at - (synced.get(loop.workdir) ?? Number.NEGATIVE_INFINITY) < settings.pollSeconds * 1e3) continue;
|
|
22417
|
+
synced.set(loop.workdir, at);
|
|
22418
|
+
if (await deps.workdirProblem(loop.workdir, loop.project)) continue;
|
|
22419
|
+
await ledgerSync(agentpipe, loop.workdir).catch(() => {});
|
|
22420
|
+
}
|
|
22421
|
+
}
|
|
22422
|
+
/**
|
|
22423
|
+
* Right before a loop's run merges (plan §1.12): null when it may, else why not. This machine's `loops.merge:
|
|
22424
|
+
* false` says no; otherwise the server, reading the run now (`mayMerge`). Anything but its yes is a no.
|
|
22425
|
+
*/
|
|
22426
|
+
async function mayMerge(runId) {
|
|
22427
|
+
if (!settings.loops.merge) return "this machine doesn't merge loops' runs (loops.merge is false in runner.json)";
|
|
22428
|
+
try {
|
|
22429
|
+
const run = await unwrap(api.GET("/v1/runs/{runId}", { params: { path: { runId } } }));
|
|
22430
|
+
if (run.mayMerge === true) return null;
|
|
22431
|
+
return run.mergeHold ? describeMergeHold(run.mergeHold, ENGLISH) : "the server didn't say it may merge";
|
|
22432
|
+
} catch (err) {
|
|
22433
|
+
return `couldn't ask the server whether it may merge (${err.message})`;
|
|
22434
|
+
}
|
|
22435
|
+
}
|
|
22436
|
+
/**
|
|
22437
|
+
* Before each step of a loop's run: why it should stop now, or null. Asked from the board (cancelled, or no
|
|
22438
|
+
* longer running), or its task deleted, archived or done (read by the run's ref now: a task can move).
|
|
22439
|
+
*/
|
|
22440
|
+
async function recheck(runId) {
|
|
22441
|
+
const run = await unwrap(api.GET("/v1/runs/{runId}", { params: { path: { runId } } }));
|
|
22442
|
+
if (run.status !== "running" || run.cancelRequested) return "Cancelled from the board.";
|
|
22443
|
+
if (!run.ref || run.recipe !== "deliver") return null;
|
|
22444
|
+
const key = run.ref.slice(0, run.ref.lastIndexOf("-"));
|
|
22445
|
+
try {
|
|
22446
|
+
const task = await unwrap(api.GET("/v1/tasks/{ref}", { params: { path: { ref: run.ref } } }));
|
|
22447
|
+
if (task.archivedAt) return `${task.ref} was archived.`;
|
|
22448
|
+
const { columns } = await unwrap(api.GET("/v1/projects/{key}", { params: { path: { key } } }));
|
|
22449
|
+
if (doneColumn(columns)?.id === task.columnId) return `${task.ref} is done.`;
|
|
22450
|
+
} catch (err) {
|
|
22451
|
+
if (err instanceof ApiProblem && err.status === 404) return `${run.ref} was deleted.`;
|
|
22452
|
+
throw err;
|
|
22453
|
+
}
|
|
22454
|
+
return null;
|
|
22455
|
+
}
|
|
20812
22456
|
}
|
|
20813
|
-
|
|
20814
|
-
|
|
22457
|
+
/** Checks in; a runner that runs loops says which recipes, and whether it's free to start one. */
|
|
22458
|
+
function heartbeat(api, runnerId, body) {
|
|
22459
|
+
return unwrap(api.POST("/v1/runners/{runnerId}/heartbeat", {
|
|
22460
|
+
params: { path: { runnerId } },
|
|
22461
|
+
...body && { body }
|
|
22462
|
+
}));
|
|
20815
22463
|
}
|
|
20816
22464
|
function patch(api, runId, body, version) {
|
|
20817
22465
|
return unwrap(api.PATCH("/v1/runs/{runId}", {
|
|
@@ -21002,7 +22650,7 @@ const LOG_LIMIT = 1048576;
|
|
|
21002
22650
|
/** Moves a long log aside, keeping one older one. */
|
|
21003
22651
|
async function rotateLog(path, limit = LOG_LIMIT) {
|
|
21004
22652
|
if (await stat(path).then((s) => s.size, () => 0) <= limit) return;
|
|
21005
|
-
await rm(`${path}.1`, { force: true });
|
|
22653
|
+
await rm$1(`${path}.1`, { force: true });
|
|
21006
22654
|
await rename(path, `${path}.1`);
|
|
21007
22655
|
}
|
|
21008
22656
|
/** The last `count` lines of a file ([] when there's none). */
|
|
@@ -21068,7 +22716,8 @@ function flagsOf(options) {
|
|
|
21068
22716
|
...options.interval !== void 0 && { interval: options.interval },
|
|
21069
22717
|
...options.allow?.length && { allow: options.allow },
|
|
21070
22718
|
...options.agents !== void 0 && { agents: options.agents },
|
|
21071
|
-
...options.allowFullAccess && { allowFullAccess: true }
|
|
22719
|
+
...options.allowFullAccess && { allowFullAccess: true },
|
|
22720
|
+
...options.loops === false && { loops: false }
|
|
21072
22721
|
};
|
|
21073
22722
|
}
|
|
21074
22723
|
/** Those flags as arguments. */
|
|
@@ -21078,7 +22727,8 @@ function argsOf(flags) {
|
|
|
21078
22727
|
...flags.interval !== void 0 ? ["--interval", flags.interval] : [],
|
|
21079
22728
|
...(flags.allow ?? []).flatMap((folder) => ["--allow", folder]),
|
|
21080
22729
|
...flags.agents !== void 0 ? ["--agents", flags.agents] : [],
|
|
21081
|
-
...flags.allowFullAccess ? ["--allow-full-access"] : []
|
|
22730
|
+
...flags.allowFullAccess ? ["--allow-full-access"] : [],
|
|
22731
|
+
...flags.loops === false ? ["--no-loops"] : []
|
|
21082
22732
|
];
|
|
21083
22733
|
}
|
|
21084
22734
|
/** Why it stopped, from what stopped it. */
|
|
@@ -21103,7 +22753,7 @@ function onSignals(signals, heard) {
|
|
|
21103
22753
|
};
|
|
21104
22754
|
}
|
|
21105
22755
|
/**
|
|
21106
|
-
* `monoban runner`: in the background unless told otherwise; in the foreground, the loop (runner/
|
|
22756
|
+
* `monoban runner`: in the background unless told otherwise; in the foreground, the poll loop (runner/poll.ts) until
|
|
21107
22757
|
* Ctrl-C, keeping its file current. It offers the agents installed here (or the ones --agents names), and says why
|
|
21108
22758
|
* it doesn't offer the others.
|
|
21109
22759
|
*/
|
|
@@ -21156,7 +22806,7 @@ async function runner(ctx, options, overrides = {}) {
|
|
|
21156
22806
|
};
|
|
21157
22807
|
let reason = null;
|
|
21158
22808
|
try {
|
|
21159
|
-
const { detect = detectAgents, ...deps } = overrides;
|
|
22809
|
+
const { detect = detectAgents, detectLoops: _, ...deps } = overrides;
|
|
21160
22810
|
let adapters = deps.adapters;
|
|
21161
22811
|
let redetect = deps.redetect;
|
|
21162
22812
|
if (!adapters) {
|
|
@@ -21168,6 +22818,18 @@ async function runner(ctx, options, overrides = {}) {
|
|
|
21168
22818
|
ctx.err(`Agents: ${agentList(found)}.${missing.length ? ` Not offered: ${missing.join("; ")}.` : ""}`);
|
|
21169
22819
|
if (settings.allowFullAccess && found.some((a) => a.name === "codex")) ctx.err("Codex may run without its sandbox here, when a run asks for full access.");
|
|
21170
22820
|
adapters = adaptersFor(found, settings, board, env, monobanBin);
|
|
22821
|
+
if (!deps.recipes) {
|
|
22822
|
+
const loops = await (overrides.detectLoops ?? detectLoops)(settings, found, env);
|
|
22823
|
+
deps.recipes = loops.recipes;
|
|
22824
|
+
deps.loopsWhy = loops.why;
|
|
22825
|
+
deps.agentpipe ??= {
|
|
22826
|
+
command: settings.commands.agentpipe,
|
|
22827
|
+
env,
|
|
22828
|
+
monobanBin
|
|
22829
|
+
};
|
|
22830
|
+
deps.spend ??= spendFile(join(runnersDir(ctx.env), "loops-spend.json"));
|
|
22831
|
+
file.save({ loopsWhy: loops.why });
|
|
22832
|
+
}
|
|
21171
22833
|
redetect ??= async () => adaptersFor((await detect(settings, env)).found, settings, board, env, monobanBin);
|
|
21172
22834
|
}
|
|
21173
22835
|
await runRunner(ctx, settings, {
|
|
@@ -21324,6 +22986,7 @@ function describe({ state, running }, board, now) {
|
|
|
21324
22986
|
if (running) {
|
|
21325
22987
|
lines.push(`● ${state.name} running ${where$1(state)} · pid ${state.pid} · up ${since(state.startedAt, now)} · monoban ${state.version}`);
|
|
21326
22988
|
if (state.agents.length) row("agents", state.agents.map(agentLabel).join(", "));
|
|
22989
|
+
if (state.recipes !== void 0) row("loops", state.recipes.length ? `on: ${state.recipes.join(", ")}` : `none: ${state.loopsWhy ?? "off"}`);
|
|
21327
22990
|
if (state.run) row("run", `${state.run.ref} in ${state.run.workdir} (${agentLabel(state.run.adapter)}), for ${since(state.run.startedAt, now)}`);
|
|
21328
22991
|
if (state.draining) row("stopping", state.run ? `once ${state.run.ref} ends` : "now");
|
|
21329
22992
|
if (state.unreachable) row("board", `can't reach the API (${state.unreachable})`);
|
|
@@ -21331,7 +22994,7 @@ function describe({ state, running }, board, now) {
|
|
|
21331
22994
|
const seenAgo = `checked in ${since(board.lastSeenAt, now)} ago (every ${board.pollSeconds}s)`;
|
|
21332
22995
|
row("board", `${board.online ? "online" : "offline"} · ${seenAgo}`);
|
|
21333
22996
|
} else if (!state.runnerId) row("board", "not on the board yet: it's starting");
|
|
21334
|
-
if (state.version !== "1.
|
|
22997
|
+
if (state.version !== "1.9.0") {
|
|
21335
22998
|
const again = state.background ? "`monoban runner restart`" : "start it again in its terminal";
|
|
21336
22999
|
row("update", `it runs monoban ${state.version}, this is ${VERSION}: ${again}`);
|
|
21337
23000
|
}
|
|
@@ -21769,7 +23432,7 @@ async function checks(ctx, deps = {}) {
|
|
|
21769
23432
|
const found = [];
|
|
21770
23433
|
const latest = await (deps.latest ?? latestVersion)(ctx);
|
|
21771
23434
|
const upgrade = UPGRADE[thisInstall()].command;
|
|
21772
|
-
found.push(latest && newer(latest, "1.
|
|
23435
|
+
found.push(latest && newer(latest, "1.9.0") ? {
|
|
21773
23436
|
name: "monoban",
|
|
21774
23437
|
status: "warn",
|
|
21775
23438
|
detail: `${VERSION}; ${latest} is out`,
|
|
@@ -22384,7 +24047,7 @@ async function setup(ctx, agent, options) {
|
|
|
22384
24047
|
if (options.json) return report("none", "");
|
|
22385
24048
|
return ctx.err(`The monoban skill isn't installed for ${name} at ${shown}.`);
|
|
22386
24049
|
}
|
|
22387
|
-
await rm(path);
|
|
24050
|
+
await rm$1(path);
|
|
22388
24051
|
await rmdir(dirname(path)).catch(() => {});
|
|
22389
24052
|
return report("removed", `Removed the monoban skill for ${name}: ${shown}.`);
|
|
22390
24053
|
}
|
|
@@ -22605,7 +24268,7 @@ function program(ctx) {
|
|
|
22605
24268
|
cli.command("done").argument("<task>", "like MON-12").description("Move a task to Done (or the last column)").addOption(json()).action(async (ref, options) => done(await ctx(), ref, options));
|
|
22606
24269
|
cli.command("start").argument("<task>", "like MON-12").description("Start a task: check out its branch (mon-12-title, made from the commit you're on) and move it to In progress").option("--no-branch", "only move it").option("--no-move", "only check out its branch").addOption(json()).action(async (ref, options) => start(await ctx(), ref, options));
|
|
22607
24270
|
cli.command("edit").argument("<task>", "like MON-12").description("Edit a task's title (the first line) and description in $EDITOR, or set them with --title and -d").option("--title <text>", "a new title (no editor)").option("-d, --description <text>", "a new description, replacing it (- reads it from stdin; no editor)").addOption(json()).action(async (ref, options) => edit(await ctx(), ref, options));
|
|
22608
|
-
cli.command("rm").argument("<task>", "like MON-12").description("Delete a task (asks first)").option("-y, --yes", "don't ask").addOption(json()).action(async (ref, options) => rm
|
|
24271
|
+
cli.command("rm").argument("<task>", "like MON-12").description("Delete a task (asks first)").option("-y, --yes", "don't ask").addOption(json()).action(async (ref, options) => rm(await ctx(), ref, options));
|
|
22609
24272
|
cli.command("tag").argument("<task>", "like MON-12").argument("<tags...>", "tag names (a new name makes a tag in the task's project)").description("Put tags on a task").addOption(json()).action(async (ref, names, options) => tag(await ctx(), ref, names, options));
|
|
22610
24273
|
cli.command("untag").argument("<task>", "like MON-12").argument("<tags...>", "tag names").description("Take tags off a task").addOption(json()).action(async (ref, names, options) => untag(await ctx(), ref, names, options));
|
|
22611
24274
|
cli.command("attach").argument("[task]", "like MON-12 (else the one this branch is named after: mon-12-…)").argument("[link]", "a pull request, an issue, a commit, or any page").description("Attach a link to a task (again: refresh it); --pr attaches this branch's pull request").option("--pr", "this branch's pull request, with its title and state (needs gh)").option("--title <text>", "its title (a pull request's or an issue's comes from gh)").addOption(json()).action(async (task, link, options) => attach(await ctx(), [task, link].filter((a) => a !== void 0), options));
|
|
@@ -22615,8 +24278,8 @@ function program(ctx) {
|
|
|
22615
24278
|
notes.command("show", { isDefault: true }).description("Print the notes (the default)").addOption(project()).addOption(json()).action(async (options) => notesShow(await ctx(), options));
|
|
22616
24279
|
notes.command("add").argument("<text...>", "the line to add (- reads it from stdin)").description("Add a line at the end of the notes").addOption(project()).addOption(json()).action(async (words, options) => notesAdd(await ctx(), words, options));
|
|
22617
24280
|
notes.command("edit").description("Edit the notes in $EDITOR").addOption(project()).addOption(json()).action(async (options) => notesEdit(await ctx(), options));
|
|
22618
|
-
cli.command("open").argument("[task]", "like MON-12").description("Open the board, or a task, in the browser").addOption(project()).action(async (ref, options) => open
|
|
22619
|
-
const runnerCommand = cli.command("runner").description("Run coding agents on this machine for the runs you start from the board, in the background: status, stop, restart, logs").enablePositionalOptions().option("--name <name>", "what the board calls this machine (default: its hostname)").option("--interval <seconds>", "how often to ask for work while idle (default 60; every 5 while a run is going)").option("--allow <folder>", "only run in this folder or below (repeat for more)", collect).option("--confirm", "ask here before starting each run (so it runs in this terminal)").option("--agents <names>", "offer only these agents: agentpipe, claude, codex (comma-separated)").option("--allow-full-access", "let a run turn Codex's sandbox off (access: full); otherwise it stays on").option("--foreground", "run in this terminal, until Ctrl-C, instead of in the background").option("--once", "take one run (if one is waiting), then stop (in this terminal)").addHelpText("after", `
|
|
24281
|
+
cli.command("open").argument("[task]", "like MON-12").description("Open the board, or a task, in the browser").addOption(project()).action(async (ref, options) => open(await ctx(), ref, options));
|
|
24282
|
+
const runnerCommand = cli.command("runner").description("Run coding agents on this machine for the runs you start from the board, in the background: status, stop, restart, logs").enablePositionalOptions().option("--name <name>", "what the board calls this machine (default: its hostname)").option("--interval <seconds>", "how often to ask for work while idle (default 60; every 5 while a run is going)").option("--allow <folder>", "only run in this folder or below (repeat for more)", collect).option("--confirm", "ask here before starting each run (so it runs in this terminal)").option("--agents <names>", "offer only these agents: agentpipe, claude, codex (comma-separated)").option("--allow-full-access", "let a run turn Codex's sandbox off (access: full); otherwise it stays on").option("--no-loops", "run no agent loops here, only the runs you start (loops are on by default)").option("--foreground", "run in this terminal, until Ctrl-C, instead of in the background").option("--once", "take one run (if one is waiting), then stop (in this terminal)").addHelpText("after", `
|
|
22620
24283
|
It starts in the background and keeps running when this terminal closes (not when you sign out or the machine
|
|
22621
24284
|
restarts): \`monoban runner status\` shows it, \`monoban runner logs\` what it says, \`monoban runner stop\` stops it.
|
|
22622
24285
|
A run works in the folder it was given, which must be a checkout of the task's project: its origin is the
|
|
@@ -22626,7 +24289,9 @@ in its sandbox). For Claude Code and Codex the runner makes the task's branch, c
|
|
|
22626
24289
|
pushes, opens the pull request with gh and comments on the task. Codex keeps its sandbox unless this
|
|
22627
24290
|
machine allows a run to turn it off. Settings can also go in runner.json in the config folder:
|
|
22628
24291
|
{"pollSeconds": 60, "allow": ["/Users/me/code"], "confirm": false, "agents": ["claude"],
|
|
22629
|
-
"adapters": {"claude": {"command": "claude", "args": []}, "codex": {"allowFullAccess": false}}
|
|
24292
|
+
"adapters": {"claude": {"command": "claude", "args": []}, "codex": {"allowFullAccess": false}},
|
|
24293
|
+
"loops": {"enabled": true, "merge": true, "maxUsdPerDay": 100}}. Agent loops (made in the browser) run here
|
|
24294
|
+
too when agentpipe can run them: --no-loops, or "enabled": false, says no; "merge": false never merges here.`).action(async (options) => runner(await ctx(), options));
|
|
22630
24295
|
runnerCommand.command("status").description("This machine's runners: running or not, the run going on, what the board sees, why one stopped").option("--name <name>", "only this runner").addOption(json()).action(async (options) => runnerStatus(await ctx(), options));
|
|
22631
24296
|
runnerCommand.command("stop").description("Stop this machine's runners (a run going on is cancelled; asks first)").option("--name <name>", "only this runner").option("--wait", "let the run going on finish first, then stop").option("-y, --yes", "don't ask before cancelling a run").action(async (options) => runnerStop(await ctx(), options));
|
|
22632
24297
|
runnerCommand.command("restart").description("Stop the runner and start it again in the background, with the same flags (after an upgrade)").option("--name <name>", "which runner, when there are several").option("-y, --yes", "don't ask before cancelling a run").action(async (options) => runnerRestart(await ctx(), options));
|