monoban 1.5.1 → 1.7.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/README.md +5 -3
- package/dist/index.mjs +1710 -998
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { homedir, hostname, tmpdir } from "node:os";
|
|
3
|
-
import path, { dirname, join, resolve, sep } from "node:path";
|
|
4
|
-
import { mkdir, mkdtemp, open, readFile, realpath, rename, rm, rmdir, stat, writeFile } from "node:fs/promises";
|
|
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";
|
|
5
5
|
import childProcess, { execFile, spawn, spawnSync } from "node:child_process";
|
|
6
6
|
import { EventEmitter } from "node:events";
|
|
7
|
-
import fs, { existsSync, realpathSync } from "node:fs";
|
|
7
|
+
import fs, { existsSync, readdirSync, realpathSync } 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";
|
|
11
11
|
import { createHash, randomBytes } from "node:crypto";
|
|
12
|
+
import { pathToFileURL } from "node:url";
|
|
12
13
|
import { createServer } from "node:http";
|
|
13
14
|
import { createInterface as createInterface$1 } from "node:readline";
|
|
14
15
|
/** Where the CLI keeps its files: $MONOBAN_CONFIG_DIR, else $XDG_CONFIG_HOME/monoban, else ~/.config/monoban. */
|
|
@@ -64,17 +65,20 @@ const AGENTS$1 = {
|
|
|
64
65
|
agentpipe: {
|
|
65
66
|
label: "agentpipe",
|
|
66
67
|
description: "Plans, implements and verifies in steps; moves and comments on the task itself.",
|
|
67
|
-
options: ["budgetUsd", "autonomous"]
|
|
68
|
+
options: ["budgetUsd", "autonomous"],
|
|
69
|
+
install: "monoban agentpipe install"
|
|
68
70
|
},
|
|
69
71
|
claude: {
|
|
70
72
|
label: "Claude Code",
|
|
71
73
|
description: "claude -p in auto mode: a classifier reviews what it does, and nothing waits for you.",
|
|
72
|
-
options: ["budgetUsd", "model"]
|
|
74
|
+
options: ["budgetUsd", "model"],
|
|
75
|
+
install: "npm install -g @anthropic-ai/claude-code"
|
|
73
76
|
},
|
|
74
77
|
codex: {
|
|
75
78
|
label: "Codex",
|
|
76
79
|
description: "codex exec in its sandbox: it writes in the folder, with the network off unless you say.",
|
|
77
|
-
options: ["model", "access"]
|
|
80
|
+
options: ["model", "access"],
|
|
81
|
+
install: "npm install -g @openai/codex"
|
|
78
82
|
}
|
|
79
83
|
};
|
|
80
84
|
/** How Codex may reach outside the folder: its sandbox, the sandbox with the network, or no sandbox. */
|
|
@@ -104,7 +108,7 @@ function unsupportedOption(agent, options) {
|
|
|
104
108
|
return null;
|
|
105
109
|
}
|
|
106
110
|
//#endregion
|
|
107
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
111
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/util.js
|
|
108
112
|
function getEnumValues(entries) {
|
|
109
113
|
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
110
114
|
return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
@@ -411,6 +415,17 @@ function prefixIssues(path, issues) {
|
|
|
411
415
|
function unwrapMessage(message) {
|
|
412
416
|
return typeof message === "string" ? message : message?.message;
|
|
413
417
|
}
|
|
418
|
+
/** The leading size checks of `defChecks` that set an upper bound, each paired with it. */
|
|
419
|
+
function sizeCaps(defChecks) {
|
|
420
|
+
const caps = [];
|
|
421
|
+
for (const ch of defChecks ?? []) {
|
|
422
|
+
const d = ch._zod.def;
|
|
423
|
+
if (!/_(length|size)$|_equals$/.test(d.check)) break;
|
|
424
|
+
const max = d.maximum ?? d.length ?? d.size;
|
|
425
|
+
if (max >= 0) caps.push([max, ch]);
|
|
426
|
+
}
|
|
427
|
+
return caps;
|
|
428
|
+
}
|
|
414
429
|
function attachSchema(issues, start, inst) {
|
|
415
430
|
var _a;
|
|
416
431
|
for (let i = start; i < issues.length; i++) (_a = issues[i]).schema ?? (_a.schema = inst);
|
|
@@ -627,7 +642,7 @@ function constantCatch(value) {
|
|
|
627
642
|
return fn;
|
|
628
643
|
}
|
|
629
644
|
//#endregion
|
|
630
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
645
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/core.js
|
|
631
646
|
var _a$1;
|
|
632
647
|
const _zodDesc = {
|
|
633
648
|
value: void 0,
|
|
@@ -733,7 +748,7 @@ function config(newConfig) {
|
|
|
733
748
|
return globalConfig;
|
|
734
749
|
}
|
|
735
750
|
//#endregion
|
|
736
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
751
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/errors.js
|
|
737
752
|
function _getMessage() {
|
|
738
753
|
const internals = this._zod;
|
|
739
754
|
internals.message ?? (internals.message = JSON.stringify(internals.def, jsonStringifyReplacer, 2));
|
|
@@ -849,7 +864,7 @@ function formatError(error, mapper = (issue) => issue.message) {
|
|
|
849
864
|
return fieldErrors;
|
|
850
865
|
}
|
|
851
866
|
//#endregion
|
|
852
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
867
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/parse.js
|
|
853
868
|
function finalizeParams(callee, params) {
|
|
854
869
|
return {
|
|
855
870
|
callee: params?.callee ?? callee,
|
|
@@ -1052,7 +1067,7 @@ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
|
1052
1067
|
return _safeParseAsync(_Err)(schema, value, _ctx);
|
|
1053
1068
|
};
|
|
1054
1069
|
//#endregion
|
|
1055
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
1070
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/regexes.js
|
|
1056
1071
|
/**
|
|
1057
1072
|
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
1058
1073
|
* (timestamps embedded in the id). Use {@link cuid2} instead.
|
|
@@ -1125,7 +1140,7 @@ const _null$2 = /^null$/i;
|
|
|
1125
1140
|
const lowercase = /^[^A-Z]*$/;
|
|
1126
1141
|
const uppercase = /^[^a-z]*$/;
|
|
1127
1142
|
//#endregion
|
|
1128
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
1143
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/checks.js
|
|
1129
1144
|
const $ZodCheck = /*@__PURE__*/ $constructor("$ZodCheck", (inst, def) => {
|
|
1130
1145
|
var _a;
|
|
1131
1146
|
inst._zod ?? (inst._zod = {});
|
|
@@ -1421,7 +1436,7 @@ const $ZodCheckOverwrite = /*@__PURE__*/ $constructor("$ZodCheckOverwrite", (ins
|
|
|
1421
1436
|
};
|
|
1422
1437
|
});
|
|
1423
1438
|
//#endregion
|
|
1424
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
1439
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/doc.js
|
|
1425
1440
|
var Doc = class {
|
|
1426
1441
|
constructor(args = [], closed = {}) {
|
|
1427
1442
|
this.content = [];
|
|
@@ -1455,14 +1470,14 @@ var Doc = class {
|
|
|
1455
1470
|
}
|
|
1456
1471
|
};
|
|
1457
1472
|
//#endregion
|
|
1458
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
1473
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/versions.js
|
|
1459
1474
|
const version = {
|
|
1460
1475
|
major: 4,
|
|
1461
1476
|
minor: 6,
|
|
1462
|
-
patch:
|
|
1477
|
+
patch: 7
|
|
1463
1478
|
};
|
|
1464
1479
|
//#endregion
|
|
1465
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
1480
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/schemas.js
|
|
1466
1481
|
const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
1467
1482
|
var _a;
|
|
1468
1483
|
inst ?? (inst = {});
|
|
@@ -1975,6 +1990,26 @@ const $ZodNever = /*@__PURE__*/ $constructor("$ZodNever", (inst, def) => {
|
|
|
1975
1990
|
return payload;
|
|
1976
1991
|
};
|
|
1977
1992
|
});
|
|
1993
|
+
function capSize(inst, size) {
|
|
1994
|
+
const caps = sizeCaps(inst._zod.def.checks);
|
|
1995
|
+
if (!caps.length) return;
|
|
1996
|
+
const cap = Math.min(...caps.map((c) => c[0]));
|
|
1997
|
+
const parse = inst._zod.parse;
|
|
1998
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1999
|
+
const n = size(payload.value);
|
|
2000
|
+
if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
|
|
2001
|
+
for (const [max, ch] of sizeCaps(inst._zod.def.checks)) if (n > max && ch._zod.def.when(payload)) {
|
|
2002
|
+
const start = payload.issues.length;
|
|
2003
|
+
ch._zod.check(payload);
|
|
2004
|
+
payload.issues[start].continue = false;
|
|
2005
|
+
attachSchema(payload.issues, start, inst);
|
|
2006
|
+
return payload;
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
return parse(payload, ctx);
|
|
2010
|
+
};
|
|
2011
|
+
}
|
|
2012
|
+
const arraySize = (input) => Array.isArray(input) ? input.length : -1;
|
|
1978
2013
|
function handleArrayResult(result, final, index) {
|
|
1979
2014
|
if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
|
|
1980
2015
|
final.value[index] = result.value;
|
|
@@ -2012,6 +2047,7 @@ const $ZodArray = /*@__PURE__*/ $constructor("$ZodArray", (inst, def) => {
|
|
|
2012
2047
|
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
2013
2048
|
return payload;
|
|
2014
2049
|
};
|
|
2050
|
+
capSize(inst, arraySize);
|
|
2015
2051
|
});
|
|
2016
2052
|
function handlePropertyResult(result, final, key, input, optin, optout) {
|
|
2017
2053
|
const isPresent = key in input;
|
|
@@ -2120,7 +2156,7 @@ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
|
|
|
2120
2156
|
}
|
|
2121
2157
|
return propValues;
|
|
2122
2158
|
});
|
|
2123
|
-
const isObject$
|
|
2159
|
+
const isObject$1 = isObject;
|
|
2124
2160
|
const catchall = def.catchall;
|
|
2125
2161
|
let value;
|
|
2126
2162
|
const memo = globalConfig.memoizer;
|
|
@@ -2128,7 +2164,7 @@ const $ZodObject = /*@__PURE__*/ $constructor("$ZodObject", (inst, def) => {
|
|
|
2128
2164
|
inst._zod.parse = (payload, ctx) => {
|
|
2129
2165
|
value ?? (value = _normalized.value);
|
|
2130
2166
|
const input = payload.value;
|
|
2131
|
-
if (!isObject$
|
|
2167
|
+
if (!isObject$1(input)) {
|
|
2132
2168
|
payload.issues.push({
|
|
2133
2169
|
expected: "object",
|
|
2134
2170
|
code: "invalid_type",
|
|
@@ -2258,7 +2294,7 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
2258
2294
|
return doc.compile();
|
|
2259
2295
|
};
|
|
2260
2296
|
let fastpass;
|
|
2261
|
-
const isObject$
|
|
2297
|
+
const isObject$2 = isObject;
|
|
2262
2298
|
const jit = !globalConfig.jitless;
|
|
2263
2299
|
const fastEnabled = jit && allowsEval.value;
|
|
2264
2300
|
const catchall = def.catchall;
|
|
@@ -2266,7 +2302,7 @@ const $ZodObjectJIT = /*@__PURE__*/ $constructor("$ZodObjectJIT", (inst, def) =>
|
|
|
2266
2302
|
inst._zod.parse = (payload, ctx) => {
|
|
2267
2303
|
value ?? (value = _normalized.value);
|
|
2268
2304
|
const input = payload.value;
|
|
2269
|
-
if (!isObject$
|
|
2305
|
+
if (!isObject$2(input)) {
|
|
2270
2306
|
payload.issues.push({
|
|
2271
2307
|
expected: "object",
|
|
2272
2308
|
code: "invalid_type",
|
|
@@ -2912,7 +2948,7 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
2912
2948
|
}
|
|
2913
2949
|
}
|
|
2914
2950
|
//#endregion
|
|
2915
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
2951
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/memoizer.js
|
|
2916
2952
|
var $ZodCyclicError = class extends Error {
|
|
2917
2953
|
constructor() {
|
|
2918
2954
|
super(`Cannot parse a reference cycle that closes through a transform`);
|
|
@@ -3165,7 +3201,7 @@ function isBackEdge(ctx, value) {
|
|
|
3165
3201
|
return backEdges !== void 0 && isRef(value) && backEdges.has(value);
|
|
3166
3202
|
}
|
|
3167
3203
|
//#endregion
|
|
3168
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
3204
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/locales/en.js
|
|
3169
3205
|
const error = () => {
|
|
3170
3206
|
const Sizable = {
|
|
3171
3207
|
string: {
|
|
@@ -3273,7 +3309,7 @@ function en_default() {
|
|
|
3273
3309
|
return { localeError: error() };
|
|
3274
3310
|
}
|
|
3275
3311
|
//#endregion
|
|
3276
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
3312
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/registries.js
|
|
3277
3313
|
var _a;
|
|
3278
3314
|
var $ZodRegistry = class {
|
|
3279
3315
|
constructor() {
|
|
@@ -3320,7 +3356,7 @@ function registry() {
|
|
|
3320
3356
|
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
3321
3357
|
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
3322
3358
|
//#endregion
|
|
3323
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
3359
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/api.js
|
|
3324
3360
|
function snapshotChecks(def) {
|
|
3325
3361
|
if (def.checks) def.checks = [...def.checks];
|
|
3326
3362
|
return def;
|
|
@@ -3845,7 +3881,7 @@ function _check(fn, params) {
|
|
|
3845
3881
|
return ch;
|
|
3846
3882
|
}
|
|
3847
3883
|
//#endregion
|
|
3848
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
3884
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/to-json-schema.js
|
|
3849
3885
|
function assignProps(target, ...sources) {
|
|
3850
3886
|
for (const source of sources) for (const key of Reflect.ownKeys(source)) if (Object.prototype.propertyIsEnumerable.call(source, key)) assignProp(target, key, source[key]);
|
|
3851
3887
|
return target;
|
|
@@ -4289,7 +4325,7 @@ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params)
|
|
|
4289
4325
|
return finalize(ctx, schema);
|
|
4290
4326
|
};
|
|
4291
4327
|
//#endregion
|
|
4292
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
4328
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/core/json-schema-processors.js
|
|
4293
4329
|
const narrowMin = (agg, key, value) => {
|
|
4294
4330
|
if (agg[key] === void 0 || value > agg[key]) agg[key] = value;
|
|
4295
4331
|
};
|
|
@@ -4744,7 +4780,7 @@ const optionalProcessor = (schema, ctx, _json, params) => {
|
|
|
4744
4780
|
seen.ref = def.innerType;
|
|
4745
4781
|
};
|
|
4746
4782
|
//#endregion
|
|
4747
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
4783
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/classic/errors.js
|
|
4748
4784
|
const _installedErrorProtos = /* @__PURE__ */ new WeakSet([Object.prototype, Error.prototype]);
|
|
4749
4785
|
function _lazyMethod(proto, key, make) {
|
|
4750
4786
|
Object.defineProperty(proto, key, {
|
|
@@ -4794,7 +4830,7 @@ const initializer = (inst, issues) => {
|
|
|
4794
4830
|
};
|
|
4795
4831
|
const ZodRealError = /*@__PURE__*/ $constructor("ZodError", initializer, void 0, { Parent: Error });
|
|
4796
4832
|
//#endregion
|
|
4797
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
4833
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/classic/parse.js
|
|
4798
4834
|
const parse$1 = /* @__PURE__ */ _parse(ZodRealError);
|
|
4799
4835
|
const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
4800
4836
|
const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
@@ -4808,7 +4844,7 @@ const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
|
|
|
4808
4844
|
const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
|
|
4809
4845
|
const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
|
|
4810
4846
|
//#endregion
|
|
4811
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
4847
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/classic/schemas.js
|
|
4812
4848
|
function _ensureDefaultLocale() {
|
|
4813
4849
|
if (!globalConfig.localeError) config(en_default());
|
|
4814
4850
|
}
|
|
@@ -5715,12 +5751,12 @@ function superRefine(fn, params) {
|
|
|
5715
5751
|
return /* @__PURE__ */ _superRefine(fn, params);
|
|
5716
5752
|
}
|
|
5717
5753
|
//#endregion
|
|
5718
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
5754
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/classic/iso.js
|
|
5719
5755
|
function datetime(params) {
|
|
5720
5756
|
return /* @__PURE__ */ _isoDateTime(ZodISODateTime, params);
|
|
5721
5757
|
}
|
|
5722
5758
|
//#endregion
|
|
5723
|
-
//#region ../../node_modules/.pnpm/zod@4.6.
|
|
5759
|
+
//#region ../../node_modules/.pnpm/zod@4.6.7/node_modules/zod/v4/classic/coerce.js
|
|
5724
5760
|
function number(params) {
|
|
5725
5761
|
return /* @__PURE__ */ _coercedNumber(ZodNumber, params);
|
|
5726
5762
|
}
|
|
@@ -5754,7 +5790,9 @@ const LIMITS = {
|
|
|
5754
5790
|
linkTitle: 200,
|
|
5755
5791
|
/** A comment on a task, in characters. */
|
|
5756
5792
|
commentBody: 2e4,
|
|
5757
|
-
commentsPerTask: 500
|
|
5793
|
+
commentsPerTask: 500,
|
|
5794
|
+
/** Why a task won't be done (archiving it outside Done), in characters. */
|
|
5795
|
+
archiveReason: 500
|
|
5758
5796
|
};
|
|
5759
5797
|
//#endregion
|
|
5760
5798
|
//#region ../../packages/contract/src/dates.ts
|
|
@@ -6624,6 +6662,8 @@ strictObject({
|
|
|
6624
6662
|
/** A task's tags: ids of its project's tags or shared ones, at most 10, each once. */
|
|
6625
6663
|
const tagIds = array(IdSchema).max(LIMITS.tagsPerTask).refine((ids) => new Set(ids.map((id) => id.toLowerCase())).size === ids.length, "Each tag once").meta({ uniqueItems: true });
|
|
6626
6664
|
const taskTitle = text().min(1, "Required").max(LIMITS.taskTitle);
|
|
6665
|
+
/** Why a task won't be done. */
|
|
6666
|
+
const archiveReason = text().min(1, "Required").max(LIMITS.archiveReason);
|
|
6627
6667
|
/** Markdown; kept as written (not trimmed). */
|
|
6628
6668
|
const taskDescription = string().max(LIMITS.taskDescription).regex(/^[^\u0000]*$/, "Can't contain NUL characters");
|
|
6629
6669
|
string().regex(/^[A-Za-z][A-Za-z0-9]{1,4}-[1-9][0-9]{0,8}$/, "A task reference like MON-12").meta({ example: "MON-12" });
|
|
@@ -6699,10 +6739,22 @@ strictObject({
|
|
|
6699
6739
|
/** Its tags from now on (all of them: the list replaces the old one). */
|
|
6700
6740
|
tagIds: tagIds.optional(),
|
|
6701
6741
|
/** The day you plan to work on it; null takes the date off. */
|
|
6702
|
-
scheduledOn: DaySchema.nullable().optional()
|
|
6703
|
-
|
|
6742
|
+
scheduledOn: DaySchema.nullable().optional(),
|
|
6743
|
+
/**
|
|
6744
|
+
* true: archive it now (off the board). In the Done column (or with `columnId` moving it there) that's
|
|
6745
|
+
* done; anywhere else it's "won't do", and needs an `archiveReason` (else 400). false: back on the board
|
|
6746
|
+
* (in Done, for another archiveAfterDays), without its reason.
|
|
6747
|
+
*/
|
|
6748
|
+
archived: boolean().optional(),
|
|
6749
|
+
/** Why it won't be done, with `archived: true`. Archiving it again with another reason replaces it. */
|
|
6750
|
+
archiveReason: archiveReason.optional()
|
|
6751
|
+
}).refine((patch) => Object.keys(patch).length > 0, "Send at least one field to change").refine((patch) => patch.archiveReason === void 0 || patch.archived === true, {
|
|
6752
|
+
message: "archiveReason goes with archived: true",
|
|
6753
|
+
path: ["archiveReason"]
|
|
6754
|
+
}).meta({
|
|
6704
6755
|
id: "TaskPatch",
|
|
6705
|
-
minProperties: 1
|
|
6756
|
+
minProperties: 1,
|
|
6757
|
+
dependentRequired: { archiveReason: ["archived"] }
|
|
6706
6758
|
});
|
|
6707
6759
|
strictObject({
|
|
6708
6760
|
/** The project's key (MON). */
|
|
@@ -6739,6 +6791,10 @@ strictObject({
|
|
|
6739
6791
|
createdAt: datetime({ offset: true }).optional(),
|
|
6740
6792
|
/** When it came into its column, so an undone delete doesn't start its archive clock again. */
|
|
6741
6793
|
columnSince: Timestamp.optional(),
|
|
6794
|
+
/** When it was archived by hand, so an undone delete leaves it archived. */
|
|
6795
|
+
archivedAt: Timestamp.nullable().optional(),
|
|
6796
|
+
/** Why it won't be done, with `archivedAt`. */
|
|
6797
|
+
archiveReason: archiveReason.nullable().optional(),
|
|
6742
6798
|
ref: string().optional(),
|
|
6743
6799
|
version: string().optional(),
|
|
6744
6800
|
updatedAt: string().optional()
|
|
@@ -6760,6 +6816,13 @@ const TaskSchema = object({
|
|
|
6760
6816
|
scheduledOn: DaySchema.nullable(),
|
|
6761
6817
|
/** When it came into its column. In the Done column for longer than its project's archiveAfterDays, it's archived. */
|
|
6762
6818
|
columnSince: Timestamp,
|
|
6819
|
+
/**
|
|
6820
|
+
* When it was archived by hand, or null: done (in the Done column), or won't do (anywhere, with an
|
|
6821
|
+
* `archiveReason`). Moving it to another column clears it.
|
|
6822
|
+
*/
|
|
6823
|
+
archivedAt: Timestamp.nullable(),
|
|
6824
|
+
/** Why it won't be done, when it was archived with a reason; else null. */
|
|
6825
|
+
archiveReason: string().nullable(),
|
|
6763
6826
|
version: Version,
|
|
6764
6827
|
createdAt: Timestamp,
|
|
6765
6828
|
updatedAt: Timestamp
|
|
@@ -6865,7 +6928,12 @@ discriminatedUnion("kind", [
|
|
|
6865
6928
|
status: _enum(RUN_ENDINGS$1),
|
|
6866
6929
|
reason: string().nullable(),
|
|
6867
6930
|
prUrl: string().nullable()
|
|
6868
|
-
}).meta({ id: "EventRunEnding" }) })
|
|
6931
|
+
}).meta({ id: "EventRunEnding" }) }),
|
|
6932
|
+
event("archived", {
|
|
6933
|
+
column: EventColumn,
|
|
6934
|
+
reason: string().nullable()
|
|
6935
|
+
}),
|
|
6936
|
+
event("unarchived", { column: EventColumn })
|
|
6869
6937
|
]).meta({ id: "TaskEvent" });
|
|
6870
6938
|
/**
|
|
6871
6939
|
* Every list takes `?limit=` and `?cursor=` and answers `{ <items>: [...], nextCursor }` (keyset
|
|
@@ -7091,9 +7159,12 @@ const SEARCH_LIMITS = {
|
|
|
7091
7159
|
PageQuerySchema.extend({ q: string().trim().min(1).max(SEARCH_LIMITS.length).regex(/^[^\u0000]*$/).describe(`Words, all of which a task must have (any case): in its title or description, as its tag's name, or as its reference (\`MON-12\`). At most ${SEARCH_LIMITS.words} words.`) });
|
|
7092
7160
|
TaskSchema.extend({
|
|
7093
7161
|
...TaskPlace,
|
|
7094
|
-
/**
|
|
7162
|
+
/** Archived: off its board (archived by hand, or done longer ago than its project's archive setting). */
|
|
7095
7163
|
archived: boolean()
|
|
7096
7164
|
}).meta({ id: "FoundTask" });
|
|
7165
|
+
object({
|
|
7166
|
+
/** How many tasks it archived (the ones in the Done column that weren't archived yet). */
|
|
7167
|
+
archived: number$1().int().nonnegative() }).meta({ id: "ArchivedDone" });
|
|
7097
7168
|
object({
|
|
7098
7169
|
project: ProjectSchema,
|
|
7099
7170
|
columns: array(ColumnSchema),
|
|
@@ -7103,9 +7174,24 @@ object({
|
|
|
7103
7174
|
tasks: array(TaskSchema),
|
|
7104
7175
|
/** How many archived tasks it leaves out. */
|
|
7105
7176
|
archived: number$1().int().nonnegative(),
|
|
7177
|
+
/** The same, per column (by column id): only the columns that have any. */
|
|
7178
|
+
archivedIn: record(string(), number$1().int().positive()),
|
|
7106
7179
|
/** More tasks than the board returns at once (2,000): load the rest from the paginated task list. */
|
|
7107
|
-
truncated: boolean()
|
|
7180
|
+
truncated: boolean(),
|
|
7181
|
+
/**
|
|
7182
|
+
* Goes up with every change to what the board shows (not with a done task that the days archive):
|
|
7183
|
+
* `GET /v1/sync` answers it without loading the board.
|
|
7184
|
+
*/
|
|
7185
|
+
version: string().regex(/^\d+$/).meta({ example: "42" })
|
|
7108
7186
|
}).meta({ id: "Board" });
|
|
7187
|
+
object({
|
|
7188
|
+
/** Changes with the project list (`GET /v1/projects`): a project made, changed, moved or deleted, or a task count. */
|
|
7189
|
+
projects: string(),
|
|
7190
|
+
/** The board's `version` (`GET /v1/projects/{key}/board`), with `project`. */
|
|
7191
|
+
board: string().nullable(),
|
|
7192
|
+
/** The notes' `version` (`GET /v1/projects/{key}/notes`), with `project`. */
|
|
7193
|
+
notes: string().nullable()
|
|
7194
|
+
}).meta({ id: "Sync" });
|
|
7109
7195
|
/** Notes text: kept as written (not trimmed). */
|
|
7110
7196
|
const notesText = string().max(LIMITS.projectNotes).regex(/^[^\u0000]*$/, "Can't contain NUL characters");
|
|
7111
7197
|
object({
|
|
@@ -7864,6 +7950,14 @@ function describeEvent(event, now = today()) {
|
|
|
7864
7950
|
verb: "commented",
|
|
7865
7951
|
detail: event.comment.excerpt
|
|
7866
7952
|
};
|
|
7953
|
+
case "archived": return {
|
|
7954
|
+
verb: "archived",
|
|
7955
|
+
detail: `in ${event.column.name}${event.reason ? `: ${event.reason}` : ""}`
|
|
7956
|
+
};
|
|
7957
|
+
case "unarchived": return {
|
|
7958
|
+
verb: "unarchived",
|
|
7959
|
+
detail: `in ${event.column.name}`
|
|
7960
|
+
};
|
|
7867
7961
|
case "run_started": return {
|
|
7868
7962
|
verb: "run started",
|
|
7869
7963
|
detail: `${event.run.adapter} on ${event.run.runner}`
|
|
@@ -7978,18 +8072,24 @@ function matchColumn(columns, query) {
|
|
|
7978
8072
|
}
|
|
7979
8073
|
const DAY_MS = 864e5;
|
|
7980
8074
|
/**
|
|
7981
|
-
* Whether a task is archived: in
|
|
7982
|
-
*
|
|
8075
|
+
* Whether a task is archived: archived by hand (in any column: in Done it's done, elsewhere it won't be), or
|
|
8076
|
+
* in its project's Done column (`doneColumnId`: doneColumn()) for longer than the project's
|
|
8077
|
+
* `archiveAfterDays` (null: never). The API applies the same rule when it reads.
|
|
7983
8078
|
*/
|
|
7984
8079
|
function isArchived(task, doneColumnId, archiveAfterDays, now = Date.now()) {
|
|
7985
|
-
if (
|
|
7986
|
-
|
|
8080
|
+
if (task.archivedAt) return true;
|
|
8081
|
+
if (!doneColumnId || task.columnId !== doneColumnId || archiveAfterDays === null) return false;
|
|
8082
|
+
return archivedByTime(task, archiveAfterDays, now);
|
|
8083
|
+
}
|
|
8084
|
+
/** Whether a task has been in its column for longer than `archiveAfterDays` (in Done, that archives it). */
|
|
8085
|
+
function archivedByTime(task, archiveAfterDays, now = Date.now()) {
|
|
8086
|
+
return archiveAfterDays !== null && Date.parse(task.columnSince) < now - archiveAfterDays * DAY_MS;
|
|
7987
8087
|
}
|
|
7988
8088
|
strictObject({ email: email().max(254).meta({ example: "ada@example.com" }) }).meta({ id: "WaitlistJoin" });
|
|
7989
8089
|
//#endregion
|
|
7990
8090
|
//#region src/version.ts
|
|
7991
8091
|
/** This CLI's version, from package.json (set at build time by tsdown, and by vitest in tests). */
|
|
7992
|
-
const VERSION = "1.
|
|
8092
|
+
const VERSION = "1.7.0";
|
|
7993
8093
|
/** Sent as X-Monoban-Client, and shown in Devices & tokens. */
|
|
7994
8094
|
const CLIENT = `cli/${VERSION}`;
|
|
7995
8095
|
//#endregion
|
|
@@ -11123,7 +11223,7 @@ new Command();
|
|
|
11123
11223
|
* token works once, and using it twice signs the CLI out). A lock older than `staleMs` is from a
|
|
11124
11224
|
* process that died, and is taken over.
|
|
11125
11225
|
*/
|
|
11126
|
-
async function withLock(path, fn, { staleMs = 3e4, timeoutMs = 45e3, sleep = wait$1 } = {}) {
|
|
11226
|
+
async function withLock(path, fn, { staleMs = 3e4, timeoutMs = 45e3, sleep = wait$1, busy = `Another monoban is still refreshing the sign-in (${path}). Try again.` } = {}) {
|
|
11127
11227
|
await mkdir(dirname(path), {
|
|
11128
11228
|
recursive: true,
|
|
11129
11229
|
mode: 448
|
|
@@ -11137,7 +11237,7 @@ async function withLock(path, fn, { staleMs = 3e4, timeoutMs = 45e3, sleep = wai
|
|
|
11137
11237
|
if (err.code !== "EEXIST") throw err;
|
|
11138
11238
|
}
|
|
11139
11239
|
if (await stat(path).then((s) => Date.now() - s.mtimeMs, () => 0) > staleMs) await rm(path, { force: true });
|
|
11140
|
-
else if (Date.now() > deadline) throw new Error(
|
|
11240
|
+
else if (Date.now() > deadline) throw new Error(busy);
|
|
11141
11241
|
else await sleep(100);
|
|
11142
11242
|
}
|
|
11143
11243
|
try {
|
|
@@ -11255,7 +11355,7 @@ function report(err, print, apiUrl) {
|
|
|
11255
11355
|
return err.status === 404 ? EXIT.notFound : EXIT.error;
|
|
11256
11356
|
}
|
|
11257
11357
|
if (err instanceof CliError) {
|
|
11258
|
-
print(err.message);
|
|
11358
|
+
if (err.message) print(err.message);
|
|
11259
11359
|
return err.exitCode;
|
|
11260
11360
|
}
|
|
11261
11361
|
const cause = err instanceof TypeError ? err.cause : void 0;
|
|
@@ -11544,6 +11644,452 @@ const apis = (ctx) => ({
|
|
|
11544
11644
|
public: publicApi(ctx.apiUrl, ctx.fetch),
|
|
11545
11645
|
signedIn: signedInApi(ctx.apiUrl, ctx.session, ctx.fetch)
|
|
11546
11646
|
});
|
|
11647
|
+
const RELEASES = `https://github.com/thiagodmont/homebrew-tap/releases`;
|
|
11648
|
+
//#endregion
|
|
11649
|
+
//#region src/agentpipe/pin.ts
|
|
11650
|
+
/**
|
|
11651
|
+
* The agentpipe this monoban release installs (`monoban agentpipe install`): its wheel and its dependencies, each
|
|
11652
|
+
* pinned with a hash, from agentpipe's release on the tap (thiagodmont/homebrew-tap, `agentpipe-vX.Y.Z`). A new
|
|
11653
|
+
* agentpipe comes with a new monoban: change these three lines (from the release's checksums.txt) and release.
|
|
11654
|
+
*/
|
|
11655
|
+
const AGENTPIPE = {
|
|
11656
|
+
version: "0.5.0",
|
|
11657
|
+
wheelSha256: "e69545311cfc99f09df165facf7fb74540d3b0903400ed5311f8245cfba00a89",
|
|
11658
|
+
requirementsSha256: "41a8d073b0087efb80efafeb6a2b4750340d0f64920159cd4c723ed9167d0a98"
|
|
11659
|
+
};
|
|
11660
|
+
const agentpipeWheel = (version) => `agentpipe-${version}-py3-none-any.whl`;
|
|
11661
|
+
const agentpipeRequirements = (version) => `agentpipe-${version}-requirements.txt`;
|
|
11662
|
+
const agentpipeAsset = (version, name) => `${RELEASES}/download/agentpipe-v${version}/${name}`;
|
|
11663
|
+
/**
|
|
11664
|
+
* The uv that installs it, when the machine has none: uv's own release archives, with the SHA-256s GitHub and
|
|
11665
|
+
* uv publish for them.
|
|
11666
|
+
*/
|
|
11667
|
+
const UV = {
|
|
11668
|
+
version: "0.12.21",
|
|
11669
|
+
sha256: {
|
|
11670
|
+
"aarch64-apple-darwin": "b88bda573e566ef9bced66b155fe0408626fbbc053aee1c30ba686f0728c9447",
|
|
11671
|
+
"x86_64-apple-darwin": "2b336763b396ec6afa20c5a8b083538ca7402445b868311979d740a4344c17d8",
|
|
11672
|
+
"aarch64-unknown-linux-gnu": "030b69227b40af8c1981b7301793dc66e71ed3c796ea8688209dd268bd91ec51",
|
|
11673
|
+
"x86_64-unknown-linux-gnu": "23f02075b652bb1df64178cfae41b5caf160822e720e2663568f3f5d63bc52c0"
|
|
11674
|
+
}
|
|
11675
|
+
};
|
|
11676
|
+
const uvArchive = (target, version = UV.version) => `https://github.com/astral-sh/uv/releases/download/${version}/uv-${target}.tar.gz`;
|
|
11677
|
+
const UPGRADE = {
|
|
11678
|
+
brew: {
|
|
11679
|
+
how: "Homebrew",
|
|
11680
|
+
command: "brew upgrade monoban"
|
|
11681
|
+
},
|
|
11682
|
+
binary: {
|
|
11683
|
+
how: "a downloaded binary",
|
|
11684
|
+
command: `download it again: ${RELEASES}/latest`
|
|
11685
|
+
},
|
|
11686
|
+
npx: {
|
|
11687
|
+
how: "npx",
|
|
11688
|
+
command: "npx monoban@latest"
|
|
11689
|
+
},
|
|
11690
|
+
npm: {
|
|
11691
|
+
how: "npm",
|
|
11692
|
+
command: "npm install -g monoban@latest"
|
|
11693
|
+
},
|
|
11694
|
+
pnpm: {
|
|
11695
|
+
how: "pnpm",
|
|
11696
|
+
command: "pnpm add -g monoban@latest"
|
|
11697
|
+
},
|
|
11698
|
+
yarn: {
|
|
11699
|
+
how: "yarn",
|
|
11700
|
+
command: "yarn global add monoban@latest"
|
|
11701
|
+
},
|
|
11702
|
+
bun: {
|
|
11703
|
+
how: "bun",
|
|
11704
|
+
command: "bun add -g monoban@latest"
|
|
11705
|
+
}
|
|
11706
|
+
};
|
|
11707
|
+
/**
|
|
11708
|
+
* Told apart by where it runs from: a binary in a Homebrew Cellar, or the npm package under npx's
|
|
11709
|
+
* cache or a package manager's global folder (npm when it's none of those).
|
|
11710
|
+
*/
|
|
11711
|
+
function installKind(where) {
|
|
11712
|
+
if (where.binary) return where.executable.includes("/Cellar/") ? "brew" : "binary";
|
|
11713
|
+
const script = where.script.replaceAll("\\", "/");
|
|
11714
|
+
if (script.includes("/_npx/")) return "npx";
|
|
11715
|
+
if (/\/\.?pnpm\//.test(script)) return "pnpm";
|
|
11716
|
+
if (script.includes("/.bun/")) return "bun";
|
|
11717
|
+
if (/\/(\.yarn|yarn\/global)\//.test(script)) return "yarn";
|
|
11718
|
+
return "npm";
|
|
11719
|
+
}
|
|
11720
|
+
const real = (path) => {
|
|
11721
|
+
try {
|
|
11722
|
+
return path ? realpathSync(path) : "";
|
|
11723
|
+
} catch {
|
|
11724
|
+
return path ?? "";
|
|
11725
|
+
}
|
|
11726
|
+
};
|
|
11727
|
+
/**
|
|
11728
|
+
* The command that runs this monoban, for a program it starts to call it back (MONOBAN_BIN): the binary itself,
|
|
11729
|
+
* or the npm package's script, which runs with the node on the PATH.
|
|
11730
|
+
*/
|
|
11731
|
+
const selfCommand = () => {
|
|
11732
|
+
const command = process.argv[1];
|
|
11733
|
+
return command && isAbsolute(command) ? command : null;
|
|
11734
|
+
};
|
|
11735
|
+
/** This process's install. */
|
|
11736
|
+
const thisInstall = () => installKind({
|
|
11737
|
+
binary: false,
|
|
11738
|
+
executable: real(process.execPath),
|
|
11739
|
+
script: real(process.argv[1])
|
|
11740
|
+
});
|
|
11741
|
+
/** 1.2.10 > 1.2.9; a pre-release counts as its version. */
|
|
11742
|
+
function newer(a, b) {
|
|
11743
|
+
const parts = (v) => v.split(/[-+]/)[0]?.split(".").map(Number) ?? [];
|
|
11744
|
+
const [x, y] = [parts(a), parts(b)];
|
|
11745
|
+
for (let i = 0; i < 3; i++) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (x[i] ?? 0) > (y[i] ?? 0);
|
|
11746
|
+
return false;
|
|
11747
|
+
}
|
|
11748
|
+
/** The latest version on npm (Homebrew and the binaries ship the same releases), or null offline. */
|
|
11749
|
+
async function latestVersion(ctx) {
|
|
11750
|
+
try {
|
|
11751
|
+
const res = await ctx.fetch(new Request("https://registry.npmjs.org/monoban/latest", { signal: AbortSignal.timeout(3e3) }));
|
|
11752
|
+
if (!res.ok) return null;
|
|
11753
|
+
const { version } = await res.json();
|
|
11754
|
+
return typeof version === "string" ? version : null;
|
|
11755
|
+
} catch {
|
|
11756
|
+
return null;
|
|
11757
|
+
}
|
|
11758
|
+
}
|
|
11759
|
+
/** `monoban upgrade`: whether there's a newer version, and the command that installs it here. */
|
|
11760
|
+
async function upgrade(ctx, options, kind = thisInstall()) {
|
|
11761
|
+
const latest = await latestVersion(ctx);
|
|
11762
|
+
const { how, command } = UPGRADE[kind];
|
|
11763
|
+
const outdated = latest !== null && newer(latest, "1.7.0");
|
|
11764
|
+
if (options.json) {
|
|
11765
|
+
ctx.out(JSON.stringify({
|
|
11766
|
+
version: VERSION,
|
|
11767
|
+
latest,
|
|
11768
|
+
outdated,
|
|
11769
|
+
installedWith: kind,
|
|
11770
|
+
command
|
|
11771
|
+
}, null, 2));
|
|
11772
|
+
return;
|
|
11773
|
+
}
|
|
11774
|
+
if (latest === null) ctx.out(`You have monoban ${VERSION} (installed with ${how}). To get the latest: ${command}`);
|
|
11775
|
+
else if (outdated) ctx.out(`monoban ${latest} is out (you have ${VERSION}). To upgrade: ${command}`);
|
|
11776
|
+
else ctx.out(`monoban ${VERSION} is the latest.`);
|
|
11777
|
+
}
|
|
11778
|
+
//#endregion
|
|
11779
|
+
//#region src/agentpipe/install.ts
|
|
11780
|
+
/**
|
|
11781
|
+
* `monoban agentpipe install`: agentpipe, CLI only, in a folder of monoban's own, for `monoban runner` to run.
|
|
11782
|
+
*
|
|
11783
|
+
* <data dir>/agentpipe/versions/X.Y.Z a Python environment with agentpipe X.Y.Z (a venv can't be moved, so
|
|
11784
|
+
* each version is made where it stays)
|
|
11785
|
+
* <data dir>/agentpipe/current → versions/X.Y.Z, switched in one step once a version works
|
|
11786
|
+
* <data dir>/agentpipe/python, uv the Python 3.12 and the uv that made it, when the machine had no uv
|
|
11787
|
+
*
|
|
11788
|
+
* Every file is checked against a SHA-256 this monoban pins (agentpipe/pin.ts) before it's used: the wheel, its
|
|
11789
|
+
* requirements, and each dependency they name (`uv pip install --require-hashes`; `uv tool install` reads a
|
|
11790
|
+
* constraints file's versions but not its hashes).
|
|
11791
|
+
*/
|
|
11792
|
+
/** Where monoban keeps what it installs: $MONOBAN_DATA_DIR, else $XDG_DATA_HOME/monoban, else ~/.local/share/monoban. */
|
|
11793
|
+
function dataDir(env = process.env) {
|
|
11794
|
+
if (env.MONOBAN_DATA_DIR) return env.MONOBAN_DATA_DIR;
|
|
11795
|
+
if (env.XDG_DATA_HOME) return join(env.XDG_DATA_HOME, "monoban");
|
|
11796
|
+
return join(homedir(), ".local", "share", "monoban");
|
|
11797
|
+
}
|
|
11798
|
+
const agentpipeHome = (env = process.env) => join(dataDir(env), "agentpipe");
|
|
11799
|
+
/** The agentpipe monoban installed, whether or not it's there. */
|
|
11800
|
+
const agentpipeBin = (env = process.env) => join(agentpipeHome(env), "current", "bin", "agentpipe");
|
|
11801
|
+
/** The file agentpipe looks for to refer its `self-update` to monoban. */
|
|
11802
|
+
const MANAGED = "monoban-managed";
|
|
11803
|
+
/** The uv release this machine runs, or why agentpipe can't be installed here. */
|
|
11804
|
+
function installTarget(platform = process.platform, arch = process.arch, musl = isMusl) {
|
|
11805
|
+
const cpu = arch === "arm64" ? "aarch64" : arch === "x64" ? "x86_64" : null;
|
|
11806
|
+
if (!cpu) return { problem: `agentpipe runs on 64-bit Intel or ARM machines, not ${arch}.` };
|
|
11807
|
+
if (platform === "darwin") return { target: `${cpu}-apple-darwin` };
|
|
11808
|
+
if (platform === "linux") {
|
|
11809
|
+
if (musl()) return { problem: "agentpipe needs a Linux with glibc (Debian, Ubuntu, Fedora…), not musl (Alpine)." };
|
|
11810
|
+
return { target: `${cpu}-unknown-linux-gnu` };
|
|
11811
|
+
}
|
|
11812
|
+
return { problem: `agentpipe runs on macOS and Linux, not ${platform}.` };
|
|
11813
|
+
}
|
|
11814
|
+
function isMusl() {
|
|
11815
|
+
try {
|
|
11816
|
+
return readdirSync("/lib").some((name) => name.startsWith("ld-musl-"));
|
|
11817
|
+
} catch {
|
|
11818
|
+
return false;
|
|
11819
|
+
}
|
|
11820
|
+
}
|
|
11821
|
+
const exec$1 = (command, args, { env, cwd }) => new Promise((resolve) => {
|
|
11822
|
+
execFile(command, args, {
|
|
11823
|
+
env,
|
|
11824
|
+
cwd,
|
|
11825
|
+
maxBuffer: 33554432,
|
|
11826
|
+
timeout: 12e5
|
|
11827
|
+
}, (err, stdout, stderr) => {
|
|
11828
|
+
const code = err?.code;
|
|
11829
|
+
resolve({
|
|
11830
|
+
code: !err ? 0 : typeof code === "number" ? code : 127,
|
|
11831
|
+
stdout: String(stdout),
|
|
11832
|
+
stderr: String(stderr) || (err?.message ?? "")
|
|
11833
|
+
});
|
|
11834
|
+
});
|
|
11835
|
+
});
|
|
11836
|
+
/** The version `current` points to, when its agentpipe is there. */
|
|
11837
|
+
async function installedVersion(env = process.env) {
|
|
11838
|
+
const home = agentpipeHome(env);
|
|
11839
|
+
try {
|
|
11840
|
+
const version = basename(await readlink(join(home, "current")));
|
|
11841
|
+
await access(agentpipeBin(env), constants.X_OK);
|
|
11842
|
+
return version;
|
|
11843
|
+
} catch {
|
|
11844
|
+
return null;
|
|
11845
|
+
}
|
|
11846
|
+
}
|
|
11847
|
+
/** What uv gets of the environment: the network's settings and uv's own, and the folders it works in. */
|
|
11848
|
+
function uvEnv(env, home) {
|
|
11849
|
+
const keep = (name) => [
|
|
11850
|
+
"PATH",
|
|
11851
|
+
"HOME",
|
|
11852
|
+
"TMPDIR",
|
|
11853
|
+
"SSL_CERT_FILE",
|
|
11854
|
+
"SSL_CERT_DIR"
|
|
11855
|
+
].includes(name) || /^(https?|no|all)_proxy$/i.test(name) || name.startsWith("UV_");
|
|
11856
|
+
return {
|
|
11857
|
+
...Object.fromEntries(Object.entries(env).filter(([name, value]) => value !== void 0 && keep(name))),
|
|
11858
|
+
UV_PYTHON_INSTALL_DIR: join(home, "python"),
|
|
11859
|
+
UV_PYTHON_PREFERENCE: "only-managed",
|
|
11860
|
+
UV_CACHE_DIR: join(home, "cache"),
|
|
11861
|
+
UV_NO_PROGRESS: "1"
|
|
11862
|
+
};
|
|
11863
|
+
}
|
|
11864
|
+
/** An executable named `name` on PATH. */
|
|
11865
|
+
async function onPath(name, env) {
|
|
11866
|
+
for (const dir of (env.PATH ?? "").split(delimiter).filter(Boolean)) {
|
|
11867
|
+
const path = join(dir, name);
|
|
11868
|
+
try {
|
|
11869
|
+
await access(path, constants.X_OK);
|
|
11870
|
+
return path;
|
|
11871
|
+
} catch {}
|
|
11872
|
+
}
|
|
11873
|
+
return null;
|
|
11874
|
+
}
|
|
11875
|
+
/** The first version a command prints for `--version`, or null. */
|
|
11876
|
+
async function versionOf$1(run, command, env, cwd) {
|
|
11877
|
+
const { code, stdout } = await run(command, ["--version"], {
|
|
11878
|
+
env,
|
|
11879
|
+
cwd
|
|
11880
|
+
});
|
|
11881
|
+
return code === 0 ? /\d+\.\d+\.\d+/.exec(stdout)?.[0] ?? null : null;
|
|
11882
|
+
}
|
|
11883
|
+
const sha256 = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
11884
|
+
/** A download, kept only when it's the file this monoban pins. */
|
|
11885
|
+
async function download(ctx, url, expected) {
|
|
11886
|
+
let res;
|
|
11887
|
+
try {
|
|
11888
|
+
res = await ctx.fetch(new Request(url, { signal: AbortSignal.timeout(3e5) }));
|
|
11889
|
+
} catch (err) {
|
|
11890
|
+
throw new CliError(`Couldn't download ${url}: ${err.message}.`);
|
|
11891
|
+
}
|
|
11892
|
+
if (!res.ok) throw new CliError(`Couldn't download ${url}: HTTP ${res.status}.`);
|
|
11893
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
11894
|
+
const actual = sha256(bytes);
|
|
11895
|
+
if (actual !== expected) throw new CliError(`${url} isn't the file this monoban pins (SHA-256 ${actual}, expected ${expected}). Nothing was installed.`);
|
|
11896
|
+
return bytes;
|
|
11897
|
+
}
|
|
11898
|
+
/** The uv to install with: monoban's own, else a recent one on PATH, else monoban downloads its own. */
|
|
11899
|
+
async function findUv(ctx, run, home, target, uvPin) {
|
|
11900
|
+
const ours = join(home, "uv", "uv");
|
|
11901
|
+
if (existsSync(ours)) return ours;
|
|
11902
|
+
const theirs = await onPath("uv", ctx.env);
|
|
11903
|
+
const version = theirs && await versionOf$1(run, theirs, uvEnv(ctx.env, home), home);
|
|
11904
|
+
if (theirs && version && !newer("0.8.0", version)) return theirs;
|
|
11905
|
+
ctx.err(`Downloading uv ${uvPin.version}…`);
|
|
11906
|
+
const archive = join(home, "downloads", `uv-${target}.tar.gz`);
|
|
11907
|
+
await writeFile(archive, await download(ctx, uvArchive(target, uvPin.version), uvPin.sha256[target]));
|
|
11908
|
+
const unpacked = join(home, "downloads", "uv");
|
|
11909
|
+
await rm(unpacked, {
|
|
11910
|
+
recursive: true,
|
|
11911
|
+
force: true
|
|
11912
|
+
});
|
|
11913
|
+
await mkdir(unpacked, { recursive: true });
|
|
11914
|
+
const untar = await run("tar", [
|
|
11915
|
+
"-xzf",
|
|
11916
|
+
archive,
|
|
11917
|
+
"-C",
|
|
11918
|
+
unpacked
|
|
11919
|
+
], {
|
|
11920
|
+
env: ctx.env,
|
|
11921
|
+
cwd: home
|
|
11922
|
+
});
|
|
11923
|
+
if (untar.code !== 0) throw new CliError(`Couldn't unpack uv: ${untar.stderr.trim()}`);
|
|
11924
|
+
await mkdir(join(home, "uv"), { recursive: true });
|
|
11925
|
+
await rename(join(unpacked, `uv-${target}`, "uv"), ours);
|
|
11926
|
+
return ours;
|
|
11927
|
+
}
|
|
11928
|
+
/** Runs uv, and turns its failure into what it said. */
|
|
11929
|
+
async function uv(run, command, args, env, cwd, doing) {
|
|
11930
|
+
const { code, stderr } = await run(command, args, {
|
|
11931
|
+
env,
|
|
11932
|
+
cwd
|
|
11933
|
+
});
|
|
11934
|
+
if (code !== 0) throw new CliError(`Couldn't ${doing} (uv exited ${code}):\n${stderr.trim().split("\n").slice(-12).join("\n")}`);
|
|
11935
|
+
}
|
|
11936
|
+
/** `monoban agentpipe install` (and `update`): installs this monoban's agentpipe, unless it's there. */
|
|
11937
|
+
async function installAgentpipe(ctx, options = {}, deps = {}) {
|
|
11938
|
+
const run = deps.exec ?? exec$1;
|
|
11939
|
+
const where = deps.target ?? installTarget();
|
|
11940
|
+
const pins = deps.pins ?? {
|
|
11941
|
+
agentpipe: AGENTPIPE,
|
|
11942
|
+
uv: UV
|
|
11943
|
+
};
|
|
11944
|
+
const pin = pins.agentpipe;
|
|
11945
|
+
if ("problem" in where) throw new CliError(where.problem);
|
|
11946
|
+
const home = agentpipeHome(ctx.env);
|
|
11947
|
+
const { version } = pin;
|
|
11948
|
+
await mkdir(join(home, "downloads"), {
|
|
11949
|
+
recursive: true,
|
|
11950
|
+
mode: 448
|
|
11951
|
+
});
|
|
11952
|
+
await withLock(join(home, "install.lock"), async () => {
|
|
11953
|
+
const before = await installedVersion(ctx.env);
|
|
11954
|
+
if (before === version && !options.force) {
|
|
11955
|
+
ctx.out(`agentpipe ${version} is installed: ${agentpipeBin(ctx.env)}`);
|
|
11956
|
+
return;
|
|
11957
|
+
}
|
|
11958
|
+
const uvBin = await findUv(ctx, run, home, where.target, pins.uv);
|
|
11959
|
+
const env = uvEnv(ctx.env, home);
|
|
11960
|
+
ctx.err(`Downloading agentpipe ${version}…`);
|
|
11961
|
+
const wheel = join(home, "downloads", agentpipeWheel(version));
|
|
11962
|
+
await writeFile(wheel, await download(ctx, agentpipeAsset(version, agentpipeWheel(version)), pin.wheelSha256));
|
|
11963
|
+
const requirements = await download(ctx, agentpipeAsset(version, agentpipeRequirements(version)), pin.requirementsSha256);
|
|
11964
|
+
const lock = join(home, "downloads", "lock.txt");
|
|
11965
|
+
await writeFile(lock, `${new TextDecoder().decode(requirements).trimEnd()}\nagentpipe @ ${pathToFileURL(wheel).href} --hash=sha256:${pin.wheelSha256}\n`);
|
|
11966
|
+
ctx.err("Installing Python 3.12 and agentpipe's dependencies (a minute or two the first time)…");
|
|
11967
|
+
const dir = join(home, "versions", version);
|
|
11968
|
+
await rm(dir, {
|
|
11969
|
+
recursive: true,
|
|
11970
|
+
force: true
|
|
11971
|
+
});
|
|
11972
|
+
await uv(run, uvBin, [
|
|
11973
|
+
"venv",
|
|
11974
|
+
"--quiet",
|
|
11975
|
+
"--python",
|
|
11976
|
+
"3.12",
|
|
11977
|
+
dir
|
|
11978
|
+
], env, home, "make agentpipe's Python environment");
|
|
11979
|
+
await uv(run, uvBin, [
|
|
11980
|
+
"pip",
|
|
11981
|
+
"install",
|
|
11982
|
+
"--quiet",
|
|
11983
|
+
"--require-hashes",
|
|
11984
|
+
"--python",
|
|
11985
|
+
join(dir, "bin", "python"),
|
|
11986
|
+
"-r",
|
|
11987
|
+
lock
|
|
11988
|
+
], env, home, "install agentpipe");
|
|
11989
|
+
await writeFile(join(dir, MANAGED), "agentpipe is installed by monoban: update it with `monoban agentpipe update`.\n");
|
|
11990
|
+
const said = await run(join(dir, "bin", "agentpipe"), ["--version"], {
|
|
11991
|
+
env,
|
|
11992
|
+
cwd: home
|
|
11993
|
+
});
|
|
11994
|
+
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()}`);
|
|
11995
|
+
const link = join(home, "current.new");
|
|
11996
|
+
await rm(link, { force: true });
|
|
11997
|
+
await symlink(join("versions", version), link);
|
|
11998
|
+
await rename(link, join(home, "current"));
|
|
11999
|
+
for (const old of await readdir(join(home, "versions"))) if (old !== version && old !== before) await rm(join(home, "versions", old), {
|
|
12000
|
+
recursive: true,
|
|
12001
|
+
force: true
|
|
12002
|
+
});
|
|
12003
|
+
await rm(join(home, "cache"), {
|
|
12004
|
+
recursive: true,
|
|
12005
|
+
force: true
|
|
12006
|
+
});
|
|
12007
|
+
await rm(join(home, "downloads"), {
|
|
12008
|
+
recursive: true,
|
|
12009
|
+
force: true
|
|
12010
|
+
});
|
|
12011
|
+
ctx.out(`Installed agentpipe ${version}: ${agentpipeBin(ctx.env)}`);
|
|
12012
|
+
}, {
|
|
12013
|
+
staleMs: 18e5,
|
|
12014
|
+
timeoutMs: 0,
|
|
12015
|
+
busy: `Another monoban is installing agentpipe (${home}). Try again.`
|
|
12016
|
+
});
|
|
12017
|
+
}
|
|
12018
|
+
async function agentpipeStatus(env, target = installTarget()) {
|
|
12019
|
+
const installed = await installedVersion(env);
|
|
12020
|
+
return {
|
|
12021
|
+
installed,
|
|
12022
|
+
pinned: AGENTPIPE.version,
|
|
12023
|
+
command: installed ? agentpipeBin(env) : null,
|
|
12024
|
+
updateAvailable: installed !== null && newer(AGENTPIPE.version, installed),
|
|
12025
|
+
unsupported: "problem" in target ? target.problem : null
|
|
12026
|
+
};
|
|
12027
|
+
}
|
|
12028
|
+
/** The status in a sentence, and the command that fixes it. */
|
|
12029
|
+
function describeStatus(s) {
|
|
12030
|
+
if (s.unsupported && !s.installed) return {
|
|
12031
|
+
ok: false,
|
|
12032
|
+
text: s.unsupported
|
|
12033
|
+
};
|
|
12034
|
+
if (!s.installed) return {
|
|
12035
|
+
ok: false,
|
|
12036
|
+
text: "agentpipe isn't installed",
|
|
12037
|
+
fix: "monoban agentpipe install"
|
|
12038
|
+
};
|
|
12039
|
+
if (s.updateAvailable) return {
|
|
12040
|
+
ok: false,
|
|
12041
|
+
text: `agentpipe ${s.installed}; this monoban comes with ${s.pinned}`,
|
|
12042
|
+
fix: "monoban agentpipe update"
|
|
12043
|
+
};
|
|
12044
|
+
return {
|
|
12045
|
+
ok: true,
|
|
12046
|
+
text: `agentpipe ${s.installed} (${s.command})`
|
|
12047
|
+
};
|
|
12048
|
+
}
|
|
12049
|
+
/** `monoban agentpipe status`. */
|
|
12050
|
+
async function status(ctx, options) {
|
|
12051
|
+
const s = await agentpipeStatus(ctx.env);
|
|
12052
|
+
if (options.json) return ctx.out(JSON.stringify(s, null, 2));
|
|
12053
|
+
const { text, fix } = describeStatus(s);
|
|
12054
|
+
ctx.out(fix ? `${text}: ${fix}` : text);
|
|
12055
|
+
}
|
|
12056
|
+
/** `monoban agentpipe update`: this monoban's agentpipe, over an older one. */
|
|
12057
|
+
async function update(ctx, deps = {}) {
|
|
12058
|
+
const installed = await installedVersion(ctx.env);
|
|
12059
|
+
const pinned = (deps.pins?.agentpipe ?? AGENTPIPE).version;
|
|
12060
|
+
if (!installed) throw new CliError("agentpipe isn't installed by monoban: monoban agentpipe install", EXIT.notFound);
|
|
12061
|
+
if (installed === pinned) {
|
|
12062
|
+
ctx.out(`agentpipe ${installed} is the version this monoban comes with. A newer one comes with a newer monoban (monoban upgrade).`);
|
|
12063
|
+
return;
|
|
12064
|
+
}
|
|
12065
|
+
await installAgentpipe(ctx, {}, deps);
|
|
12066
|
+
}
|
|
12067
|
+
/** `monoban agentpipe uninstall`: removes what monoban installed; agentpipe's runs and settings stay. */
|
|
12068
|
+
async function uninstall(ctx, options) {
|
|
12069
|
+
const home = agentpipeHome(ctx.env);
|
|
12070
|
+
if (!existsSync(home)) return ctx.out("agentpipe isn't installed by monoban: nothing to remove.");
|
|
12071
|
+
if (!options.yes && !await ctx.confirm(`Remove agentpipe (${home})?`)) throw new CliError("Left as it is (--yes removes it without asking).", EXIT.usage);
|
|
12072
|
+
await rm(home, {
|
|
12073
|
+
recursive: true,
|
|
12074
|
+
force: true
|
|
12075
|
+
});
|
|
12076
|
+
ctx.out(`Removed agentpipe (${home}). Its runs and settings in ~/.agentpipe are kept.`);
|
|
12077
|
+
}
|
|
12078
|
+
/** Runs monoban's agentpipe on this terminal (`monoban agentpipe login`, `monoban agentpipe -- …`): its exit code. */
|
|
12079
|
+
async function runAgentpipe(ctx, args) {
|
|
12080
|
+
if (!await installedVersion(ctx.env)) throw new CliError("agentpipe isn't installed by monoban: monoban agentpipe install", EXIT.notFound);
|
|
12081
|
+
return new Promise((resolve) => {
|
|
12082
|
+
const child = spawn(agentpipeBin(ctx.env), args, {
|
|
12083
|
+
stdio: "inherit",
|
|
12084
|
+
env: ctx.env
|
|
12085
|
+
});
|
|
12086
|
+
child.on("error", (err) => {
|
|
12087
|
+
ctx.err(`Couldn't start agentpipe: ${err.message}`);
|
|
12088
|
+
resolve(EXIT.error);
|
|
12089
|
+
});
|
|
12090
|
+
child.on("close", (code) => resolve(code ?? EXIT.error));
|
|
12091
|
+
});
|
|
12092
|
+
}
|
|
11547
12093
|
//#endregion
|
|
11548
12094
|
//#region src/login/browser.ts
|
|
11549
12095
|
/**
|
|
@@ -12183,7 +12729,7 @@ async function projects(ctx, options) {
|
|
|
12183
12729
|
const tasks = (p) => `${p.taskCount} ${p.taskCount === 1 ? "task" : "tasks"}`;
|
|
12184
12730
|
/**
|
|
12185
12731
|
* `monoban list [COLUMN…]`: the board, by column (every column, or the ones named); `--tag` keeps a tag's
|
|
12186
|
-
* tasks. `--archived`: the archived ones instead (done a while ago,
|
|
12732
|
+
* tasks. `--archived`: the archived ones instead (done a while ago, or won't do: with why).
|
|
12187
12733
|
*/
|
|
12188
12734
|
async function list(ctx, columnQueries, options) {
|
|
12189
12735
|
const api = apis(ctx).signedIn;
|
|
@@ -12228,7 +12774,9 @@ async function list(ctx, columnQueries, options) {
|
|
|
12228
12774
|
const pad = " ".repeat(Math.max(0, titleWidth - visibleLength(title)));
|
|
12229
12775
|
ctx.out(` ${dim(t.ref.padEnd(refWidth))} ${title}${pad} ${dim(meta(t).padStart(metaWidth))}`.trimEnd());
|
|
12230
12776
|
}
|
|
12231
|
-
|
|
12777
|
+
for (const t of options.archived ? inColumn : []) if (t.archiveReason) ctx.out(dim(` ${" ".repeat(refWidth)} won't do: ${oneLine(t.archiveReason)}`));
|
|
12778
|
+
const hidden = board.archivedIn[column.id] ?? 0;
|
|
12779
|
+
if (!options.archived && hidden > 0 && options.tag === void 0) ctx.out(dim(` + ${hidden} archived (monoban list --archived)`));
|
|
12232
12780
|
}
|
|
12233
12781
|
}
|
|
12234
12782
|
/**
|
|
@@ -12286,14 +12834,16 @@ async function show(ctx, ref, options) {
|
|
|
12286
12834
|
if (options.json) return printJson$1(ctx, taskJson(task, columns, tags));
|
|
12287
12835
|
const { bold, dim } = ctx.style;
|
|
12288
12836
|
const doneId = doneColumn(columns)?.id;
|
|
12289
|
-
const archived = task.columnId === doneId && isArchived(task, doneId, (await unwrap(api.GET("/v1/projects/{key}", { params: { path: { key } } }))).project.archiveAfterDays);
|
|
12290
|
-
const
|
|
12837
|
+
const archived = Boolean(task.archivedAt) || task.columnId === doneId && isArchived(task, doneId, (await unwrap(api.GET("/v1/projects/{key}", { params: { path: { key } } }))).project.archiveAfterDays);
|
|
12838
|
+
const mark = task.archiveReason && archived ? " · won't do" : archived ? " · archived" : "";
|
|
12839
|
+
const column = `${columns.find((c) => c.id === task.columnId)?.name ?? "?"}${mark}`;
|
|
12291
12840
|
const list = checklist(task.description);
|
|
12292
12841
|
ctx.out(`${bold(task.ref)} ${bold(task.title)}`);
|
|
12293
12842
|
const when = task.scheduledOn ? ` · ${planned(task, columns)}` : "";
|
|
12294
12843
|
ctx.out(dim(`${column}${when} · created ${ago(task.createdAt)} · updated ${ago(task.updatedAt)}`));
|
|
12295
12844
|
const own = tagsOfTask(task, tags);
|
|
12296
12845
|
if (own.length) ctx.out(tagWords(own, ctx.style));
|
|
12846
|
+
if (task.archiveReason && archived) ctx.out(`Won't do: ${task.archiveReason}`);
|
|
12297
12847
|
if (list) ctx.out(dim(`Checklist ${list.done}/${list.all}`));
|
|
12298
12848
|
if (task.links.length) {
|
|
12299
12849
|
const width = Math.max(...task.links.map((l) => linkLabel(l).length));
|
|
@@ -12750,609 +13300,254 @@ async function detach(ctx, ref, which, options) {
|
|
|
12750
13300
|
ctx.out(`Removed ${linkLabel(link)} from ${task.ref}.`);
|
|
12751
13301
|
}
|
|
12752
13302
|
//#endregion
|
|
12753
|
-
//#region src/commands/
|
|
12754
|
-
|
|
12755
|
-
|
|
12756
|
-
|
|
12757
|
-
|
|
12758
|
-
|
|
12759
|
-
|
|
12760
|
-
|
|
12761
|
-
const key = await resolveProject(ctx, api, options.project);
|
|
12762
|
-
const notes = await unwrap(api.GET("/v1/projects/{key}/notes", { params: { path: { key } } }));
|
|
12763
|
-
if (options.json) return printNotes(ctx, key, notes);
|
|
12764
|
-
if (!notes.text) {
|
|
12765
|
-
ctx.err(`${key} has no notes yet. Add a line with \`monoban notes add …\`, or write them with \`monoban notes edit\`.`);
|
|
12766
|
-
return;
|
|
12767
|
-
}
|
|
12768
|
-
ctx.out(notes.text.replace(/\n$/, ""));
|
|
12769
|
-
}
|
|
12770
|
-
/** `monoban notes add TEXT…`: a line at the end of the notes (`-` reads it from stdin). */
|
|
12771
|
-
async function notesAdd(ctx, words, options) {
|
|
12772
|
-
const text = words.length === 1 && words[0] === "-" ? (await ctx.readStdin()).replace(/\n$/, "") : words.join(" ");
|
|
12773
|
-
if (!text.trim()) throw new CliError("Nothing to add: give the text, or - to read it from stdin.", EXIT.usage);
|
|
12774
|
-
const api = apis(ctx).signedIn;
|
|
12775
|
-
const key = await resolveProject(ctx, api, options.project);
|
|
12776
|
-
const notes = await unwrap(api.PATCH("/v1/projects/{key}/notes", {
|
|
12777
|
-
params: { path: { key } },
|
|
12778
|
-
body: { append: text }
|
|
12779
|
-
}));
|
|
12780
|
-
if (options.json) return printNotes(ctx, key, notes);
|
|
12781
|
-
ctx.out(`Added to the notes of ${key}.`);
|
|
13303
|
+
//#region src/commands/start.ts
|
|
13304
|
+
/** How long a branch name's words may be, after `mon-12-`. */
|
|
13305
|
+
const SLUG_LENGTH = 40;
|
|
13306
|
+
/** The branch for a task: `mon-12-import-boards-from-trello` (its ref, then its title's first words). */
|
|
13307
|
+
function branchName(ref, title) {
|
|
13308
|
+
const words = title.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
13309
|
+
const cut = words.length > SLUG_LENGTH ? words.slice(0, 41).replace(/-[^-]*$/, "") : words;
|
|
13310
|
+
return [ref.toLowerCase(), cut].filter(Boolean).join("-");
|
|
12782
13311
|
}
|
|
12783
|
-
/**
|
|
12784
|
-
|
|
12785
|
-
|
|
12786
|
-
|
|
12787
|
-
|
|
12788
|
-
const
|
|
12789
|
-
|
|
12790
|
-
|
|
12791
|
-
|
|
12792
|
-
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
|
|
13312
|
+
/**
|
|
13313
|
+
* The column where work happens: the one named In progress (or Doing, WIP…), else the one after the
|
|
13314
|
+
* first, unless that's Done. undefined when the board has none (Backlog and Done only).
|
|
13315
|
+
*/
|
|
13316
|
+
function workColumn(columns) {
|
|
13317
|
+
const names = [
|
|
13318
|
+
"in progress",
|
|
13319
|
+
"in-progress",
|
|
13320
|
+
"doing",
|
|
13321
|
+
"wip",
|
|
13322
|
+
"started",
|
|
13323
|
+
"working",
|
|
13324
|
+
"active"
|
|
13325
|
+
];
|
|
13326
|
+
const named = columns.find((c) => names.includes(c.name.trim().toLowerCase()));
|
|
13327
|
+
if (named) return named;
|
|
13328
|
+
const second = columns[1];
|
|
13329
|
+
return second && second !== doneColumn(columns) ? second : void 0;
|
|
13330
|
+
}
|
|
13331
|
+
/**
|
|
13332
|
+
* Moves a task to the column where work happens, unless it's there or further on. Answers it, and what
|
|
13333
|
+
* happened in words ("Moved MON-12 from Backlog to In progress.").
|
|
13334
|
+
*/
|
|
13335
|
+
async function moveToWork(api, task, columns) {
|
|
13336
|
+
const target = workColumn(columns);
|
|
13337
|
+
const at = (t) => columns.findIndex((c) => c.id === t.columnId);
|
|
13338
|
+
const here = columns[at(task)];
|
|
13339
|
+
if (!target) return {
|
|
13340
|
+
task,
|
|
13341
|
+
moved: false,
|
|
13342
|
+
line: `${task.ref} stays in ${here?.name ?? "its column"}: the board has no In progress column.`
|
|
13343
|
+
};
|
|
13344
|
+
if (at(task) >= columns.indexOf(target)) return {
|
|
13345
|
+
task,
|
|
13346
|
+
moved: false,
|
|
13347
|
+
line: `${task.ref} is in ${here?.name ?? "its column"} already.`
|
|
13348
|
+
};
|
|
13349
|
+
const { key, number } = taskRefOf(task.ref);
|
|
13350
|
+
return {
|
|
13351
|
+
task: await unwrap(api.PATCH("/v1/projects/{key}/tasks/{number}", {
|
|
12796
13352
|
params: {
|
|
12797
|
-
path: {
|
|
12798
|
-
|
|
13353
|
+
path: {
|
|
13354
|
+
key,
|
|
13355
|
+
number
|
|
13356
|
+
},
|
|
13357
|
+
header: ifMatch(task.version)
|
|
12799
13358
|
},
|
|
12800
|
-
body: {
|
|
12801
|
-
}))
|
|
12802
|
-
|
|
12803
|
-
|
|
12804
|
-
|
|
12805
|
-
if (err instanceof ApiProblem && err.status === 412) throw new CliError(`The notes of ${key} changed elsewhere in the meantime. Run \`monoban notes edit\` again.`);
|
|
12806
|
-
throw err;
|
|
12807
|
-
}
|
|
12808
|
-
if (options.json) return printNotes(ctx, key, saved);
|
|
12809
|
-
ctx.out(`Updated the notes of ${key}.`);
|
|
13359
|
+
body: { columnId: target.id }
|
|
13360
|
+
})).catch((err) => changedElsewhere(err, task.ref)),
|
|
13361
|
+
moved: true,
|
|
13362
|
+
line: `Moved ${task.ref}${here ? ` from ${here.name}` : ""} to ${target.name}.`
|
|
13363
|
+
};
|
|
12810
13364
|
}
|
|
12811
|
-
//#endregion
|
|
12812
|
-
//#region src/runner/agents/agentpipe.ts
|
|
12813
|
-
/** agentpipe's step statuses that monoban has too; the others (budget_exceeded, max_turns…) are failures. */
|
|
12814
|
-
const SAME = [
|
|
12815
|
-
"ok",
|
|
12816
|
-
"failed",
|
|
12817
|
-
"skipped",
|
|
12818
|
-
"cancelled",
|
|
12819
|
-
"needs_human"
|
|
12820
|
-
];
|
|
12821
|
-
const RUN_ENDINGS = {
|
|
12822
|
-
ok: "succeeded",
|
|
12823
|
-
needs_human: "needs_human",
|
|
12824
|
-
cancelled: "cancelled"
|
|
12825
|
-
};
|
|
12826
|
-
const str = (v) => typeof v === "string" && v.trim() ? v.trim() : null;
|
|
12827
|
-
const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : null;
|
|
12828
|
-
/** A message the API takes: one line or more, at most 2000 characters. */
|
|
12829
|
-
const clip$1 = (text) => text.length > 2e3 ? `${text.slice(0, 1999)}…` : text;
|
|
12830
13365
|
/**
|
|
12831
|
-
*
|
|
12832
|
-
*
|
|
12833
|
-
*
|
|
12834
|
-
* starts, or the run ends, if it never does).
|
|
13366
|
+
* `monoban start MON-12`: work on a task. Checks out its branch (`mon-12-title`: made from the commit
|
|
13367
|
+
* you're on, or the one already there) and moves it to In progress, unless it's there or further on.
|
|
13368
|
+
* --no-branch and --no-move do half of it.
|
|
12835
13369
|
*/
|
|
12836
|
-
function
|
|
12837
|
-
const
|
|
12838
|
-
|
|
12839
|
-
|
|
12840
|
-
|
|
12841
|
-
|
|
12842
|
-
|
|
12843
|
-
|
|
12844
|
-
|
|
12845
|
-
|
|
12846
|
-
const
|
|
12847
|
-
if (
|
|
12848
|
-
|
|
12849
|
-
|
|
12850
|
-
|
|
12851
|
-
|
|
12852
|
-
|
|
12853
|
-
|
|
12854
|
-
|
|
12855
|
-
|
|
12856
|
-
|
|
12857
|
-
|
|
12858
|
-
|
|
12859
|
-
|
|
12860
|
-
|
|
12861
|
-
|
|
12862
|
-
|
|
12863
|
-
|
|
12864
|
-
|
|
12865
|
-
|
|
12866
|
-
|
|
13370
|
+
async function start(ctx, ref, options) {
|
|
13371
|
+
const api = apis(ctx).signedIn;
|
|
13372
|
+
let task = await taskByRef(api, ref, ctx);
|
|
13373
|
+
const { key } = taskRefOf(task.ref);
|
|
13374
|
+
const columns = await columnsOf(api, key);
|
|
13375
|
+
const lines = [];
|
|
13376
|
+
let branch = null;
|
|
13377
|
+
if (options.branch !== false) {
|
|
13378
|
+
if (!await ctx.clone.inClone()) throw new CliError("Not in a git clone, so there's no branch to make. Run it in the repository, or with --no-branch.", EXIT.usage);
|
|
13379
|
+
const current = await ctx.clone.branch();
|
|
13380
|
+
const own = (name) => taskOfBranch(name) === task.ref;
|
|
13381
|
+
if (own(current)) {
|
|
13382
|
+
branch = current;
|
|
13383
|
+
lines.push(`Already on ${branch}.`);
|
|
13384
|
+
} else {
|
|
13385
|
+
const existing = (await ctx.clone.branches()).find(own);
|
|
13386
|
+
branch = existing ?? branchName(task.ref, task.title);
|
|
13387
|
+
const why = await ctx.clone.switchTo(branch, !existing);
|
|
13388
|
+
if (why) throw new CliError(`git couldn't switch to ${branch}: ${why}`);
|
|
13389
|
+
lines.push(existing ? `Switched to ${branch}.` : `Switched to a new branch ${branch}.`);
|
|
13390
|
+
}
|
|
13391
|
+
}
|
|
13392
|
+
if (options.move !== false) {
|
|
13393
|
+
const moved = await moveToWork(api, task, columns);
|
|
13394
|
+
task = moved.task;
|
|
13395
|
+
lines.push(moved.line);
|
|
13396
|
+
}
|
|
13397
|
+
if (options.json) {
|
|
13398
|
+
const json = {
|
|
13399
|
+
...taskJson(task, columns, await tagsFor(api, key, task)),
|
|
13400
|
+
branch
|
|
12867
13401
|
};
|
|
13402
|
+
return ctx.out(JSON.stringify(json, null, 2));
|
|
13403
|
+
}
|
|
13404
|
+
for (const line of lines) ctx.out(line);
|
|
13405
|
+
}
|
|
13406
|
+
//#endregion
|
|
13407
|
+
//#region src/runner/process.ts
|
|
13408
|
+
const defaultSpawn = spawn;
|
|
13409
|
+
const TAIL$1 = 20;
|
|
13410
|
+
function startProcess({ command, args, cwd, env, stdin, onLine, spawn = defaultSpawn, graceMs = 1e4 }) {
|
|
13411
|
+
let child;
|
|
13412
|
+
let exited = false;
|
|
13413
|
+
const timers = [];
|
|
13414
|
+
const signal = (sig) => {
|
|
13415
|
+
if (!child || exited) return;
|
|
13416
|
+
try {
|
|
13417
|
+
if (child.pid) process.kill(-child.pid, sig);
|
|
13418
|
+
else child.kill(sig);
|
|
13419
|
+
} catch {
|
|
13420
|
+
child.kill(sig);
|
|
13421
|
+
}
|
|
12868
13422
|
};
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
|
|
12874
|
-
|
|
12875
|
-
|
|
12876
|
-
const id = str(d.run_id) ?? str(e.run_id);
|
|
12877
|
-
if (id) report.update({ externalId: id });
|
|
12878
|
-
return;
|
|
12879
|
-
}
|
|
12880
|
-
case "step.start": {
|
|
12881
|
-
if (!step) return;
|
|
12882
|
-
const attempt = num(d.attempt) ?? attempts.get(step) ?? 1;
|
|
12883
|
-
const key = `${step}@${attempt}`;
|
|
12884
|
-
if (started.has(key)) return;
|
|
12885
|
-
if (pending && pending.step !== step) flush();
|
|
12886
|
-
started.add(key);
|
|
12887
|
-
attempts.set(step, attempt);
|
|
12888
|
-
report.event({
|
|
12889
|
-
kind: "step_started",
|
|
12890
|
-
step,
|
|
12891
|
-
attempt,
|
|
12892
|
-
status: "running",
|
|
12893
|
-
...at && { at }
|
|
13423
|
+
return {
|
|
13424
|
+
done: new Promise((resolve) => {
|
|
13425
|
+
try {
|
|
13426
|
+
child = spawn(command, args, {
|
|
13427
|
+
cwd,
|
|
13428
|
+
env,
|
|
13429
|
+
detached: true
|
|
12894
13430
|
});
|
|
12895
|
-
|
|
12896
|
-
|
|
12897
|
-
|
|
12898
|
-
|
|
12899
|
-
|
|
12900
|
-
const { status, note } = stepStatus(d.status);
|
|
12901
|
-
const reason = str(d.reason) ?? str(d.error) ?? note;
|
|
12902
|
-
const costShaped = "turns" in d || "cost_usd" in d;
|
|
12903
|
-
if (!pending || pending.step !== step) {
|
|
12904
|
-
flush();
|
|
12905
|
-
pending = {
|
|
12906
|
-
step,
|
|
12907
|
-
attempt,
|
|
12908
|
-
status,
|
|
12909
|
-
message: reason,
|
|
12910
|
-
...at && { at }
|
|
12911
|
-
};
|
|
12912
|
-
} else {
|
|
12913
|
-
if (pending.status === "ok" && status !== "ok") pending.status = status;
|
|
12914
|
-
pending.message = pending.message ?? reason;
|
|
12915
|
-
if (at) pending.at = at;
|
|
12916
|
-
}
|
|
12917
|
-
if (costShaped) {
|
|
12918
|
-
const costUsd = num(d.cost_usd);
|
|
12919
|
-
if (costUsd) {
|
|
12920
|
-
total += costUsd;
|
|
12921
|
-
report.update({ costUsd: Math.round(total * 1e4) / 1e4 });
|
|
12922
|
-
}
|
|
12923
|
-
flush({
|
|
12924
|
-
durationMs: num(d.duration_ms),
|
|
12925
|
-
costUsd
|
|
12926
|
-
});
|
|
12927
|
-
}
|
|
12928
|
-
return;
|
|
12929
|
-
}
|
|
12930
|
-
case "pr.created": {
|
|
12931
|
-
const url = str(d.url);
|
|
12932
|
-
if (!url) return;
|
|
12933
|
-
report.update({ prUrl: url });
|
|
12934
|
-
report.event({
|
|
12935
|
-
kind: "pr_opened",
|
|
12936
|
-
...step && { step },
|
|
12937
|
-
message: url,
|
|
12938
|
-
data: {
|
|
12939
|
-
url,
|
|
12940
|
-
...num(d.number) !== null && { number: num(d.number) }
|
|
12941
|
-
},
|
|
12942
|
-
...at && { at }
|
|
13431
|
+
} catch (err) {
|
|
13432
|
+
resolve({
|
|
13433
|
+
code: null,
|
|
13434
|
+
spawnError: `Couldn't start ${command}: ${err.message}`,
|
|
13435
|
+
lastError: null
|
|
12943
13436
|
});
|
|
12944
13437
|
return;
|
|
12945
13438
|
}
|
|
12946
|
-
|
|
12947
|
-
|
|
12948
|
-
|
|
12949
|
-
|
|
12950
|
-
|
|
12951
|
-
|
|
12952
|
-
});
|
|
12953
|
-
|
|
12954
|
-
}
|
|
12955
|
-
case "issue.comment": {
|
|
12956
|
-
const milestone = str(d.milestone);
|
|
12957
|
-
report.event({
|
|
12958
|
-
kind: "board",
|
|
12959
|
-
message: milestone ? `commented: ${milestone}` : "commented",
|
|
12960
|
-
...at && { at }
|
|
12961
|
-
});
|
|
12962
|
-
return;
|
|
12963
|
-
}
|
|
12964
|
-
case "question.asked":
|
|
12965
|
-
case "escalation": {
|
|
12966
|
-
const text = str(d.question) ?? str(d.text) ?? str(d.message) ?? str(d.reason) ?? "It needs an answer.";
|
|
12967
|
-
report.event({
|
|
12968
|
-
kind: "question",
|
|
12969
|
-
...step && { step },
|
|
12970
|
-
message: clip$1(text),
|
|
12971
|
-
...at && { at }
|
|
12972
|
-
});
|
|
12973
|
-
return;
|
|
12974
|
-
}
|
|
12975
|
-
case "error": {
|
|
12976
|
-
const text = str(d.message) ?? str(d.kind) ?? "Something went wrong.";
|
|
12977
|
-
report.event({
|
|
12978
|
-
kind: "warning",
|
|
12979
|
-
...step && { step },
|
|
12980
|
-
message: clip$1(text),
|
|
12981
|
-
...at && { at }
|
|
12982
|
-
});
|
|
12983
|
-
return;
|
|
13439
|
+
let spawnError = null;
|
|
13440
|
+
const tail = [];
|
|
13441
|
+
child.on("error", (err) => {
|
|
13442
|
+
spawnError = err.code === "ENOENT" ? `${command} isn't installed here (or isn't on the runner's PATH).` : `${command} failed: ${err.message}`;
|
|
13443
|
+
});
|
|
13444
|
+
if (child.stdin) {
|
|
13445
|
+
child.stdin.on("error", () => {});
|
|
13446
|
+
child.stdin.end(stdin ?? "");
|
|
12984
13447
|
}
|
|
12985
|
-
|
|
12986
|
-
|
|
12987
|
-
|
|
12988
|
-
|
|
12989
|
-
|
|
12990
|
-
|
|
12991
|
-
|
|
12992
|
-
|
|
12993
|
-
|
|
12994
|
-
|
|
12995
|
-
|
|
13448
|
+
if (child.stdout) createInterface$1({ input: child.stdout }).on("line", onLine);
|
|
13449
|
+
if (child.stderr) createInterface$1({ input: child.stderr }).on("line", (line) => {
|
|
13450
|
+
if (!line.trim()) return;
|
|
13451
|
+
tail.push(line.trim());
|
|
13452
|
+
if (tail.length > TAIL$1) tail.shift();
|
|
13453
|
+
});
|
|
13454
|
+
child.on("close", (code) => {
|
|
13455
|
+
exited = true;
|
|
13456
|
+
for (const t of timers) clearTimeout(t);
|
|
13457
|
+
resolve({
|
|
13458
|
+
code,
|
|
13459
|
+
spawnError,
|
|
13460
|
+
lastError: tail.at(-1) ?? null
|
|
12996
13461
|
});
|
|
12997
|
-
|
|
12998
|
-
|
|
13462
|
+
});
|
|
13463
|
+
}),
|
|
13464
|
+
stop: () => {
|
|
13465
|
+
signal("SIGINT");
|
|
13466
|
+
timers.push(setTimeout(() => signal("SIGTERM"), graceMs));
|
|
13467
|
+
timers.push(setTimeout(() => signal("SIGKILL"), graceMs * 2));
|
|
12999
13468
|
}
|
|
13000
13469
|
};
|
|
13001
|
-
return {
|
|
13002
|
-
take,
|
|
13003
|
-
/** How agentpipe said the run ended (null: it didn't). */
|
|
13004
|
-
ending: () => ending,
|
|
13005
|
-
flush: () => flush()
|
|
13006
|
-
};
|
|
13007
13470
|
}
|
|
13008
|
-
/**
|
|
13009
|
-
function
|
|
13010
|
-
|
|
13011
|
-
|
|
13012
|
-
|
|
13013
|
-
|
|
13014
|
-
|
|
13015
|
-
|
|
13016
|
-
|
|
13471
|
+
/** The first version number a command prints for `--version` ("2.1.300 (Claude Code)" → 2.1.300), or null. */
|
|
13472
|
+
function versionOf(command, env = process.env) {
|
|
13473
|
+
return new Promise((resolve) => {
|
|
13474
|
+
execFile(command, ["--version"], {
|
|
13475
|
+
timeout: 15e3,
|
|
13476
|
+
env
|
|
13477
|
+
}, (err, stdout, stderr) => {
|
|
13478
|
+
if (err) return resolve(null);
|
|
13479
|
+
resolve(/\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?/.exec(`${stdout} ${stderr}`)?.[0] ?? null);
|
|
13480
|
+
});
|
|
13481
|
+
});
|
|
13017
13482
|
}
|
|
13018
|
-
/**
|
|
13019
|
-
function
|
|
13020
|
-
|
|
13021
|
-
|
|
13022
|
-
|
|
13023
|
-
|
|
13024
|
-
|
|
13025
|
-
|
|
13026
|
-
|
|
13027
|
-
...options.budgetUsd !== void 0 ? ["--budget", String(options.budgetUsd)] : [],
|
|
13028
|
-
...options.autonomous ? ["--autonomous"] : []
|
|
13029
|
-
];
|
|
13483
|
+
/** Whether version `a` is at least `b` (numbers only: 2.1.259). */
|
|
13484
|
+
function atLeast(a, b) {
|
|
13485
|
+
const parts = (v) => v.split(/[-+]/)[0]?.split(".").map(Number) ?? [];
|
|
13486
|
+
const [x, y] = [parts(a), parts(b)];
|
|
13487
|
+
for (let i = 0; i < Math.max(x.length, y.length); i++) {
|
|
13488
|
+
const d = (x[i] ?? 0) - (y[i] ?? 0);
|
|
13489
|
+
if (d) return d > 0;
|
|
13490
|
+
}
|
|
13491
|
+
return true;
|
|
13030
13492
|
}
|
|
13031
|
-
|
|
13032
|
-
|
|
13033
|
-
|
|
13034
|
-
|
|
13035
|
-
|
|
13036
|
-
|
|
13037
|
-
|
|
13038
|
-
|
|
13039
|
-
|
|
13040
|
-
|
|
13041
|
-
|
|
13042
|
-
|
|
13043
|
-
|
|
13044
|
-
|
|
13045
|
-
|
|
13046
|
-
|
|
13047
|
-
|
|
13048
|
-
|
|
13049
|
-
|
|
13050
|
-
|
|
13051
|
-
|
|
13052
|
-
|
|
13053
|
-
|
|
13054
|
-
|
|
13055
|
-
|
|
13056
|
-
|
|
13057
|
-
|
|
13058
|
-
|
|
13059
|
-
|
|
13060
|
-
resolve({
|
|
13061
|
-
status: "failed",
|
|
13062
|
-
reason: `Couldn't start ${command}: ${err.message}`
|
|
13063
|
-
});
|
|
13064
|
-
return;
|
|
13065
|
-
}
|
|
13066
|
-
let spawnError = null;
|
|
13067
|
-
child.on("error", (err) => {
|
|
13068
|
-
spawnError = err.code === "ENOENT" ? `${command} isn't installed here (or isn't on the runner's PATH).` : `${command} failed: ${err.message}`;
|
|
13069
|
-
});
|
|
13070
|
-
if (child.stdout) createInterface$1({ input: child.stdout }).on("line", (line) => {
|
|
13071
|
-
const event = parseLine(line);
|
|
13072
|
-
if (event) feed.take(event);
|
|
13073
|
-
});
|
|
13074
|
-
if (child.stderr) createInterface$1({ input: child.stderr }).on("line", (line) => {
|
|
13075
|
-
if (!line.trim()) return;
|
|
13076
|
-
tail.push(line.trim());
|
|
13077
|
-
if (tail.length > TAIL$1) tail.shift();
|
|
13078
|
-
});
|
|
13079
|
-
child.on("close", (code) => {
|
|
13080
|
-
feed.flush();
|
|
13081
|
-
const said = feed.ending();
|
|
13082
|
-
if (said) return resolve(said);
|
|
13083
|
-
if (spawnError) return resolve({
|
|
13084
|
-
status: "failed",
|
|
13085
|
-
reason: spawnError
|
|
13086
|
-
});
|
|
13087
|
-
const last = tail.at(-1);
|
|
13088
|
-
resolve({
|
|
13089
|
-
status: "failed",
|
|
13090
|
-
reason: `${command} stopped (exit code ${code ?? "none"}) without saying how it ended${last ? `: ${last}` : "."}`
|
|
13091
|
-
});
|
|
13092
|
-
});
|
|
13093
|
-
}),
|
|
13094
|
-
cancel: async () => {
|
|
13095
|
-
if (externalId) await execCommand(command, [
|
|
13096
|
-
"cancel",
|
|
13097
|
-
externalId,
|
|
13098
|
-
"--reason",
|
|
13099
|
-
"Cancelled from monoban"
|
|
13100
|
-
], env);
|
|
13101
|
-
else child?.kill("SIGINT");
|
|
13102
|
-
}
|
|
13103
|
-
};
|
|
13493
|
+
//#endregion
|
|
13494
|
+
//#region src/runner/prompt.ts
|
|
13495
|
+
/** The JSON Schema the agent's last message follows (strict, as Codex's --output-schema needs). */
|
|
13496
|
+
const OUTCOME_SCHEMA = {
|
|
13497
|
+
type: "object",
|
|
13498
|
+
additionalProperties: false,
|
|
13499
|
+
required: [
|
|
13500
|
+
"status",
|
|
13501
|
+
"summary",
|
|
13502
|
+
"prTitle",
|
|
13503
|
+
"question"
|
|
13504
|
+
],
|
|
13505
|
+
properties: {
|
|
13506
|
+
status: {
|
|
13507
|
+
type: "string",
|
|
13508
|
+
enum: ["done", "blocked"],
|
|
13509
|
+
description: "done: the task is done; blocked: it can't go on without an answer"
|
|
13510
|
+
},
|
|
13511
|
+
summary: {
|
|
13512
|
+
type: "string",
|
|
13513
|
+
description: "What you changed and how you checked it, in a few sentences of Markdown"
|
|
13514
|
+
},
|
|
13515
|
+
prTitle: {
|
|
13516
|
+
type: "string",
|
|
13517
|
+
description: "A pull request title, under 70 characters"
|
|
13518
|
+
},
|
|
13519
|
+
question: {
|
|
13520
|
+
type: "string",
|
|
13521
|
+
description: "When blocked, what you need to know; otherwise empty"
|
|
13104
13522
|
}
|
|
13105
|
-
}
|
|
13106
|
-
}
|
|
13107
|
-
|
|
13108
|
-
|
|
13109
|
-
|
|
13110
|
-
|
|
13111
|
-
|
|
13112
|
-
|
|
13113
|
-
|
|
13114
|
-
|
|
13115
|
-
|
|
13116
|
-
|
|
13117
|
-
|
|
13118
|
-
|
|
13119
|
-
|
|
13120
|
-
|
|
13121
|
-
|
|
13122
|
-
|
|
13123
|
-
|
|
13124
|
-
|
|
13125
|
-
|
|
13126
|
-
|
|
13127
|
-
|
|
13128
|
-
|
|
13129
|
-
|
|
13130
|
-
|
|
13131
|
-
|
|
13132
|
-
|
|
13133
|
-
const second = columns[1];
|
|
13134
|
-
return second && second !== doneColumn(columns) ? second : void 0;
|
|
13135
|
-
}
|
|
13136
|
-
/**
|
|
13137
|
-
* Moves a task to the column where work happens, unless it's there or further on. Answers it, and what
|
|
13138
|
-
* happened in words ("Moved MON-12 from Backlog to In progress.").
|
|
13139
|
-
*/
|
|
13140
|
-
async function moveToWork(api, task, columns) {
|
|
13141
|
-
const target = workColumn(columns);
|
|
13142
|
-
const at = (t) => columns.findIndex((c) => c.id === t.columnId);
|
|
13143
|
-
const here = columns[at(task)];
|
|
13144
|
-
if (!target) return {
|
|
13145
|
-
task,
|
|
13146
|
-
moved: false,
|
|
13147
|
-
line: `${task.ref} stays in ${here?.name ?? "its column"}: the board has no In progress column.`
|
|
13148
|
-
};
|
|
13149
|
-
if (at(task) >= columns.indexOf(target)) return {
|
|
13150
|
-
task,
|
|
13151
|
-
moved: false,
|
|
13152
|
-
line: `${task.ref} is in ${here?.name ?? "its column"} already.`
|
|
13153
|
-
};
|
|
13154
|
-
const { key, number } = taskRefOf(task.ref);
|
|
13155
|
-
return {
|
|
13156
|
-
task: await unwrap(api.PATCH("/v1/projects/{key}/tasks/{number}", {
|
|
13157
|
-
params: {
|
|
13158
|
-
path: {
|
|
13159
|
-
key,
|
|
13160
|
-
number
|
|
13161
|
-
},
|
|
13162
|
-
header: ifMatch(task.version)
|
|
13163
|
-
},
|
|
13164
|
-
body: { columnId: target.id }
|
|
13165
|
-
})).catch((err) => changedElsewhere(err, task.ref)),
|
|
13166
|
-
moved: true,
|
|
13167
|
-
line: `Moved ${task.ref}${here ? ` from ${here.name}` : ""} to ${target.name}.`
|
|
13168
|
-
};
|
|
13169
|
-
}
|
|
13170
|
-
/**
|
|
13171
|
-
* `monoban start MON-12`: work on a task. Checks out its branch (`mon-12-title`: made from the commit
|
|
13172
|
-
* you're on, or the one already there) and moves it to In progress, unless it's there or further on.
|
|
13173
|
-
* --no-branch and --no-move do half of it.
|
|
13174
|
-
*/
|
|
13175
|
-
async function start(ctx, ref, options) {
|
|
13176
|
-
const api = apis(ctx).signedIn;
|
|
13177
|
-
let task = await taskByRef(api, ref, ctx);
|
|
13178
|
-
const { key } = taskRefOf(task.ref);
|
|
13179
|
-
const columns = await columnsOf(api, key);
|
|
13180
|
-
const lines = [];
|
|
13181
|
-
let branch = null;
|
|
13182
|
-
if (options.branch !== false) {
|
|
13183
|
-
if (!await ctx.clone.inClone()) throw new CliError("Not in a git clone, so there's no branch to make. Run it in the repository, or with --no-branch.", EXIT.usage);
|
|
13184
|
-
const current = await ctx.clone.branch();
|
|
13185
|
-
const own = (name) => taskOfBranch(name) === task.ref;
|
|
13186
|
-
if (own(current)) {
|
|
13187
|
-
branch = current;
|
|
13188
|
-
lines.push(`Already on ${branch}.`);
|
|
13189
|
-
} else {
|
|
13190
|
-
const existing = (await ctx.clone.branches()).find(own);
|
|
13191
|
-
branch = existing ?? branchName(task.ref, task.title);
|
|
13192
|
-
const why = await ctx.clone.switchTo(branch, !existing);
|
|
13193
|
-
if (why) throw new CliError(`git couldn't switch to ${branch}: ${why}`);
|
|
13194
|
-
lines.push(existing ? `Switched to ${branch}.` : `Switched to a new branch ${branch}.`);
|
|
13195
|
-
}
|
|
13196
|
-
}
|
|
13197
|
-
if (options.move !== false) {
|
|
13198
|
-
const moved = await moveToWork(api, task, columns);
|
|
13199
|
-
task = moved.task;
|
|
13200
|
-
lines.push(moved.line);
|
|
13201
|
-
}
|
|
13202
|
-
if (options.json) {
|
|
13203
|
-
const json = {
|
|
13204
|
-
...taskJson(task, columns, await tagsFor(api, key, task)),
|
|
13205
|
-
branch
|
|
13206
|
-
};
|
|
13207
|
-
return ctx.out(JSON.stringify(json, null, 2));
|
|
13208
|
-
}
|
|
13209
|
-
for (const line of lines) ctx.out(line);
|
|
13210
|
-
}
|
|
13211
|
-
//#endregion
|
|
13212
|
-
//#region src/runner/process.ts
|
|
13213
|
-
const defaultSpawn = spawn;
|
|
13214
|
-
const TAIL = 20;
|
|
13215
|
-
function startProcess({ command, args, cwd, env, stdin, onLine, spawn = defaultSpawn, graceMs = 1e4 }) {
|
|
13216
|
-
let child;
|
|
13217
|
-
let exited = false;
|
|
13218
|
-
const timers = [];
|
|
13219
|
-
const signal = (sig) => {
|
|
13220
|
-
if (!child || exited) return;
|
|
13221
|
-
try {
|
|
13222
|
-
if (child.pid) process.kill(-child.pid, sig);
|
|
13223
|
-
else child.kill(sig);
|
|
13224
|
-
} catch {
|
|
13225
|
-
child.kill(sig);
|
|
13226
|
-
}
|
|
13227
|
-
};
|
|
13228
|
-
return {
|
|
13229
|
-
done: new Promise((resolve) => {
|
|
13230
|
-
try {
|
|
13231
|
-
child = spawn(command, args, {
|
|
13232
|
-
cwd,
|
|
13233
|
-
env,
|
|
13234
|
-
detached: true
|
|
13235
|
-
});
|
|
13236
|
-
} catch (err) {
|
|
13237
|
-
resolve({
|
|
13238
|
-
code: null,
|
|
13239
|
-
spawnError: `Couldn't start ${command}: ${err.message}`,
|
|
13240
|
-
lastError: null
|
|
13241
|
-
});
|
|
13242
|
-
return;
|
|
13243
|
-
}
|
|
13244
|
-
let spawnError = null;
|
|
13245
|
-
const tail = [];
|
|
13246
|
-
child.on("error", (err) => {
|
|
13247
|
-
spawnError = err.code === "ENOENT" ? `${command} isn't installed here (or isn't on the runner's PATH).` : `${command} failed: ${err.message}`;
|
|
13248
|
-
});
|
|
13249
|
-
if (child.stdin) {
|
|
13250
|
-
child.stdin.on("error", () => {});
|
|
13251
|
-
child.stdin.end(stdin ?? "");
|
|
13252
|
-
}
|
|
13253
|
-
if (child.stdout) createInterface$1({ input: child.stdout }).on("line", onLine);
|
|
13254
|
-
if (child.stderr) createInterface$1({ input: child.stderr }).on("line", (line) => {
|
|
13255
|
-
if (!line.trim()) return;
|
|
13256
|
-
tail.push(line.trim());
|
|
13257
|
-
if (tail.length > TAIL) tail.shift();
|
|
13258
|
-
});
|
|
13259
|
-
child.on("close", (code) => {
|
|
13260
|
-
exited = true;
|
|
13261
|
-
for (const t of timers) clearTimeout(t);
|
|
13262
|
-
resolve({
|
|
13263
|
-
code,
|
|
13264
|
-
spawnError,
|
|
13265
|
-
lastError: tail.at(-1) ?? null
|
|
13266
|
-
});
|
|
13267
|
-
});
|
|
13268
|
-
}),
|
|
13269
|
-
stop: () => {
|
|
13270
|
-
signal("SIGINT");
|
|
13271
|
-
timers.push(setTimeout(() => signal("SIGTERM"), graceMs));
|
|
13272
|
-
timers.push(setTimeout(() => signal("SIGKILL"), graceMs * 2));
|
|
13273
|
-
}
|
|
13274
|
-
};
|
|
13275
|
-
}
|
|
13276
|
-
/** The first version number a command prints for `--version` ("2.1.300 (Claude Code)" → 2.1.300), or null. */
|
|
13277
|
-
function versionOf(command, env = process.env) {
|
|
13278
|
-
return new Promise((resolve) => {
|
|
13279
|
-
execFile(command, ["--version"], {
|
|
13280
|
-
timeout: 15e3,
|
|
13281
|
-
env
|
|
13282
|
-
}, (err, stdout, stderr) => {
|
|
13283
|
-
if (err) return resolve(null);
|
|
13284
|
-
resolve(/\d+\.\d+(?:\.\d+)?(?:[-+][0-9A-Za-z.-]+)?/.exec(`${stdout} ${stderr}`)?.[0] ?? null);
|
|
13285
|
-
});
|
|
13286
|
-
});
|
|
13287
|
-
}
|
|
13288
|
-
/** Whether version `a` is at least `b` (numbers only: 2.1.259). */
|
|
13289
|
-
function atLeast(a, b) {
|
|
13290
|
-
const parts = (v) => v.split(/[-+]/)[0]?.split(".").map(Number) ?? [];
|
|
13291
|
-
const [x, y] = [parts(a), parts(b)];
|
|
13292
|
-
for (let i = 0; i < Math.max(x.length, y.length); i++) {
|
|
13293
|
-
const d = (x[i] ?? 0) - (y[i] ?? 0);
|
|
13294
|
-
if (d) return d > 0;
|
|
13295
|
-
}
|
|
13296
|
-
return true;
|
|
13297
|
-
}
|
|
13298
|
-
//#endregion
|
|
13299
|
-
//#region src/runner/prompt.ts
|
|
13300
|
-
/** The JSON Schema the agent's last message follows (strict, as Codex's --output-schema needs). */
|
|
13301
|
-
const OUTCOME_SCHEMA = {
|
|
13302
|
-
type: "object",
|
|
13303
|
-
additionalProperties: false,
|
|
13304
|
-
required: [
|
|
13305
|
-
"status",
|
|
13306
|
-
"summary",
|
|
13307
|
-
"prTitle",
|
|
13308
|
-
"question"
|
|
13309
|
-
],
|
|
13310
|
-
properties: {
|
|
13311
|
-
status: {
|
|
13312
|
-
type: "string",
|
|
13313
|
-
enum: ["done", "blocked"],
|
|
13314
|
-
description: "done: the task is done; blocked: it can't go on without an answer"
|
|
13315
|
-
},
|
|
13316
|
-
summary: {
|
|
13317
|
-
type: "string",
|
|
13318
|
-
description: "What you changed and how you checked it, in a few sentences of Markdown"
|
|
13319
|
-
},
|
|
13320
|
-
prTitle: {
|
|
13321
|
-
type: "string",
|
|
13322
|
-
description: "A pull request title, under 70 characters"
|
|
13323
|
-
},
|
|
13324
|
-
question: {
|
|
13325
|
-
type: "string",
|
|
13326
|
-
description: "When blocked, what you need to know; otherwise empty"
|
|
13327
|
-
}
|
|
13328
|
-
}
|
|
13329
|
-
};
|
|
13330
|
-
/** The outcome in an agent's answer: the JSON itself, or the last JSON object in its text. */
|
|
13331
|
-
function parseOutcome(value) {
|
|
13332
|
-
let v = value;
|
|
13333
|
-
if (typeof v === "string") {
|
|
13334
|
-
const text = v.trim();
|
|
13335
|
-
const candidates = [text, ...[...text.matchAll(/```(?:json)?\s*([\s\S]*?)```/g)].map((m) => m[1] ?? "")];
|
|
13336
|
-
const open = text.lastIndexOf("{", text.lastIndexOf("\"status\""));
|
|
13337
|
-
if (open >= 0) candidates.push(text.slice(open, text.lastIndexOf("}") + 1));
|
|
13338
|
-
v = null;
|
|
13339
|
-
for (const c of candidates.reverse()) try {
|
|
13340
|
-
const parsed = JSON.parse(c);
|
|
13341
|
-
if (parsed && typeof parsed === "object") {
|
|
13342
|
-
v = parsed;
|
|
13343
|
-
break;
|
|
13344
|
-
}
|
|
13345
|
-
} catch {}
|
|
13346
|
-
}
|
|
13347
|
-
if (!v || typeof v !== "object") return null;
|
|
13348
|
-
const o = v;
|
|
13349
|
-
if (o.status !== "done" && o.status !== "blocked") return null;
|
|
13350
|
-
const str = (x) => typeof x === "string" ? x.trim() : "";
|
|
13351
|
-
return {
|
|
13352
|
-
status: o.status,
|
|
13353
|
-
summary: str(o.summary),
|
|
13354
|
-
prTitle: str(o.prTitle),
|
|
13355
|
-
question: str(o.question)
|
|
13523
|
+
}
|
|
13524
|
+
};
|
|
13525
|
+
/** The outcome in an agent's answer: the JSON itself, or the last JSON object in its text. */
|
|
13526
|
+
function parseOutcome(value) {
|
|
13527
|
+
let v = value;
|
|
13528
|
+
if (typeof v === "string") {
|
|
13529
|
+
const text = v.trim();
|
|
13530
|
+
const candidates = [text, ...[...text.matchAll(/```(?:json)?\s*([\s\S]*?)```/g)].map((m) => m[1] ?? "")];
|
|
13531
|
+
const open = text.lastIndexOf("{", text.lastIndexOf("\"status\""));
|
|
13532
|
+
if (open >= 0) candidates.push(text.slice(open, text.lastIndexOf("}") + 1));
|
|
13533
|
+
v = null;
|
|
13534
|
+
for (const c of candidates.reverse()) try {
|
|
13535
|
+
const parsed = JSON.parse(c);
|
|
13536
|
+
if (parsed && typeof parsed === "object") {
|
|
13537
|
+
v = parsed;
|
|
13538
|
+
break;
|
|
13539
|
+
}
|
|
13540
|
+
} catch {}
|
|
13541
|
+
}
|
|
13542
|
+
if (!v || typeof v !== "object") return null;
|
|
13543
|
+
const o = v;
|
|
13544
|
+
if (o.status !== "done" && o.status !== "blocked") return null;
|
|
13545
|
+
const str = (x) => typeof x === "string" ? x.trim() : "";
|
|
13546
|
+
return {
|
|
13547
|
+
status: o.status,
|
|
13548
|
+
summary: str(o.summary),
|
|
13549
|
+
prTitle: str(o.prTitle),
|
|
13550
|
+
question: str(o.question)
|
|
13356
13551
|
};
|
|
13357
13552
|
}
|
|
13358
13553
|
/** The prompt for `task`, on `branch`. */
|
|
@@ -13486,7 +13681,7 @@ function redact(text) {
|
|
|
13486
13681
|
return SECRETS.reduce((t, [pattern, by]) => t.replace(pattern, by), text);
|
|
13487
13682
|
}
|
|
13488
13683
|
/** A message the API takes (and the board shows), secrets out. */
|
|
13489
|
-
function clip(text, max = 2e3) {
|
|
13684
|
+
function clip$1(text, max = 2e3) {
|
|
13490
13685
|
const clean = redact(text).trim();
|
|
13491
13686
|
return clean.length > max ? `${clean.slice(0, max - 1)}…` : clean;
|
|
13492
13687
|
}
|
|
@@ -13562,7 +13757,7 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
13562
13757
|
step,
|
|
13563
13758
|
attempt: 1,
|
|
13564
13759
|
status,
|
|
13565
|
-
...message && { message: clip(message) },
|
|
13760
|
+
...message && { message: clip$1(message) },
|
|
13566
13761
|
data: {
|
|
13567
13762
|
durationMs: Date.now() - started,
|
|
13568
13763
|
...data
|
|
@@ -13571,7 +13766,7 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
13571
13766
|
};
|
|
13572
13767
|
const warn = (message) => report.event({
|
|
13573
13768
|
kind: "warning",
|
|
13574
|
-
message: clip(message)
|
|
13769
|
+
message: clip$1(message)
|
|
13575
13770
|
});
|
|
13576
13771
|
/** Says on the task how it went; a failure to is a warning, not the run's ending. */
|
|
13577
13772
|
let ref = run.ref;
|
|
@@ -13607,7 +13802,7 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
13607
13802
|
});
|
|
13608
13803
|
if (moved) report.event({
|
|
13609
13804
|
kind: "board",
|
|
13610
|
-
message: clip(moved)
|
|
13805
|
+
message: clip$1(moved)
|
|
13611
13806
|
});
|
|
13612
13807
|
prompt = buildPrompt({
|
|
13613
13808
|
task,
|
|
@@ -13616,7 +13811,7 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
13616
13811
|
});
|
|
13617
13812
|
end("ok");
|
|
13618
13813
|
} catch (err) {
|
|
13619
|
-
const reason = clip(`Couldn't get the folder ready: ${err.message}`, 1e3);
|
|
13814
|
+
const reason = clip$1(`Couldn't get the folder ready: ${err.message}`, 1e3);
|
|
13620
13815
|
end("failed", reason);
|
|
13621
13816
|
return {
|
|
13622
13817
|
status: "failed",
|
|
@@ -13632,7 +13827,7 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
13632
13827
|
if (limited) report.event({
|
|
13633
13828
|
kind: "warning",
|
|
13634
13829
|
step: "code",
|
|
13635
|
-
message: clip(limited.warning)
|
|
13830
|
+
message: clip$1(limited.warning)
|
|
13636
13831
|
});
|
|
13637
13832
|
const asked = limited ? {
|
|
13638
13833
|
...run,
|
|
@@ -13646,14 +13841,14 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
13646
13841
|
const activity = throttled((message) => report.event({
|
|
13647
13842
|
kind: "activity",
|
|
13648
13843
|
step: "code",
|
|
13649
|
-
message: clip(message, 200)
|
|
13844
|
+
message: clip$1(message, 200)
|
|
13650
13845
|
}), activityMs);
|
|
13651
13846
|
const out = {
|
|
13652
13847
|
activity: (m) => m.trim() && activity.push(m),
|
|
13653
13848
|
warning: (m) => report.event({
|
|
13654
13849
|
kind: "warning",
|
|
13655
13850
|
step: "code",
|
|
13656
|
-
message: clip(m)
|
|
13851
|
+
message: clip$1(m)
|
|
13657
13852
|
}),
|
|
13658
13853
|
externalId: (id) => report.update({ externalId: id.slice(0, 128) })
|
|
13659
13854
|
};
|
|
@@ -13700,7 +13895,7 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
13700
13895
|
}
|
|
13701
13896
|
if (exit.spawnError) return {
|
|
13702
13897
|
status: "failed",
|
|
13703
|
-
reason: clip(exit.spawnError, 1e3)
|
|
13898
|
+
reason: clip$1(exit.spawnError, 1e3)
|
|
13704
13899
|
};
|
|
13705
13900
|
end = begin("commit");
|
|
13706
13901
|
const unfinished = cancelled || failure !== null;
|
|
@@ -13724,195 +13919,859 @@ function codingAgent({ spec, command, args: extra = [], board, env = process.env
|
|
|
13724
13919
|
reason: commits ? `Cancelled; its work so far is on ${branch}.` : null
|
|
13725
13920
|
};
|
|
13726
13921
|
if (failure) {
|
|
13727
|
-
await tell(`${label} couldn't finish: ${clip(failure, 1e3)}${kept}`);
|
|
13922
|
+
await tell(`${label} couldn't finish: ${clip$1(failure, 1e3)}${kept}`);
|
|
13728
13923
|
return {
|
|
13729
13924
|
status: "failed",
|
|
13730
|
-
reason: clip(failure, 1e3)
|
|
13925
|
+
reason: clip$1(failure, 1e3)
|
|
13731
13926
|
};
|
|
13732
13927
|
}
|
|
13733
13928
|
if (outcome?.status === "blocked") {
|
|
13734
13929
|
const question = outcome.question || outcome.summary || "It got stuck without saying why.";
|
|
13735
13930
|
report.event({
|
|
13736
13931
|
kind: "question",
|
|
13737
|
-
message: clip(question)
|
|
13932
|
+
message: clip$1(question)
|
|
13738
13933
|
});
|
|
13739
|
-
await tell(`${label} needs an answer: ${clip(question, 1500)}${kept}`);
|
|
13934
|
+
await tell(`${label} needs an answer: ${clip$1(question, 1500)}${kept}`);
|
|
13740
13935
|
return {
|
|
13741
13936
|
status: "needs_human",
|
|
13742
|
-
reason: clip(question, 1e3)
|
|
13937
|
+
reason: clip$1(question, 1e3)
|
|
13743
13938
|
};
|
|
13744
13939
|
}
|
|
13745
13940
|
const summary = outcome?.summary || (typeof result.answer === "string" ? result.answer : "");
|
|
13746
13941
|
if (!commits) {
|
|
13747
13942
|
const reason = `${label} changed nothing${summary ? `: ${summary}` : "."}`;
|
|
13748
|
-
await tell(`${label} made no changes.${summary ? `\n\n${clip(summary, 1500)}` : ""}`);
|
|
13943
|
+
await tell(`${label} made no changes.${summary ? `\n\n${clip$1(summary, 1500)}` : ""}`);
|
|
13749
13944
|
return {
|
|
13750
13945
|
status: "needs_human",
|
|
13751
|
-
reason: clip(reason, 1e3)
|
|
13946
|
+
reason: clip$1(reason, 1e3)
|
|
13947
|
+
};
|
|
13948
|
+
}
|
|
13949
|
+
let url = null;
|
|
13950
|
+
const prTitle = clip$1(outcome?.prTitle || `${ref}: ${title}`, 200);
|
|
13951
|
+
if (run.options.pr === "none") begin("pr")("skipped", `none asked for: the work is on ${branch}`);
|
|
13952
|
+
else {
|
|
13953
|
+
end = begin("push");
|
|
13954
|
+
try {
|
|
13955
|
+
await ws.push(branch);
|
|
13956
|
+
end("ok");
|
|
13957
|
+
end = begin("pr");
|
|
13958
|
+
url = await ws.pullRequestOf(branch) ?? await ws.openPullRequest({
|
|
13959
|
+
base,
|
|
13960
|
+
branch,
|
|
13961
|
+
title: prTitle,
|
|
13962
|
+
body: `${clip$1(summary || prTitle, 6e3)}\n\n---\n${ref} · by ${label}, through \`monoban runner\``,
|
|
13963
|
+
draft: run.options.pr === "draft"
|
|
13964
|
+
});
|
|
13965
|
+
report.update({ prUrl: url });
|
|
13966
|
+
report.event({
|
|
13967
|
+
kind: "pr_opened",
|
|
13968
|
+
step: "pr",
|
|
13969
|
+
message: url,
|
|
13970
|
+
data: { url }
|
|
13971
|
+
});
|
|
13972
|
+
end("ok");
|
|
13973
|
+
} catch (err) {
|
|
13974
|
+
const reason = clip$1(err.message, 1e3);
|
|
13975
|
+
end("failed", reason);
|
|
13976
|
+
await tell(`${label} finished, but couldn't put it up for review: ${reason}${kept}`);
|
|
13977
|
+
return {
|
|
13978
|
+
status: "failed",
|
|
13979
|
+
reason
|
|
13980
|
+
};
|
|
13981
|
+
}
|
|
13982
|
+
}
|
|
13983
|
+
end = begin("report");
|
|
13984
|
+
try {
|
|
13985
|
+
if (url) await board.attach(ref, url, prTitle, run.options.pr === "draft");
|
|
13986
|
+
await board.comment(ref, `${label} finished${url ? `: ${url}` : `, on the branch \`${branch}\``}.${summary ? `\n\n${clip$1(summary, 6e3)}` : ""}`);
|
|
13987
|
+
report.event({
|
|
13988
|
+
kind: "board",
|
|
13989
|
+
message: url ? "attached the pull request, and commented" : "commented"
|
|
13990
|
+
});
|
|
13991
|
+
end("ok");
|
|
13992
|
+
} catch (err) {
|
|
13993
|
+
end("failed", err.message);
|
|
13994
|
+
}
|
|
13995
|
+
return {
|
|
13996
|
+
status: "succeeded",
|
|
13997
|
+
reason: null
|
|
13998
|
+
};
|
|
13999
|
+
};
|
|
14000
|
+
return {
|
|
14001
|
+
done: flow().catch((err) => ({
|
|
14002
|
+
status: "failed",
|
|
14003
|
+
reason: clip$1(`The run stopped: ${err.message}`, 1e3)
|
|
14004
|
+
})),
|
|
14005
|
+
cancel: async () => {
|
|
14006
|
+
cancelled = true;
|
|
14007
|
+
agent?.stop();
|
|
14008
|
+
}
|
|
14009
|
+
};
|
|
14010
|
+
}
|
|
14011
|
+
};
|
|
14012
|
+
}
|
|
14013
|
+
//#endregion
|
|
14014
|
+
//#region src/runner/agents/claude.ts
|
|
14015
|
+
/**
|
|
14016
|
+
* Claude Code, unattended: `claude -p --output-format stream-json --verbose` with the prompt on stdin. Auto
|
|
14017
|
+
* mode has a classifier review each action instead of a person, and `--permission-prompts none` denies what
|
|
14018
|
+
* would still need one (so nothing waits). It ends with a `result` line: the cost, and the outcome shaped by
|
|
14019
|
+
* --json-schema. It loads the folder's CLAUDE.md, settings and MCP servers, as a session there would.
|
|
14020
|
+
*/
|
|
14021
|
+
/** The oldest Claude Code with --permission-prompts. */
|
|
14022
|
+
const CLAUDE_MINIMUM = "2.1.259";
|
|
14023
|
+
/** "edit src/a.ts", "$ pnpm test", "subagent: review the diff": a tool call in a few words. */
|
|
14024
|
+
function describeTool(name, input = {}, roots = []) {
|
|
14025
|
+
const path = (key) => relativeTo(roots, input[key]);
|
|
14026
|
+
switch (name) {
|
|
14027
|
+
case "Edit":
|
|
14028
|
+
case "MultiEdit": return `edit ${path("file_path")}`;
|
|
14029
|
+
case "NotebookEdit": return `edit ${path("notebook_path")}`;
|
|
14030
|
+
case "Write": return `write ${path("file_path")}`;
|
|
14031
|
+
case "Read": return `read ${path("file_path")}`;
|
|
14032
|
+
case "Bash": return `$ ${firstLine(input.command)}`;
|
|
14033
|
+
case "Grep": return `search ${JSON.stringify(input.pattern ?? "")}`;
|
|
14034
|
+
case "Glob": return `find ${String(input.pattern ?? "")}`;
|
|
14035
|
+
case "Agent":
|
|
14036
|
+
case "Task": return `subagent: ${String(input.description ?? input.subagent_type ?? "")}`;
|
|
14037
|
+
case "TodoWrite": return planLine((Array.isArray(input.todos) ? input.todos : []).map((t) => ({ done: t.status === "completed" })));
|
|
14038
|
+
case "WebFetch": return `fetch ${String(input.url ?? "")}`;
|
|
14039
|
+
case "WebSearch": return `search the web: ${String(input.query ?? "")}`;
|
|
14040
|
+
default: return name.startsWith("mcp__") ? name.split("__").slice(1).join(": ") : name;
|
|
14041
|
+
}
|
|
14042
|
+
}
|
|
14043
|
+
/** Why a `result` line says it didn't succeed. */
|
|
14044
|
+
function failureOf(line) {
|
|
14045
|
+
const subtype = line.subtype ?? "";
|
|
14046
|
+
if (subtype.includes("budget")) return "It reached its budget.";
|
|
14047
|
+
if (subtype.includes("max_turns")) return "It reached its turn limit.";
|
|
14048
|
+
const said = typeof line.result === "string" && line.result.trim() ? line.result.trim().split("\n")[0] : null;
|
|
14049
|
+
return `It stopped${subtype && subtype !== "success" ? ` (${subtype.replace(/_/g, " ")})` : ""}${said ? `: ${said}` : "."}`;
|
|
14050
|
+
}
|
|
14051
|
+
function claudeReader(roots) {
|
|
14052
|
+
let answer = null;
|
|
14053
|
+
let lastText = null;
|
|
14054
|
+
let costUsd = null;
|
|
14055
|
+
let failure = null;
|
|
14056
|
+
let ended = false;
|
|
14057
|
+
return {
|
|
14058
|
+
line(text, out) {
|
|
14059
|
+
if (!text.trim().startsWith("{")) return;
|
|
14060
|
+
const line = JSON.parse(text);
|
|
14061
|
+
switch (line.type) {
|
|
14062
|
+
case "system":
|
|
14063
|
+
if (line.subtype === "init") {
|
|
14064
|
+
if (line.session_id) out.externalId(line.session_id);
|
|
14065
|
+
out.activity(line.model ? `started (${line.model})` : "started");
|
|
14066
|
+
} else if (line.subtype === "api_retry") out.activity(`retrying: ${line.error ?? "the API"}${line.attempt ? ` (attempt ${line.attempt})` : ""}`);
|
|
14067
|
+
return;
|
|
14068
|
+
case "assistant":
|
|
14069
|
+
for (const c of line.message?.content ?? []) if (c.type === "tool_use" && c.name) {
|
|
14070
|
+
if (c.name !== "StructuredOutput") out.activity(describeTool(c.name, c.input, roots));
|
|
14071
|
+
} else if (c.type === "text" && c.text?.trim()) lastText = c.text;
|
|
14072
|
+
return;
|
|
14073
|
+
case "result": {
|
|
14074
|
+
ended = true;
|
|
14075
|
+
if (typeof line.total_cost_usd === "number") costUsd = line.total_cost_usd;
|
|
14076
|
+
answer = line.structured_output ?? line.result ?? lastText;
|
|
14077
|
+
if (line.is_error || line.subtype && line.subtype !== "success") failure = failureOf(line);
|
|
14078
|
+
const denied = new Set((line.permission_denials ?? []).map((d) => describeTool(d.tool_name ?? "a tool", d.tool_input, roots)));
|
|
14079
|
+
for (const what of [...denied].slice(0, 3)) out.warning(`Not allowed: ${what}`);
|
|
14080
|
+
return;
|
|
14081
|
+
}
|
|
14082
|
+
}
|
|
14083
|
+
},
|
|
14084
|
+
result: () => ({
|
|
14085
|
+
answer: ended ? answer : lastText,
|
|
14086
|
+
costUsd,
|
|
14087
|
+
tokens: null,
|
|
14088
|
+
failure
|
|
14089
|
+
})
|
|
14090
|
+
};
|
|
14091
|
+
}
|
|
14092
|
+
const claude = {
|
|
14093
|
+
name: "claude",
|
|
14094
|
+
args: (run, { schema }, extra) => [
|
|
14095
|
+
"-p",
|
|
14096
|
+
"--output-format",
|
|
14097
|
+
"stream-json",
|
|
14098
|
+
"--verbose",
|
|
14099
|
+
"--permission-mode",
|
|
14100
|
+
"auto",
|
|
14101
|
+
"--permission-prompts",
|
|
14102
|
+
"none",
|
|
14103
|
+
"--json-schema",
|
|
14104
|
+
schema,
|
|
14105
|
+
...run.options.budgetUsd !== void 0 ? ["--max-budget-usd", String(run.options.budgetUsd)] : [],
|
|
14106
|
+
...run.options.model ? ["--model", run.options.model] : [],
|
|
14107
|
+
...extra
|
|
14108
|
+
],
|
|
14109
|
+
reader: claudeReader
|
|
14110
|
+
};
|
|
14111
|
+
const AGENT_NAMES$1 = Object.keys(AGENTS$1);
|
|
14112
|
+
const isAgent = (name) => AGENT_NAMES$1.includes(name);
|
|
14113
|
+
/** What's wrong with runner.json's contents, or null. */
|
|
14114
|
+
function fileProblem(v) {
|
|
14115
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return "it should be an object";
|
|
14116
|
+
const f = v;
|
|
14117
|
+
const known = [
|
|
14118
|
+
"name",
|
|
14119
|
+
"pollSeconds",
|
|
14120
|
+
"allow",
|
|
14121
|
+
"confirm",
|
|
14122
|
+
"agents",
|
|
14123
|
+
"adapters"
|
|
14124
|
+
];
|
|
14125
|
+
const unknown = Object.keys(f).find((k) => !known.includes(k));
|
|
14126
|
+
if (unknown) return `${unknown} isn't a setting (${known.join(", ")})`;
|
|
14127
|
+
if (f.name !== void 0 && (typeof f.name !== "string" || !f.name.trim() || f.name.length > 64)) return "name: 1 to 64 characters";
|
|
14128
|
+
if (f.pollSeconds !== void 0 && !(Number.isInteger(f.pollSeconds) && f.pollSeconds >= 1 && f.pollSeconds <= 60)) return "pollSeconds: a whole number of seconds, 1 to 60";
|
|
14129
|
+
if (f.allow !== void 0 && !(Array.isArray(f.allow) && f.allow.every((p) => typeof p === "string" && p.startsWith("/")))) return "allow: a list of absolute paths";
|
|
14130
|
+
if (f.confirm !== void 0 && typeof f.confirm !== "boolean") return "confirm: true or false";
|
|
14131
|
+
if (f.agents !== void 0) {
|
|
14132
|
+
if (!Array.isArray(f.agents) || !f.agents.every((a) => typeof a === "string" && isAgent(a))) return `agents: a list of ${AGENT_NAMES$1.join(", ")}`;
|
|
14133
|
+
}
|
|
14134
|
+
if (f.adapters !== void 0) {
|
|
14135
|
+
if (!f.adapters || typeof f.adapters !== "object" || Array.isArray(f.adapters)) return "adapters: an object";
|
|
14136
|
+
for (const [name, value] of Object.entries(f.adapters)) {
|
|
14137
|
+
if (!isAgent(name)) return `adapters.${name}: monoban doesn't run ${name} (${AGENT_NAMES$1.join(", ")})`;
|
|
14138
|
+
const agent = value ?? {};
|
|
14139
|
+
const settings = [
|
|
14140
|
+
"command",
|
|
14141
|
+
"args",
|
|
14142
|
+
...name === "codex" ? ["allowFullAccess"] : name === "agentpipe" ? ["budgetUsd"] : []
|
|
14143
|
+
];
|
|
14144
|
+
const extra = Object.keys(agent).find((k) => !settings.includes(k));
|
|
14145
|
+
if (extra) return `adapters.${name}.${extra} isn't a setting (${settings.join(", ")})`;
|
|
14146
|
+
if (agent.allowFullAccess !== void 0 && typeof agent.allowFullAccess !== "boolean") return `adapters.${name}.allowFullAccess: true or false`;
|
|
14147
|
+
if (agent.budgetUsd !== void 0 && !(typeof agent.budgetUsd === "number" && agent.budgetUsd >= .1 && agent.budgetUsd <= 1e3)) return `adapters.${name}.budgetUsd: US dollars, 0.1 to 1000`;
|
|
14148
|
+
if (agent.command !== void 0 && (typeof agent.command !== "string" || !agent.command)) return `adapters.${name}.command: a command`;
|
|
14149
|
+
if (agent.args !== void 0 && !(Array.isArray(agent.args) && agent.args.every((a) => typeof a === "string"))) return `adapters.${name}.args: a list of arguments`;
|
|
14150
|
+
}
|
|
14151
|
+
}
|
|
14152
|
+
return null;
|
|
14153
|
+
}
|
|
14154
|
+
const RUNNER_FILE = "runner.json";
|
|
14155
|
+
async function readSettingsFile(dir) {
|
|
14156
|
+
const path = join(dir, RUNNER_FILE);
|
|
14157
|
+
let text;
|
|
14158
|
+
try {
|
|
14159
|
+
text = await readFile(path, "utf8");
|
|
14160
|
+
} catch {
|
|
14161
|
+
return {};
|
|
14162
|
+
}
|
|
14163
|
+
let parsed;
|
|
14164
|
+
try {
|
|
14165
|
+
parsed = JSON.parse(text);
|
|
14166
|
+
} catch {
|
|
14167
|
+
throw new CliError(`${path} isn't JSON.`, EXIT.usage);
|
|
14168
|
+
}
|
|
14169
|
+
const problem = fileProblem(parsed);
|
|
14170
|
+
if (problem) throw new CliError(`${path}: ${problem}.`, EXIT.usage);
|
|
14171
|
+
return parsed;
|
|
14172
|
+
}
|
|
14173
|
+
/** --agents claude,codex. */
|
|
14174
|
+
function agentsFlag(value) {
|
|
14175
|
+
const names = value.split(",").map((a) => a.trim().toLowerCase()).filter(Boolean);
|
|
14176
|
+
const unknown = names.find((a) => !isAgent(a));
|
|
14177
|
+
if (unknown || !names.length) throw new CliError(`--agents takes ${AGENT_NAMES$1.join(", ")} (comma-separated)${unknown ? `, not ${unknown}` : ""}.`, EXIT.usage);
|
|
14178
|
+
return names;
|
|
14179
|
+
}
|
|
14180
|
+
async function runnerSettings(dir, flags, env, hostname) {
|
|
14181
|
+
const file = await readSettingsFile(dir);
|
|
14182
|
+
let pollSeconds = file.pollSeconds ?? 3;
|
|
14183
|
+
if (flags.interval !== void 0) {
|
|
14184
|
+
pollSeconds = Number(flags.interval);
|
|
14185
|
+
if (!Number.isInteger(pollSeconds) || pollSeconds < 1 || pollSeconds > 60) throw new CliError("--interval is how often to ask for work, in seconds: 1 to 60.", EXIT.usage);
|
|
14186
|
+
}
|
|
14187
|
+
const allow = [...file.allow ?? [], ...flags.allow ?? []];
|
|
14188
|
+
const relative = allow.find((p) => !p.startsWith("/"));
|
|
14189
|
+
if (relative) throw new CliError(`--allow takes absolute paths (${relative} isn't one).`, EXIT.usage);
|
|
14190
|
+
const commands = {};
|
|
14191
|
+
const args = {};
|
|
14192
|
+
for (const name of AGENT_NAMES$1) {
|
|
14193
|
+
commands[name] = env[`MONOBAN_${name.toUpperCase()}`] || file.adapters?.[name]?.command || (name === "agentpipe" && existsSync(agentpipeBin(env)) ? agentpipeBin(env) : name);
|
|
14194
|
+
args[name] = file.adapters?.[name]?.args ?? [];
|
|
14195
|
+
}
|
|
14196
|
+
return {
|
|
14197
|
+
name: flags.name?.trim() || file.name || hostname,
|
|
14198
|
+
pollSeconds,
|
|
14199
|
+
allow,
|
|
14200
|
+
confirm: flags.confirm ?? file.confirm ?? false,
|
|
14201
|
+
agents: flags.agents !== void 0 ? agentsFlag(flags.agents) : file.agents ?? null,
|
|
14202
|
+
commands,
|
|
14203
|
+
args,
|
|
14204
|
+
allowFullAccess: flags.allowFullAccess ?? file.adapters?.codex?.allowFullAccess ?? false,
|
|
14205
|
+
agentpipeBudgetUsd: file.adapters?.agentpipe?.budgetUsd ?? 10
|
|
14206
|
+
};
|
|
14207
|
+
}
|
|
14208
|
+
//#endregion
|
|
14209
|
+
//#region src/commands/doctor.ts
|
|
14210
|
+
const MARKS = {
|
|
14211
|
+
ok: "✓",
|
|
14212
|
+
warn: "!",
|
|
14213
|
+
fail: "✗"
|
|
14214
|
+
};
|
|
14215
|
+
async function checks(ctx, deps = {}) {
|
|
14216
|
+
const version = deps.version ?? versionOf;
|
|
14217
|
+
const env = ctx.env;
|
|
14218
|
+
const found = [];
|
|
14219
|
+
const latest = await (deps.latest ?? latestVersion)(ctx);
|
|
14220
|
+
const upgrade = UPGRADE[thisInstall()].command;
|
|
14221
|
+
found.push(latest && newer(latest, "1.7.0") ? {
|
|
14222
|
+
name: "monoban",
|
|
14223
|
+
status: "warn",
|
|
14224
|
+
detail: `${VERSION}; ${latest} is out`,
|
|
14225
|
+
fix: upgrade
|
|
14226
|
+
} : {
|
|
14227
|
+
name: "monoban",
|
|
14228
|
+
status: "ok",
|
|
14229
|
+
detail: latest ? `${VERSION} (the latest)` : VERSION
|
|
14230
|
+
});
|
|
14231
|
+
try {
|
|
14232
|
+
const me = await unwrap(apis(ctx).signedIn.GET("/v1/me"));
|
|
14233
|
+
found.push({
|
|
14234
|
+
name: "sign-in",
|
|
14235
|
+
status: "ok",
|
|
14236
|
+
detail: me.email ?? me.id
|
|
14237
|
+
});
|
|
14238
|
+
} catch (err) {
|
|
14239
|
+
if (err instanceof NotSignedIn || err instanceof ApiProblem && err.status === 401) found.push({
|
|
14240
|
+
name: "sign-in",
|
|
14241
|
+
status: "fail",
|
|
14242
|
+
detail: "not signed in",
|
|
14243
|
+
fix: "monoban login"
|
|
14244
|
+
});
|
|
14245
|
+
else found.push({
|
|
14246
|
+
name: "sign-in",
|
|
14247
|
+
status: "warn",
|
|
14248
|
+
detail: `can't reach ${ctx.apiUrl} (${err.message})`
|
|
14249
|
+
});
|
|
14250
|
+
}
|
|
14251
|
+
let settings = null;
|
|
14252
|
+
try {
|
|
14253
|
+
settings = await runnerSettings(configDir(ctx.env), {}, ctx.env, deviceName());
|
|
14254
|
+
} catch (err) {
|
|
14255
|
+
found.push({
|
|
14256
|
+
name: "runner.json",
|
|
14257
|
+
status: "fail",
|
|
14258
|
+
detail: err.message
|
|
14259
|
+
});
|
|
14260
|
+
}
|
|
14261
|
+
const pipe = await (deps.agentpipe ?? agentpipeStatus)(ctx.env);
|
|
14262
|
+
const command = settings?.commands.agentpipe ?? "agentpipe";
|
|
14263
|
+
if (command !== "agentpipe" && command !== agentpipeBin(ctx.env)) {
|
|
14264
|
+
const v = await version(command, env);
|
|
14265
|
+
found.push(v ? {
|
|
14266
|
+
name: "agentpipe",
|
|
14267
|
+
status: "ok",
|
|
14268
|
+
detail: `${v} (${command}, the runner's)`
|
|
14269
|
+
} : {
|
|
14270
|
+
name: "agentpipe",
|
|
14271
|
+
status: "warn",
|
|
14272
|
+
detail: `${command} doesn't answer --version`
|
|
14273
|
+
});
|
|
14274
|
+
} else {
|
|
14275
|
+
const onPath = pipe.installed ? null : await version("agentpipe", env);
|
|
14276
|
+
const said = describeStatus(pipe);
|
|
14277
|
+
if (onPath && !newer(pipe.pinned, onPath)) found.push({
|
|
14278
|
+
name: "agentpipe",
|
|
14279
|
+
status: "ok",
|
|
14280
|
+
detail: `${onPath} (on PATH)`
|
|
14281
|
+
});
|
|
14282
|
+
else if (onPath) {
|
|
14283
|
+
const detail = `${onPath} (on PATH); this monoban comes with ${pipe.pinned}`;
|
|
14284
|
+
found.push({
|
|
14285
|
+
name: "agentpipe",
|
|
14286
|
+
status: "warn",
|
|
14287
|
+
detail,
|
|
14288
|
+
fix: "monoban agentpipe install"
|
|
14289
|
+
});
|
|
14290
|
+
} else found.push({
|
|
14291
|
+
name: "agentpipe",
|
|
14292
|
+
status: said.ok ? "ok" : "warn",
|
|
14293
|
+
detail: said.text,
|
|
14294
|
+
...said.fix && { fix: said.fix }
|
|
14295
|
+
});
|
|
14296
|
+
}
|
|
14297
|
+
const agents = [{
|
|
14298
|
+
name: "claude",
|
|
14299
|
+
minimum: CLAUDE_MINIMUM,
|
|
14300
|
+
update: "claude update"
|
|
14301
|
+
}, {
|
|
14302
|
+
name: "codex",
|
|
14303
|
+
minimum: null,
|
|
14304
|
+
update: null
|
|
14305
|
+
}];
|
|
14306
|
+
for (const agent of agents) {
|
|
14307
|
+
const v = await version(settings?.commands[agent.name] ?? agent.name, env);
|
|
14308
|
+
const label = agentLabel(agent.name);
|
|
14309
|
+
if (!v) found.push({
|
|
14310
|
+
name: label,
|
|
14311
|
+
status: "warn",
|
|
14312
|
+
detail: "not installed (the runner offers it once it is)"
|
|
14313
|
+
});
|
|
14314
|
+
else if (agent.minimum && !atLeast(v, agent.minimum)) found.push({
|
|
14315
|
+
name: label,
|
|
14316
|
+
status: "warn",
|
|
14317
|
+
detail: `${v}; the runner needs ${agent.minimum}`,
|
|
14318
|
+
fix: agent.update ?? ""
|
|
14319
|
+
});
|
|
14320
|
+
else found.push({
|
|
14321
|
+
name: label,
|
|
14322
|
+
status: "ok",
|
|
14323
|
+
detail: v
|
|
14324
|
+
});
|
|
14325
|
+
}
|
|
14326
|
+
const git = await version("git", env);
|
|
14327
|
+
found.push(git ? {
|
|
14328
|
+
name: "git",
|
|
14329
|
+
status: "ok",
|
|
14330
|
+
detail: git
|
|
14331
|
+
} : {
|
|
14332
|
+
name: "git",
|
|
14333
|
+
status: "fail",
|
|
14334
|
+
detail: "not installed"
|
|
14335
|
+
});
|
|
14336
|
+
const gh = await version("gh", env);
|
|
14337
|
+
found.push(gh ? {
|
|
14338
|
+
name: "gh",
|
|
14339
|
+
status: "ok",
|
|
14340
|
+
detail: gh
|
|
14341
|
+
} : {
|
|
14342
|
+
name: "gh",
|
|
14343
|
+
status: "warn",
|
|
14344
|
+
detail: "not installed: runs can't open pull requests",
|
|
14345
|
+
fix: "https://cli.github.com"
|
|
14346
|
+
});
|
|
14347
|
+
return found;
|
|
14348
|
+
}
|
|
14349
|
+
/** `monoban doctor`. */
|
|
14350
|
+
async function doctor(ctx, options, deps = {}) {
|
|
14351
|
+
const found = await checks(ctx, deps);
|
|
14352
|
+
if (options.json) ctx.out(JSON.stringify({ checks: found }, null, 2));
|
|
14353
|
+
else {
|
|
14354
|
+
const width = Math.max(...found.map((c) => c.name.length));
|
|
14355
|
+
for (const c of found) ctx.out(`${MARKS[c.status]} ${c.name.padEnd(width)} ${c.detail}${c.fix ? `: ${c.fix}` : ""}`);
|
|
14356
|
+
}
|
|
14357
|
+
if (found.some((c) => c.status === "fail")) throw new CliError("", EXIT.error);
|
|
14358
|
+
}
|
|
14359
|
+
//#endregion
|
|
14360
|
+
//#region src/commands/notes.ts
|
|
14361
|
+
const printNotes = (ctx, key, notes) => ctx.out(JSON.stringify({
|
|
14362
|
+
project: key,
|
|
14363
|
+
...notes
|
|
14364
|
+
}, null, 2));
|
|
14365
|
+
/** `monoban notes`: the project's notes as they are, for reading, a pager or a pipe. */
|
|
14366
|
+
async function notesShow(ctx, options) {
|
|
14367
|
+
const api = apis(ctx).signedIn;
|
|
14368
|
+
const key = await resolveProject(ctx, api, options.project);
|
|
14369
|
+
const notes = await unwrap(api.GET("/v1/projects/{key}/notes", { params: { path: { key } } }));
|
|
14370
|
+
if (options.json) return printNotes(ctx, key, notes);
|
|
14371
|
+
if (!notes.text) {
|
|
14372
|
+
ctx.err(`${key} has no notes yet. Add a line with \`monoban notes add …\`, or write them with \`monoban notes edit\`.`);
|
|
14373
|
+
return;
|
|
14374
|
+
}
|
|
14375
|
+
ctx.out(notes.text.replace(/\n$/, ""));
|
|
14376
|
+
}
|
|
14377
|
+
/** `monoban notes add TEXT…`: a line at the end of the notes (`-` reads it from stdin). */
|
|
14378
|
+
async function notesAdd(ctx, words, options) {
|
|
14379
|
+
const text = words.length === 1 && words[0] === "-" ? (await ctx.readStdin()).replace(/\n$/, "") : words.join(" ");
|
|
14380
|
+
if (!text.trim()) throw new CliError("Nothing to add: give the text, or - to read it from stdin.", EXIT.usage);
|
|
14381
|
+
const api = apis(ctx).signedIn;
|
|
14382
|
+
const key = await resolveProject(ctx, api, options.project);
|
|
14383
|
+
const notes = await unwrap(api.PATCH("/v1/projects/{key}/notes", {
|
|
14384
|
+
params: { path: { key } },
|
|
14385
|
+
body: { append: text }
|
|
14386
|
+
}));
|
|
14387
|
+
if (options.json) return printNotes(ctx, key, notes);
|
|
14388
|
+
ctx.out(`Added to the notes of ${key}.`);
|
|
14389
|
+
}
|
|
14390
|
+
/** `monoban notes edit`: the notes in $EDITOR, saved only if nobody changed them in the meantime. */
|
|
14391
|
+
async function notesEdit(ctx, options) {
|
|
14392
|
+
const api = apis(ctx).signedIn;
|
|
14393
|
+
const key = await resolveProject(ctx, api, options.project);
|
|
14394
|
+
const notes = await unwrap(api.GET("/v1/projects/{key}/notes", { params: { path: { key } } }));
|
|
14395
|
+
const text = await ctx.edit(notes.text, `${key}-notes`);
|
|
14396
|
+
if (text === notes.text) {
|
|
14397
|
+
ctx.err(`No changes to the notes of ${key}.`);
|
|
14398
|
+
return;
|
|
14399
|
+
}
|
|
14400
|
+
let saved;
|
|
14401
|
+
try {
|
|
14402
|
+
saved = await unwrap(api.PATCH("/v1/projects/{key}/notes", {
|
|
14403
|
+
params: {
|
|
14404
|
+
path: { key },
|
|
14405
|
+
header: ifMatch(notes.version)
|
|
14406
|
+
},
|
|
14407
|
+
body: { text }
|
|
14408
|
+
}));
|
|
14409
|
+
} catch (err) {
|
|
14410
|
+
const draft = await keepDraft(text, `${key}-notes`);
|
|
14411
|
+
ctx.err(`Your text is saved in ${draft}.`);
|
|
14412
|
+
if (err instanceof ApiProblem && err.status === 412) throw new CliError(`The notes of ${key} changed elsewhere in the meantime. Run \`monoban notes edit\` again.`);
|
|
14413
|
+
throw err;
|
|
14414
|
+
}
|
|
14415
|
+
if (options.json) return printNotes(ctx, key, saved);
|
|
14416
|
+
ctx.out(`Updated the notes of ${key}.`);
|
|
14417
|
+
}
|
|
14418
|
+
//#endregion
|
|
14419
|
+
//#region src/runner/agents/agentpipe.ts
|
|
14420
|
+
/** agentpipe's step statuses that monoban has too; the others (budget_exceeded, max_turns…) are failures. */
|
|
14421
|
+
const SAME = [
|
|
14422
|
+
"ok",
|
|
14423
|
+
"failed",
|
|
14424
|
+
"skipped",
|
|
14425
|
+
"cancelled",
|
|
14426
|
+
"needs_human"
|
|
14427
|
+
];
|
|
14428
|
+
const RUN_ENDINGS = {
|
|
14429
|
+
ok: "succeeded",
|
|
14430
|
+
needs_human: "needs_human",
|
|
14431
|
+
cancelled: "cancelled",
|
|
14432
|
+
nothing_to_do: "succeeded"
|
|
14433
|
+
};
|
|
14434
|
+
/** How agentpipe's own endings read, before its reason. */
|
|
14435
|
+
const SAYS = {
|
|
14436
|
+
refused: "It couldn't start",
|
|
14437
|
+
nothing_to_do: "There was nothing to do"
|
|
14438
|
+
};
|
|
14439
|
+
const str = (v) => typeof v === "string" && v.trim() ? v.trim() : null;
|
|
14440
|
+
const num = (v) => typeof v === "number" && Number.isFinite(v) ? v : null;
|
|
14441
|
+
/** A message the API takes: one line or more, at most 2000 characters. */
|
|
14442
|
+
const clip = (text) => text.length > 2e3 ? `${text.slice(0, 1999)}…` : text;
|
|
14443
|
+
/**
|
|
14444
|
+
* Turns agentpipe's events into monoban's, one at a time, remembering what it needs across them. agentpipe ends
|
|
14445
|
+
* each step twice: first with what the step decided (a skip says `skipped`, with its reason), then with what it
|
|
14446
|
+
* cost (`turns`, `cost_usd`). They become one step_finished, sent when the second arrives (or the next step
|
|
14447
|
+
* starts, or the run ends, if it never does).
|
|
14448
|
+
*/
|
|
14449
|
+
function agentpipeMapper(report) {
|
|
14450
|
+
const started = /* @__PURE__ */ new Set();
|
|
14451
|
+
const attempts = /* @__PURE__ */ new Map();
|
|
14452
|
+
let pending = null;
|
|
14453
|
+
let total = 0;
|
|
14454
|
+
let ending = null;
|
|
14455
|
+
const flush = (cost) => {
|
|
14456
|
+
if (!pending) return;
|
|
14457
|
+
const { step, attempt, status, message, at } = pending;
|
|
14458
|
+
pending = null;
|
|
14459
|
+
const data = {};
|
|
14460
|
+
if (cost?.durationMs != null) data.durationMs = cost.durationMs;
|
|
14461
|
+
if (cost?.costUsd != null) data.costUsd = cost.costUsd;
|
|
14462
|
+
report.event({
|
|
14463
|
+
kind: "step_finished",
|
|
14464
|
+
step,
|
|
14465
|
+
attempt,
|
|
14466
|
+
status,
|
|
14467
|
+
...message && { message: clip(message) },
|
|
14468
|
+
...Object.keys(data).length && { data },
|
|
14469
|
+
...at && { at }
|
|
14470
|
+
});
|
|
14471
|
+
};
|
|
14472
|
+
const stepStatus = (raw) => {
|
|
14473
|
+
const s = str(raw) ?? "ok";
|
|
14474
|
+
return SAME.includes(s) ? {
|
|
14475
|
+
status: s,
|
|
14476
|
+
note: null
|
|
14477
|
+
} : {
|
|
14478
|
+
status: "failed",
|
|
14479
|
+
note: s.replace(/_/g, " ")
|
|
14480
|
+
};
|
|
14481
|
+
};
|
|
14482
|
+
/** Feed it one event; answers how the run ended once agentpipe said so. */
|
|
14483
|
+
const take = (e) => {
|
|
14484
|
+
const d = e.data ?? {};
|
|
14485
|
+
const at = str(e.ts) ?? void 0;
|
|
14486
|
+
const step = str(e.step);
|
|
14487
|
+
switch (e.kind) {
|
|
14488
|
+
case "run.start": {
|
|
14489
|
+
const id = str(d.run_id) ?? str(e.run_id);
|
|
14490
|
+
if (id) report.update({ externalId: id });
|
|
14491
|
+
return;
|
|
14492
|
+
}
|
|
14493
|
+
case "step.start": {
|
|
14494
|
+
if (!step) return;
|
|
14495
|
+
const attempt = num(d.attempt) ?? attempts.get(step) ?? 1;
|
|
14496
|
+
const key = `${step}@${attempt}`;
|
|
14497
|
+
if (started.has(key)) return;
|
|
14498
|
+
if (pending && pending.step !== step) flush();
|
|
14499
|
+
started.add(key);
|
|
14500
|
+
attempts.set(step, attempt);
|
|
14501
|
+
report.event({
|
|
14502
|
+
kind: "step_started",
|
|
14503
|
+
step,
|
|
14504
|
+
attempt,
|
|
14505
|
+
status: "running",
|
|
14506
|
+
...at && { at }
|
|
14507
|
+
});
|
|
14508
|
+
return;
|
|
14509
|
+
}
|
|
14510
|
+
case "step.end": {
|
|
14511
|
+
if (!step) return;
|
|
14512
|
+
const attempt = num(d.attempt) ?? attempts.get(step) ?? 1;
|
|
14513
|
+
const { status, note } = stepStatus(d.status);
|
|
14514
|
+
const reason = str(d.reason) ?? str(d.error) ?? note;
|
|
14515
|
+
const costShaped = "turns" in d || "cost_usd" in d;
|
|
14516
|
+
if (!pending || pending.step !== step) {
|
|
14517
|
+
flush();
|
|
14518
|
+
pending = {
|
|
14519
|
+
step,
|
|
14520
|
+
attempt,
|
|
14521
|
+
status,
|
|
14522
|
+
message: reason,
|
|
14523
|
+
...at && { at }
|
|
13752
14524
|
};
|
|
14525
|
+
} else {
|
|
14526
|
+
if (pending.status === "ok" && status !== "ok") pending.status = status;
|
|
14527
|
+
pending.message = pending.message ?? reason;
|
|
14528
|
+
if (at) pending.at = at;
|
|
13753
14529
|
}
|
|
13754
|
-
|
|
13755
|
-
|
|
13756
|
-
|
|
13757
|
-
|
|
13758
|
-
|
|
13759
|
-
try {
|
|
13760
|
-
await ws.push(branch);
|
|
13761
|
-
end("ok");
|
|
13762
|
-
end = begin("pr");
|
|
13763
|
-
url = await ws.pullRequestOf(branch) ?? await ws.openPullRequest({
|
|
13764
|
-
base,
|
|
13765
|
-
branch,
|
|
13766
|
-
title: prTitle,
|
|
13767
|
-
body: `${clip(summary || prTitle, 6e3)}\n\n---\n${ref} · by ${label}, through \`monoban runner\``,
|
|
13768
|
-
draft: run.options.pr === "draft"
|
|
13769
|
-
});
|
|
13770
|
-
report.update({ prUrl: url });
|
|
13771
|
-
report.event({
|
|
13772
|
-
kind: "pr_opened",
|
|
13773
|
-
step: "pr",
|
|
13774
|
-
message: url,
|
|
13775
|
-
data: { url }
|
|
13776
|
-
});
|
|
13777
|
-
end("ok");
|
|
13778
|
-
} catch (err) {
|
|
13779
|
-
const reason = clip(err.message, 1e3);
|
|
13780
|
-
end("failed", reason);
|
|
13781
|
-
await tell(`${label} finished, but couldn't put it up for review: ${reason}${kept}`);
|
|
13782
|
-
return {
|
|
13783
|
-
status: "failed",
|
|
13784
|
-
reason
|
|
13785
|
-
};
|
|
14530
|
+
if (costShaped) {
|
|
14531
|
+
const costUsd = num(d.cost_usd);
|
|
14532
|
+
if (costUsd) {
|
|
14533
|
+
total += costUsd;
|
|
14534
|
+
report.update({ costUsd: Math.round(total * 1e4) / 1e4 });
|
|
13786
14535
|
}
|
|
13787
|
-
|
|
13788
|
-
|
|
13789
|
-
|
|
13790
|
-
if (url) await board.attach(ref, url, prTitle, run.options.pr === "draft");
|
|
13791
|
-
await board.comment(ref, `${label} finished${url ? `: ${url}` : `, on the branch \`${branch}\``}.${summary ? `\n\n${clip(summary, 6e3)}` : ""}`);
|
|
13792
|
-
report.event({
|
|
13793
|
-
kind: "board",
|
|
13794
|
-
message: url ? "attached the pull request, and commented" : "commented"
|
|
14536
|
+
flush({
|
|
14537
|
+
durationMs: num(d.duration_ms),
|
|
14538
|
+
costUsd
|
|
13795
14539
|
});
|
|
13796
|
-
end("ok");
|
|
13797
|
-
} catch (err) {
|
|
13798
|
-
end("failed", err.message);
|
|
13799
14540
|
}
|
|
13800
|
-
return
|
|
13801
|
-
|
|
13802
|
-
|
|
14541
|
+
return;
|
|
14542
|
+
}
|
|
14543
|
+
case "pr.created": {
|
|
14544
|
+
const url = str(d.url);
|
|
14545
|
+
if (!url) return;
|
|
14546
|
+
report.update({ prUrl: url });
|
|
14547
|
+
report.event({
|
|
14548
|
+
kind: "pr_opened",
|
|
14549
|
+
...step && { step },
|
|
14550
|
+
message: url,
|
|
14551
|
+
data: {
|
|
14552
|
+
url,
|
|
14553
|
+
...num(d.number) !== null && { number: num(d.number) }
|
|
14554
|
+
},
|
|
14555
|
+
...at && { at }
|
|
14556
|
+
});
|
|
14557
|
+
return;
|
|
14558
|
+
}
|
|
14559
|
+
case "issue.updated": {
|
|
14560
|
+
const change = str(d.change);
|
|
14561
|
+
if (change) report.event({
|
|
14562
|
+
kind: "board",
|
|
14563
|
+
message: clip(change),
|
|
14564
|
+
...at && { at }
|
|
14565
|
+
});
|
|
14566
|
+
return;
|
|
14567
|
+
}
|
|
14568
|
+
case "issue.comment": {
|
|
14569
|
+
const milestone = str(d.milestone);
|
|
14570
|
+
report.event({
|
|
14571
|
+
kind: "board",
|
|
14572
|
+
message: milestone ? `commented: ${milestone}` : "commented",
|
|
14573
|
+
...at && { at }
|
|
14574
|
+
});
|
|
14575
|
+
return;
|
|
14576
|
+
}
|
|
14577
|
+
case "question.asked":
|
|
14578
|
+
case "escalation": {
|
|
14579
|
+
const text = str(d.question) ?? str(d.text) ?? str(d.message) ?? str(d.reason) ?? "It needs an answer.";
|
|
14580
|
+
report.event({
|
|
14581
|
+
kind: "question",
|
|
14582
|
+
...step && { step },
|
|
14583
|
+
message: clip(text),
|
|
14584
|
+
...at && { at }
|
|
14585
|
+
});
|
|
14586
|
+
return;
|
|
14587
|
+
}
|
|
14588
|
+
case "error": {
|
|
14589
|
+
const text = str(d.message) ?? str(d.kind) ?? "Something went wrong.";
|
|
14590
|
+
report.event({
|
|
14591
|
+
kind: "warning",
|
|
14592
|
+
...step && { step },
|
|
14593
|
+
message: clip(text),
|
|
14594
|
+
...at && { at }
|
|
14595
|
+
});
|
|
14596
|
+
return;
|
|
14597
|
+
}
|
|
14598
|
+
case "run.end": {
|
|
14599
|
+
flush();
|
|
14600
|
+
const status = str(d.status) ?? "failed";
|
|
14601
|
+
const reason = str(d.reason);
|
|
14602
|
+
const says = SAYS[status];
|
|
14603
|
+
ending = {
|
|
14604
|
+
status: RUN_ENDINGS[status] ?? "failed",
|
|
14605
|
+
reason: clip(says ? `${says}${reason ? `: ${reason}` : "."}` : reason ?? (RUN_ENDINGS[status] ? "" : `It ended ${status.replace(/_/g, " ")}.`)) || null
|
|
13803
14606
|
};
|
|
13804
|
-
|
|
13805
|
-
|
|
13806
|
-
|
|
13807
|
-
|
|
13808
|
-
|
|
13809
|
-
|
|
13810
|
-
cancel: async () => {
|
|
13811
|
-
cancelled = true;
|
|
13812
|
-
agent?.stop();
|
|
13813
|
-
}
|
|
13814
|
-
};
|
|
14607
|
+
if (ending.status === "failed" && ending.reason) report.event({
|
|
14608
|
+
kind: "error",
|
|
14609
|
+
message: clip(ending.reason)
|
|
14610
|
+
});
|
|
14611
|
+
return;
|
|
14612
|
+
}
|
|
13815
14613
|
}
|
|
13816
14614
|
};
|
|
14615
|
+
return {
|
|
14616
|
+
take,
|
|
14617
|
+
/** How agentpipe said the run ended (null: it didn't). */
|
|
14618
|
+
ending: () => ending,
|
|
14619
|
+
flush: () => flush()
|
|
14620
|
+
};
|
|
13817
14621
|
}
|
|
13818
|
-
|
|
13819
|
-
|
|
14622
|
+
/** One stdout line as an event, or null for agentpipe's plain lines ("profile: cached", the step table). */
|
|
14623
|
+
function parseLine(line) {
|
|
14624
|
+
const text = line.trim();
|
|
14625
|
+
if (!text.startsWith("{")) return null;
|
|
14626
|
+
try {
|
|
14627
|
+
const value = JSON.parse(text);
|
|
14628
|
+
if (value && typeof value === "object" && typeof value.kind === "string") return value;
|
|
14629
|
+
} catch {}
|
|
14630
|
+
return null;
|
|
14631
|
+
}
|
|
14632
|
+
/** agentpipe's arguments for a run: the folder, the task, and what it may do (and spend, by default `budgetUsd`). */
|
|
14633
|
+
function agentpipeArgs({ ref, workdir, options }, budgetUsd = 10) {
|
|
14634
|
+
return [
|
|
14635
|
+
"run",
|
|
14636
|
+
workdir,
|
|
14637
|
+
"--from-issue",
|
|
14638
|
+
ref,
|
|
14639
|
+
"--json",
|
|
14640
|
+
...options.pr === "none" ? ["--local"] : options.pr === "ready" ? ["--no-draft"] : ["--draft"],
|
|
14641
|
+
"--budget",
|
|
14642
|
+
String(options.budgetUsd ?? budgetUsd),
|
|
14643
|
+
...options.autonomous ? ["--autonomous"] : []
|
|
14644
|
+
];
|
|
14645
|
+
}
|
|
14646
|
+
/** What agentpipe keeps of the runner's environment, by name. */
|
|
14647
|
+
const KEEP = /* @__PURE__ */ new Set([
|
|
14648
|
+
"PATH",
|
|
14649
|
+
"HOME",
|
|
14650
|
+
"USER",
|
|
14651
|
+
"LOGNAME",
|
|
14652
|
+
"SHELL",
|
|
14653
|
+
"TMPDIR",
|
|
14654
|
+
"LANG",
|
|
14655
|
+
"LANGUAGE",
|
|
14656
|
+
"TZ",
|
|
14657
|
+
"DBUS_SESSION_BUS_ADDRESS",
|
|
14658
|
+
"SSH_AUTH_SOCK",
|
|
14659
|
+
"GIT_SSH_COMMAND",
|
|
14660
|
+
"GITHUB_TOKEN",
|
|
14661
|
+
"HTTPS_PROXY",
|
|
14662
|
+
"HTTP_PROXY",
|
|
14663
|
+
"NO_PROXY",
|
|
14664
|
+
"ALL_PROXY",
|
|
14665
|
+
"https_proxy",
|
|
14666
|
+
"http_proxy",
|
|
14667
|
+
"no_proxy",
|
|
14668
|
+
"all_proxy",
|
|
14669
|
+
"SSL_CERT_FILE",
|
|
14670
|
+
"SSL_CERT_DIR",
|
|
14671
|
+
"NODE_EXTRA_CA_CERTS"
|
|
14672
|
+
]);
|
|
13820
14673
|
/**
|
|
13821
|
-
*
|
|
13822
|
-
*
|
|
13823
|
-
* would still need one (so nothing waits). It ends with a `result` line: the cost, and the outcome shaped by
|
|
13824
|
-
* --json-schema. It loads the folder's CLAUDE.md, settings and MCP servers, as a session there would.
|
|
14674
|
+
* And by prefix: the locale, the XDG folders, Claude's sign-in (ANTHROPIC_API_KEY, CLAUDE_CODE_OAUTH_TOKEN), gh's
|
|
14675
|
+
* (GH_TOKEN, GH_HOST), agentpipe's own settings, and monoban's sign-in for the commands agentpipe runs.
|
|
13825
14676
|
*/
|
|
13826
|
-
|
|
13827
|
-
|
|
13828
|
-
|
|
13829
|
-
|
|
13830
|
-
|
|
13831
|
-
|
|
13832
|
-
|
|
13833
|
-
|
|
13834
|
-
|
|
13835
|
-
|
|
13836
|
-
|
|
13837
|
-
|
|
13838
|
-
|
|
13839
|
-
|
|
13840
|
-
|
|
13841
|
-
|
|
13842
|
-
|
|
13843
|
-
|
|
13844
|
-
|
|
13845
|
-
|
|
13846
|
-
}
|
|
13847
|
-
}
|
|
13848
|
-
/** Why a `result` line says it didn't succeed. */
|
|
13849
|
-
function failureOf(line) {
|
|
13850
|
-
const subtype = line.subtype ?? "";
|
|
13851
|
-
if (subtype.includes("budget")) return "It reached its budget.";
|
|
13852
|
-
if (subtype.includes("max_turns")) return "It reached its turn limit.";
|
|
13853
|
-
const said = typeof line.result === "string" && line.result.trim() ? line.result.trim().split("\n")[0] : null;
|
|
13854
|
-
return `It stopped${subtype && subtype !== "success" ? ` (${subtype.replace(/_/g, " ")})` : ""}${said ? `: ${said}` : "."}`;
|
|
14677
|
+
const KEEP_PREFIXES = [
|
|
14678
|
+
"LC_",
|
|
14679
|
+
"XDG_",
|
|
14680
|
+
"ANTHROPIC_",
|
|
14681
|
+
"CLAUDE_CODE_",
|
|
14682
|
+
"GH_",
|
|
14683
|
+
"AGENTPIPE_",
|
|
14684
|
+
"MONOBAN_"
|
|
14685
|
+
];
|
|
14686
|
+
/**
|
|
14687
|
+
* agentpipe's environment: only what it needs, so the runner's other secrets (a database password, cloud keys, an
|
|
14688
|
+
* npm token) never reach it, nor the commands it runs. MONOBAN_BIN names this monoban, so agentpipe calls back the
|
|
14689
|
+
* one that started it.
|
|
14690
|
+
*/
|
|
14691
|
+
function agentpipeEnv(env, monobanBin) {
|
|
14692
|
+
const kept = {};
|
|
14693
|
+
for (const [name, value] of Object.entries(env)) if (value !== void 0 && (KEEP.has(name) || KEEP_PREFIXES.some((p) => name.startsWith(p)))) kept[name] = value;
|
|
14694
|
+
delete kept.MONOBAN_BIN;
|
|
14695
|
+
if (monobanBin) kept.MONOBAN_BIN = monobanBin;
|
|
14696
|
+
return kept;
|
|
13855
14697
|
}
|
|
13856
|
-
|
|
13857
|
-
|
|
13858
|
-
|
|
13859
|
-
|
|
13860
|
-
|
|
13861
|
-
|
|
14698
|
+
const exec = (command, args, env) => new Promise((resolve) => execFile(command, args, {
|
|
14699
|
+
timeout: 3e4,
|
|
14700
|
+
env
|
|
14701
|
+
}, () => resolve()));
|
|
14702
|
+
/** Stderr's last lines, to say why agentpipe stopped without saying so itself. */
|
|
14703
|
+
const TAIL = 20;
|
|
14704
|
+
function agentpipe({ command = "agentpipe", args = [], spawn: spawn$1 = spawn, execCommand = exec, env: runnerEnv = process.env, monobanBin = null, budgetUsd = 10 } = {}) {
|
|
14705
|
+
const env = agentpipeEnv(runnerEnv, monobanBin);
|
|
13862
14706
|
return {
|
|
13863
|
-
|
|
13864
|
-
|
|
13865
|
-
|
|
13866
|
-
|
|
13867
|
-
|
|
13868
|
-
|
|
13869
|
-
|
|
13870
|
-
|
|
13871
|
-
|
|
13872
|
-
|
|
13873
|
-
|
|
13874
|
-
|
|
13875
|
-
|
|
13876
|
-
|
|
13877
|
-
|
|
13878
|
-
|
|
13879
|
-
|
|
13880
|
-
|
|
13881
|
-
|
|
13882
|
-
|
|
13883
|
-
|
|
13884
|
-
|
|
13885
|
-
|
|
14707
|
+
name: "agentpipe",
|
|
14708
|
+
start(run, report) {
|
|
14709
|
+
let externalId = null;
|
|
14710
|
+
const feed = agentpipeMapper({
|
|
14711
|
+
event: report.event,
|
|
14712
|
+
update: (u) => {
|
|
14713
|
+
if (u.externalId) externalId = u.externalId;
|
|
14714
|
+
report.update(u);
|
|
14715
|
+
}
|
|
14716
|
+
});
|
|
14717
|
+
const tail = [];
|
|
14718
|
+
let child;
|
|
14719
|
+
return {
|
|
14720
|
+
done: new Promise((resolve) => {
|
|
14721
|
+
try {
|
|
14722
|
+
child = spawn$1(command, [...agentpipeArgs(run, budgetUsd), ...args], {
|
|
14723
|
+
cwd: run.workdir,
|
|
14724
|
+
env,
|
|
14725
|
+
detached: true
|
|
14726
|
+
});
|
|
14727
|
+
} catch (err) {
|
|
14728
|
+
resolve({
|
|
14729
|
+
status: "failed",
|
|
14730
|
+
reason: `Couldn't start ${command}: ${err.message}`
|
|
14731
|
+
});
|
|
14732
|
+
return;
|
|
14733
|
+
}
|
|
14734
|
+
let spawnError = null;
|
|
14735
|
+
child.on("error", (err) => {
|
|
14736
|
+
spawnError = err.code === "ENOENT" ? `${command} isn't installed here (or isn't on the runner's PATH).` : `${command} failed: ${err.message}`;
|
|
14737
|
+
});
|
|
14738
|
+
if (child.stdout) createInterface$1({ input: child.stdout }).on("line", (line) => {
|
|
14739
|
+
const event = parseLine(line);
|
|
14740
|
+
if (event) feed.take(event);
|
|
14741
|
+
});
|
|
14742
|
+
if (child.stderr) createInterface$1({ input: child.stderr }).on("line", (line) => {
|
|
14743
|
+
if (!line.trim()) return;
|
|
14744
|
+
tail.push(line.trim());
|
|
14745
|
+
if (tail.length > TAIL) tail.shift();
|
|
14746
|
+
});
|
|
14747
|
+
child.on("close", (code) => {
|
|
14748
|
+
feed.flush();
|
|
14749
|
+
const said = feed.ending();
|
|
14750
|
+
if (said) return resolve(said);
|
|
14751
|
+
if (spawnError) return resolve({
|
|
14752
|
+
status: "failed",
|
|
14753
|
+
reason: spawnError
|
|
14754
|
+
});
|
|
14755
|
+
const last = tail.at(-1);
|
|
14756
|
+
resolve({
|
|
14757
|
+
status: "failed",
|
|
14758
|
+
reason: `${command} stopped (exit code ${code ?? "none"}) without saying how it ended${last ? `: ${last}` : "."}`
|
|
14759
|
+
});
|
|
14760
|
+
});
|
|
14761
|
+
}),
|
|
14762
|
+
cancel: async () => {
|
|
14763
|
+
if (externalId) await execCommand(command, [
|
|
14764
|
+
"cancel",
|
|
14765
|
+
externalId,
|
|
14766
|
+
"--reason",
|
|
14767
|
+
"Cancelled from monoban"
|
|
14768
|
+
], env);
|
|
14769
|
+
else child?.kill("SIGINT");
|
|
13886
14770
|
}
|
|
13887
|
-
}
|
|
13888
|
-
}
|
|
13889
|
-
result: () => ({
|
|
13890
|
-
answer: ended ? answer : lastText,
|
|
13891
|
-
costUsd,
|
|
13892
|
-
tokens: null,
|
|
13893
|
-
failure
|
|
13894
|
-
})
|
|
14771
|
+
};
|
|
14772
|
+
}
|
|
13895
14773
|
};
|
|
13896
14774
|
}
|
|
13897
|
-
const claude = {
|
|
13898
|
-
name: "claude",
|
|
13899
|
-
args: (run, { schema }, extra) => [
|
|
13900
|
-
"-p",
|
|
13901
|
-
"--output-format",
|
|
13902
|
-
"stream-json",
|
|
13903
|
-
"--verbose",
|
|
13904
|
-
"--permission-mode",
|
|
13905
|
-
"auto",
|
|
13906
|
-
"--permission-prompts",
|
|
13907
|
-
"none",
|
|
13908
|
-
"--json-schema",
|
|
13909
|
-
schema,
|
|
13910
|
-
...run.options.budgetUsd !== void 0 ? ["--max-budget-usd", String(run.options.budgetUsd)] : [],
|
|
13911
|
-
...run.options.model ? ["--model", run.options.model] : [],
|
|
13912
|
-
...extra
|
|
13913
|
-
],
|
|
13914
|
-
reader: claudeReader
|
|
13915
|
-
};
|
|
13916
14775
|
//#endregion
|
|
13917
14776
|
//#region src/runner/agents/codex.ts
|
|
13918
14777
|
/** `bash -lc 'pnpm test'` → `pnpm test`: the command inside the shell Codex runs it with. */
|
|
@@ -14020,17 +14879,19 @@ const DEFINITIONS = {
|
|
|
14020
14879
|
agentpipe: { create: (d) => agentpipe({
|
|
14021
14880
|
command: d.command,
|
|
14022
14881
|
args: d.args,
|
|
14023
|
-
env: d.env
|
|
14882
|
+
env: d.env,
|
|
14883
|
+
monobanBin: d.monobanBin,
|
|
14884
|
+
budgetUsd: d.agentpipeBudgetUsd
|
|
14024
14885
|
}) },
|
|
14025
14886
|
claude: {
|
|
14026
14887
|
minimum: CLAUDE_MINIMUM,
|
|
14027
14888
|
update: "claude update",
|
|
14028
|
-
create: ({ allowFullAccess: _, ...d }) => codingAgent({
|
|
14889
|
+
create: ({ allowFullAccess: _, agentpipeBudgetUsd: __, monobanBin: ___, ...d }) => codingAgent({
|
|
14029
14890
|
spec: claude,
|
|
14030
14891
|
...d
|
|
14031
14892
|
})
|
|
14032
14893
|
},
|
|
14033
|
-
codex: { create: ({ allowFullAccess, ...d }) => codingAgent({
|
|
14894
|
+
codex: { create: ({ allowFullAccess, agentpipeBudgetUsd: _, monobanBin: __, ...d }) => codingAgent({
|
|
14034
14895
|
spec: codexSpec({ allowFullAccess }),
|
|
14035
14896
|
...d
|
|
14036
14897
|
}) }
|
|
@@ -14063,13 +14924,15 @@ async function detectAgents(settings, env, version = versionOf) {
|
|
|
14063
14924
|
};
|
|
14064
14925
|
}
|
|
14065
14926
|
/** The adapters for what was found. */
|
|
14066
|
-
function adaptersFor(found, settings, board, env) {
|
|
14927
|
+
function adaptersFor(found, settings, board, env, monobanBin = null) {
|
|
14067
14928
|
return Object.fromEntries(found.map(({ name }) => [name, DEFINITIONS[name].create({
|
|
14068
14929
|
command: settings.commands[name],
|
|
14069
14930
|
args: settings.args[name],
|
|
14070
14931
|
board,
|
|
14071
14932
|
env,
|
|
14072
|
-
allowFullAccess: settings.allowFullAccess
|
|
14933
|
+
allowFullAccess: settings.allowFullAccess,
|
|
14934
|
+
agentpipeBudgetUsd: settings.agentpipeBudgetUsd,
|
|
14935
|
+
monobanBin
|
|
14073
14936
|
})]));
|
|
14074
14937
|
}
|
|
14075
14938
|
//#endregion
|
|
@@ -14115,103 +14978,6 @@ function runBoard(api) {
|
|
|
14115
14978
|
};
|
|
14116
14979
|
}
|
|
14117
14980
|
//#endregion
|
|
14118
|
-
//#region src/runner/config.ts
|
|
14119
|
-
const AGENT_NAMES$1 = Object.keys(AGENTS$1);
|
|
14120
|
-
const isAgent = (name) => AGENT_NAMES$1.includes(name);
|
|
14121
|
-
/** What's wrong with runner.json's contents, or null. */
|
|
14122
|
-
function fileProblem(v) {
|
|
14123
|
-
if (!v || typeof v !== "object" || Array.isArray(v)) return "it should be an object";
|
|
14124
|
-
const f = v;
|
|
14125
|
-
const known = [
|
|
14126
|
-
"name",
|
|
14127
|
-
"pollSeconds",
|
|
14128
|
-
"allow",
|
|
14129
|
-
"confirm",
|
|
14130
|
-
"agents",
|
|
14131
|
-
"adapters"
|
|
14132
|
-
];
|
|
14133
|
-
const unknown = Object.keys(f).find((k) => !known.includes(k));
|
|
14134
|
-
if (unknown) return `${unknown} isn't a setting (${known.join(", ")})`;
|
|
14135
|
-
if (f.name !== void 0 && (typeof f.name !== "string" || !f.name.trim() || f.name.length > 64)) return "name: 1 to 64 characters";
|
|
14136
|
-
if (f.pollSeconds !== void 0 && !(Number.isInteger(f.pollSeconds) && f.pollSeconds >= 1 && f.pollSeconds <= 60)) return "pollSeconds: a whole number of seconds, 1 to 60";
|
|
14137
|
-
if (f.allow !== void 0 && !(Array.isArray(f.allow) && f.allow.every((p) => typeof p === "string" && p.startsWith("/")))) return "allow: a list of absolute paths";
|
|
14138
|
-
if (f.confirm !== void 0 && typeof f.confirm !== "boolean") return "confirm: true or false";
|
|
14139
|
-
if (f.agents !== void 0) {
|
|
14140
|
-
if (!Array.isArray(f.agents) || !f.agents.every((a) => typeof a === "string" && isAgent(a))) return `agents: a list of ${AGENT_NAMES$1.join(", ")}`;
|
|
14141
|
-
}
|
|
14142
|
-
if (f.adapters !== void 0) {
|
|
14143
|
-
if (!f.adapters || typeof f.adapters !== "object" || Array.isArray(f.adapters)) return "adapters: an object";
|
|
14144
|
-
for (const [name, value] of Object.entries(f.adapters)) {
|
|
14145
|
-
if (!isAgent(name)) return `adapters.${name}: monoban doesn't run ${name} (${AGENT_NAMES$1.join(", ")})`;
|
|
14146
|
-
const agent = value ?? {};
|
|
14147
|
-
const settings = name === "codex" ? [
|
|
14148
|
-
"command",
|
|
14149
|
-
"args",
|
|
14150
|
-
"allowFullAccess"
|
|
14151
|
-
] : ["command", "args"];
|
|
14152
|
-
const extra = Object.keys(agent).find((k) => !settings.includes(k));
|
|
14153
|
-
if (extra) return `adapters.${name}.${extra} isn't a setting (${settings.join(", ")})`;
|
|
14154
|
-
if (agent.allowFullAccess !== void 0 && typeof agent.allowFullAccess !== "boolean") return `adapters.${name}.allowFullAccess: true or false`;
|
|
14155
|
-
if (agent.command !== void 0 && (typeof agent.command !== "string" || !agent.command)) return `adapters.${name}.command: a command`;
|
|
14156
|
-
if (agent.args !== void 0 && !(Array.isArray(agent.args) && agent.args.every((a) => typeof a === "string"))) return `adapters.${name}.args: a list of arguments`;
|
|
14157
|
-
}
|
|
14158
|
-
}
|
|
14159
|
-
return null;
|
|
14160
|
-
}
|
|
14161
|
-
const RUNNER_FILE = "runner.json";
|
|
14162
|
-
async function readSettingsFile(dir) {
|
|
14163
|
-
const path = join(dir, RUNNER_FILE);
|
|
14164
|
-
let text;
|
|
14165
|
-
try {
|
|
14166
|
-
text = await readFile(path, "utf8");
|
|
14167
|
-
} catch {
|
|
14168
|
-
return {};
|
|
14169
|
-
}
|
|
14170
|
-
let parsed;
|
|
14171
|
-
try {
|
|
14172
|
-
parsed = JSON.parse(text);
|
|
14173
|
-
} catch {
|
|
14174
|
-
throw new CliError(`${path} isn't JSON.`, EXIT.usage);
|
|
14175
|
-
}
|
|
14176
|
-
const problem = fileProblem(parsed);
|
|
14177
|
-
if (problem) throw new CliError(`${path}: ${problem}.`, EXIT.usage);
|
|
14178
|
-
return parsed;
|
|
14179
|
-
}
|
|
14180
|
-
/** --agents claude,codex. */
|
|
14181
|
-
function agentsFlag(value) {
|
|
14182
|
-
const names = value.split(",").map((a) => a.trim().toLowerCase()).filter(Boolean);
|
|
14183
|
-
const unknown = names.find((a) => !isAgent(a));
|
|
14184
|
-
if (unknown || !names.length) throw new CliError(`--agents takes ${AGENT_NAMES$1.join(", ")} (comma-separated)${unknown ? `, not ${unknown}` : ""}.`, EXIT.usage);
|
|
14185
|
-
return names;
|
|
14186
|
-
}
|
|
14187
|
-
async function runnerSettings(dir, flags, env, hostname) {
|
|
14188
|
-
const file = await readSettingsFile(dir);
|
|
14189
|
-
let pollSeconds = file.pollSeconds ?? 3;
|
|
14190
|
-
if (flags.interval !== void 0) {
|
|
14191
|
-
pollSeconds = Number(flags.interval);
|
|
14192
|
-
if (!Number.isInteger(pollSeconds) || pollSeconds < 1 || pollSeconds > 60) throw new CliError("--interval is how often to ask for work, in seconds: 1 to 60.", EXIT.usage);
|
|
14193
|
-
}
|
|
14194
|
-
const allow = [...file.allow ?? [], ...flags.allow ?? []];
|
|
14195
|
-
const relative = allow.find((p) => !p.startsWith("/"));
|
|
14196
|
-
if (relative) throw new CliError(`--allow takes absolute paths (${relative} isn't one).`, EXIT.usage);
|
|
14197
|
-
const commands = {};
|
|
14198
|
-
const args = {};
|
|
14199
|
-
for (const name of AGENT_NAMES$1) {
|
|
14200
|
-
commands[name] = env[`MONOBAN_${name.toUpperCase()}`] || file.adapters?.[name]?.command || name;
|
|
14201
|
-
args[name] = file.adapters?.[name]?.args ?? [];
|
|
14202
|
-
}
|
|
14203
|
-
return {
|
|
14204
|
-
name: flags.name?.trim() || file.name || hostname,
|
|
14205
|
-
pollSeconds,
|
|
14206
|
-
allow,
|
|
14207
|
-
confirm: flags.confirm ?? file.confirm ?? false,
|
|
14208
|
-
agents: flags.agents !== void 0 ? agentsFlag(flags.agents) : file.agents ?? null,
|
|
14209
|
-
commands,
|
|
14210
|
-
args,
|
|
14211
|
-
allowFullAccess: flags.allowFullAccess ?? file.adapters?.codex?.allowFullAccess ?? false
|
|
14212
|
-
};
|
|
14213
|
-
}
|
|
14214
|
-
//#endregion
|
|
14215
14981
|
//#region src/runner/loop.ts
|
|
14216
14982
|
const sleepFor = (ms, signal) => new Promise((resolve) => {
|
|
14217
14983
|
if (signal.aborted) return resolve();
|
|
@@ -14232,13 +14998,31 @@ const ENDINGS = {
|
|
|
14232
14998
|
async function runRunner(ctx, settings, deps, options = {}) {
|
|
14233
14999
|
const api = apis(ctx).signedIn;
|
|
14234
15000
|
const now = deps.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
|
|
14235
|
-
|
|
15001
|
+
let installed = deps.adapters;
|
|
15002
|
+
let adapters = Object.keys(installed);
|
|
14236
15003
|
const register = () => unwrap(api.POST("/v1/runners", { body: {
|
|
14237
15004
|
name: settings.name,
|
|
14238
15005
|
adapters,
|
|
14239
15006
|
version: VERSION,
|
|
14240
15007
|
pollSeconds: settings.pollSeconds
|
|
14241
15008
|
} }));
|
|
15009
|
+
const redetectMs = deps.redetectMs ?? 6e4;
|
|
15010
|
+
let detectedAt = Date.now();
|
|
15011
|
+
/** Offers the agents installed now, when they changed (registering again tells the board). */
|
|
15012
|
+
const redetect = async () => {
|
|
15013
|
+
if (!deps.redetect || Date.now() - detectedAt < redetectMs) return;
|
|
15014
|
+
detectedAt = Date.now();
|
|
15015
|
+
const next = await deps.redetect().catch(() => installed);
|
|
15016
|
+
const names = Object.keys(next);
|
|
15017
|
+
if (!names.length || names.join() === adapters.join()) return;
|
|
15018
|
+
const added = names.filter((n) => !adapters.includes(n));
|
|
15019
|
+
const gone = adapters.filter((n) => !names.includes(n));
|
|
15020
|
+
installed = next;
|
|
15021
|
+
adapters = names;
|
|
15022
|
+
runner = await register();
|
|
15023
|
+
const said = [added.length && `now offers ${added.join(", ")}`, gone.length && `no longer offers ${gone.join(", ")}`];
|
|
15024
|
+
ctx.err(`Runner ${runner.name} ${said.filter(Boolean).join(" and ")}.`);
|
|
15025
|
+
};
|
|
14242
15026
|
let runner = await register();
|
|
14243
15027
|
ctx.err(`Runner ${runner.name} is online with ${adapters.join(", ")}: waiting for runs (checking every ${settings.pollSeconds}s; Ctrl-C to stop).`);
|
|
14244
15028
|
let active = null;
|
|
@@ -14303,6 +15087,7 @@ async function runRunner(ctx, settings, deps, options = {}) {
|
|
|
14303
15087
|
}
|
|
14304
15088
|
await active?.flush();
|
|
14305
15089
|
if (options.once && !active && (took || !work?.queued.length)) break;
|
|
15090
|
+
if (!active && !stopping) await redetect().catch(() => {});
|
|
14306
15091
|
if (!leave && (!stopping || active)) {
|
|
14307
15092
|
await deps.sleep(settings.pollSeconds * 1e3, wake.signal);
|
|
14308
15093
|
wake = new AbortController();
|
|
@@ -14338,7 +15123,7 @@ async function runRunner(ctx, settings, deps, options = {}) {
|
|
|
14338
15123
|
}, run.version).catch(() => {});
|
|
14339
15124
|
};
|
|
14340
15125
|
if (!ref) return refuse("failed", "Its task was deleted.");
|
|
14341
|
-
const adapter =
|
|
15126
|
+
const adapter = installed[run.adapter];
|
|
14342
15127
|
if (!adapter) return refuse("failed", `${runner.name} can't run ${run.adapter}.`);
|
|
14343
15128
|
const problem = await deps.workdirProblem(run.workdir, run.project);
|
|
14344
15129
|
if (problem) return refuse("failed", problem);
|
|
@@ -14520,13 +15305,17 @@ async function runner(ctx, options, overrides = {}) {
|
|
|
14520
15305
|
const settings = await runnerSettings(configDir(ctx.env), options, ctx.env, deviceName());
|
|
14521
15306
|
const { detect = detectAgents, ...deps } = overrides;
|
|
14522
15307
|
let adapters = deps.adapters;
|
|
15308
|
+
let redetect = deps.redetect;
|
|
14523
15309
|
if (!adapters) {
|
|
14524
15310
|
const env = ctx.env;
|
|
15311
|
+
const board = runBoard(apis(ctx).signedIn);
|
|
15312
|
+
const monobanBin = selfCommand();
|
|
14525
15313
|
const { found, missing } = await detect(settings, env);
|
|
14526
15314
|
if (!found.length) throw new CliError(`No coding agent to run here: ${missing.join("; ")}. Install one (agentpipe, Claude Code or Codex), or set its command in ${configDir(ctx.env)}/runner.json.`, EXIT.usage);
|
|
14527
15315
|
ctx.err(`Agents: ${agentList(found)}.${missing.length ? ` Not offered: ${missing.join("; ")}.` : ""}`);
|
|
14528
15316
|
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.");
|
|
14529
|
-
adapters = adaptersFor(found, settings,
|
|
15317
|
+
adapters = adaptersFor(found, settings, board, env, monobanBin);
|
|
15318
|
+
redetect ??= async () => adaptersFor((await detect(settings, env)).found, settings, board, env, monobanBin);
|
|
14530
15319
|
}
|
|
14531
15320
|
await runRunner(ctx, settings, {
|
|
14532
15321
|
workdirProblem: (workdir, project) => workdirProblem(workdir, project, settings.allow),
|
|
@@ -14536,7 +15325,8 @@ async function runner(ctx, options, overrides = {}) {
|
|
|
14536
15325
|
return () => process.off("SIGINT", handler);
|
|
14537
15326
|
},
|
|
14538
15327
|
...deps,
|
|
14539
|
-
adapters
|
|
15328
|
+
adapters,
|
|
15329
|
+
redetect
|
|
14540
15330
|
}, { once: options.once });
|
|
14541
15331
|
}
|
|
14542
15332
|
const PR_CHOICES = [
|
|
@@ -14864,7 +15654,7 @@ go?"). Once the user agrees:
|
|
|
14864
15654
|
| Command | Does |
|
|
14865
15655
|
| --- | --- |
|
|
14866
15656
|
| \`monoban projects\` | the projects and their keys |
|
|
14867
|
-
| \`monoban list [COLUMN…] [--tag TAG] [--archived]\` | tasks by column (--archived:
|
|
15657
|
+
| \`monoban list [COLUMN…] [--tag TAG] [--archived]\` | tasks by column (--archived: done long ago, or won't do) |
|
|
14868
15658
|
| \`monoban show MON-12\` | one task in full |
|
|
14869
15659
|
| \`monoban log MON-12 [-n COUNT]\` | what happened to it, newest first |
|
|
14870
15660
|
| \`monoban comments MON-12 [-n COUNT]\` | its latest comments |
|
|
@@ -15124,99 +15914,6 @@ end
|
|
|
15124
15914
|
complete -c monoban -f -a '(__monoban_complete)'
|
|
15125
15915
|
`
|
|
15126
15916
|
};
|
|
15127
|
-
const UPGRADE = {
|
|
15128
|
-
brew: {
|
|
15129
|
-
how: "Homebrew",
|
|
15130
|
-
command: "brew upgrade monoban"
|
|
15131
|
-
},
|
|
15132
|
-
binary: {
|
|
15133
|
-
how: "a downloaded binary",
|
|
15134
|
-
command: `download it again: https://github.com/thiagodmont/homebrew-tap/releases/latest`
|
|
15135
|
-
},
|
|
15136
|
-
npx: {
|
|
15137
|
-
how: "npx",
|
|
15138
|
-
command: "npx monoban@latest"
|
|
15139
|
-
},
|
|
15140
|
-
npm: {
|
|
15141
|
-
how: "npm",
|
|
15142
|
-
command: "npm install -g monoban@latest"
|
|
15143
|
-
},
|
|
15144
|
-
pnpm: {
|
|
15145
|
-
how: "pnpm",
|
|
15146
|
-
command: "pnpm add -g monoban@latest"
|
|
15147
|
-
},
|
|
15148
|
-
yarn: {
|
|
15149
|
-
how: "yarn",
|
|
15150
|
-
command: "yarn global add monoban@latest"
|
|
15151
|
-
},
|
|
15152
|
-
bun: {
|
|
15153
|
-
how: "bun",
|
|
15154
|
-
command: "bun add -g monoban@latest"
|
|
15155
|
-
}
|
|
15156
|
-
};
|
|
15157
|
-
/**
|
|
15158
|
-
* Told apart by where it runs from: a binary in a Homebrew Cellar, or the npm package under npx's
|
|
15159
|
-
* cache or a package manager's global folder (npm when it's none of those).
|
|
15160
|
-
*/
|
|
15161
|
-
function installKind(where) {
|
|
15162
|
-
if (where.binary) return where.executable.includes("/Cellar/") ? "brew" : "binary";
|
|
15163
|
-
const script = where.script.replaceAll("\\", "/");
|
|
15164
|
-
if (script.includes("/_npx/")) return "npx";
|
|
15165
|
-
if (/\/\.?pnpm\//.test(script)) return "pnpm";
|
|
15166
|
-
if (script.includes("/.bun/")) return "bun";
|
|
15167
|
-
if (/\/(\.yarn|yarn\/global)\//.test(script)) return "yarn";
|
|
15168
|
-
return "npm";
|
|
15169
|
-
}
|
|
15170
|
-
const real = (path) => {
|
|
15171
|
-
try {
|
|
15172
|
-
return path ? realpathSync(path) : "";
|
|
15173
|
-
} catch {
|
|
15174
|
-
return path ?? "";
|
|
15175
|
-
}
|
|
15176
|
-
};
|
|
15177
|
-
/** This process's install. */
|
|
15178
|
-
const thisInstall = () => installKind({
|
|
15179
|
-
binary: false,
|
|
15180
|
-
executable: real(process.execPath),
|
|
15181
|
-
script: real(process.argv[1])
|
|
15182
|
-
});
|
|
15183
|
-
/** 1.2.10 > 1.2.9; a pre-release counts as its version. */
|
|
15184
|
-
function newer(a, b) {
|
|
15185
|
-
const parts = (v) => v.split(/[-+]/)[0]?.split(".").map(Number) ?? [];
|
|
15186
|
-
const [x, y] = [parts(a), parts(b)];
|
|
15187
|
-
for (let i = 0; i < 3; i++) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (x[i] ?? 0) > (y[i] ?? 0);
|
|
15188
|
-
return false;
|
|
15189
|
-
}
|
|
15190
|
-
/** The latest version on npm (Homebrew and the binaries ship the same releases), or null offline. */
|
|
15191
|
-
async function latestVersion(ctx) {
|
|
15192
|
-
try {
|
|
15193
|
-
const res = await ctx.fetch(new Request("https://registry.npmjs.org/monoban/latest", { signal: AbortSignal.timeout(3e3) }));
|
|
15194
|
-
if (!res.ok) return null;
|
|
15195
|
-
const { version } = await res.json();
|
|
15196
|
-
return typeof version === "string" ? version : null;
|
|
15197
|
-
} catch {
|
|
15198
|
-
return null;
|
|
15199
|
-
}
|
|
15200
|
-
}
|
|
15201
|
-
/** `monoban upgrade`: whether there's a newer version, and the command that installs it here. */
|
|
15202
|
-
async function upgrade(ctx, options, kind = thisInstall()) {
|
|
15203
|
-
const latest = await latestVersion(ctx);
|
|
15204
|
-
const { how, command } = UPGRADE[kind];
|
|
15205
|
-
const outdated = latest !== null && newer(latest, "1.5.1");
|
|
15206
|
-
if (options.json) {
|
|
15207
|
-
ctx.out(JSON.stringify({
|
|
15208
|
-
version: VERSION,
|
|
15209
|
-
latest,
|
|
15210
|
-
outdated,
|
|
15211
|
-
installedWith: kind,
|
|
15212
|
-
command
|
|
15213
|
-
}, null, 2));
|
|
15214
|
-
return;
|
|
15215
|
-
}
|
|
15216
|
-
if (latest === null) ctx.out(`You have monoban ${VERSION} (installed with ${how}). To get the latest: ${command}`);
|
|
15217
|
-
else if (outdated) ctx.out(`monoban ${latest} is out (you have ${VERSION}). To upgrade: ${command}`);
|
|
15218
|
-
else ctx.out(`monoban ${VERSION} is the latest.`);
|
|
15219
|
-
}
|
|
15220
15917
|
//#endregion
|
|
15221
15918
|
//#region src/program.ts
|
|
15222
15919
|
/** The command tree. Each action gets the run's Context. */
|
|
@@ -15231,7 +15928,7 @@ function program(ctx) {
|
|
|
15231
15928
|
cli.command("projects").description("List your projects and their keys").addOption(json()).action(async (options) => projects(await ctx(), options));
|
|
15232
15929
|
cli.command("link").argument("[key]", "the project (else the one already linked, or your only one)").description("Link a project to this clone's GitHub repository, so commands here use it").addOption(json()).action(async (key, options) => link(await ctx(), key, options));
|
|
15233
15930
|
cli.command("unlink").description("Undo `monoban link` for this clone's repository").addOption(json()).action(async (options) => unlink(await ctx(), options));
|
|
15234
|
-
cli.command("list").alias("ls").argument("[columns...]", "only these columns (any case; a prefix works: `back`, `inp`)").description("Show the board's tasks by column").option("-t, --tag <tag>", "only tasks with this tag").option("--archived", "the archived tasks instead (done a while ago,
|
|
15931
|
+
cli.command("list").alias("ls").argument("[columns...]", "only these columns (any case; a prefix works: `back`, `inp`)").description("Show the board's tasks by column").option("-t, --tag <tag>", "only tasks with this tag").option("--archived", "the archived tasks instead (done a while ago, or won't do), with why").addOption(project()).addOption(json()).action(async (columns, options) => list(await ctx(), columns, options));
|
|
15235
15932
|
cli.command("show").argument("<task>", "like MON-12").description("Show a task: title, column, tags, checklist and description").addOption(json()).action(async (ref, options) => show(await ctx(), ref, options));
|
|
15236
15933
|
cli.command("log").argument("<task>", "like MON-12").description("Show what happened to a task, newest first: created, moved, edited, tags, links").option("-n, --number <count>", "how many events (default 20)").addOption(json()).action(async (ref, options) => log(await ctx(), ref, options));
|
|
15237
15934
|
cli.command("comment").argument("<task>", "like MON-12").argument("<text...>", "what to say, in Markdown (- reads it from stdin)").description("Comment on a task").addOption(json()).action(async (ref, words, options) => comment(await ctx(), ref, words, options));
|
|
@@ -15277,6 +15974,21 @@ machine allows a run to turn it off. Settings can also go in runner.json in the
|
|
|
15277
15974
|
cli.command("setup").addArgument(new Argument("<agent>", "which agent: claude (Claude Code) or codex").choices(AGENTS)).description("Teach a coding agent monoban: a skill to plan work as tasks (phases as tags) and keep them current").option("--project", "install it in this repository (to commit), not for you in every one").option("--print", "print the skill instead of installing it").option("--remove", "remove the skill").option("-f, --force", "replace (or remove) a skill monoban didn't write").addOption(json()).addHelpText("after", `
|
|
15278
15975
|
It goes in ~/.claude/skills/monoban (Claude Code) or ~/.agents/skills/monoban (Codex); with --project,
|
|
15279
15976
|
in .claude/skills or .agents/skills at the top of this repository. Run it again after upgrading monoban.`).action(async (agent, options) => setup(await ctx(), agent, options));
|
|
15977
|
+
const pipe = cli.command("agentpipe").description("Install agentpipe for the runner, and run it: install, status, update, login, uninstall").argument("[args...]", "after --: arguments for agentpipe itself (monoban agentpipe -- doctor .)").addHelpText("after", `
|
|
15978
|
+
agentpipe is installed, CLI only, in monoban's own folder ($XDG_DATA_HOME/monoban, or ~/.local/share/monoban),
|
|
15979
|
+
at the version this monoban comes with: every file it downloads is checked against a SHA-256 monoban pins.
|
|
15980
|
+
\`monoban runner\` offers it within a minute of installing. It needs macOS, or Linux with glibc.`).action(async (args) => {
|
|
15981
|
+
if (!args.length) return pipe.help();
|
|
15982
|
+
process.exitCode = await runAgentpipe(await ctx(), args);
|
|
15983
|
+
});
|
|
15984
|
+
pipe.command("install").description("Install the agentpipe this monoban comes with (downloads Python 3.12, and uv if needed)").option("--force", "install it again, over the same version").action(async (options) => installAgentpipe(await ctx(), options));
|
|
15985
|
+
pipe.command("status").description("Whether agentpipe is installed, and whether this monoban comes with a newer one").addOption(json()).action(async (options) => status(await ctx(), options));
|
|
15986
|
+
pipe.command("update").description("Install the agentpipe this monoban comes with, over an older one").action(async () => update(await ctx()));
|
|
15987
|
+
pipe.command("login").description("Sign agentpipe in to Claude (your Claude account), on this terminal").action(async () => {
|
|
15988
|
+
process.exitCode = await runAgentpipe(await ctx(), ["login"]);
|
|
15989
|
+
});
|
|
15990
|
+
pipe.command("uninstall").description("Remove the agentpipe monoban installed (its runs and settings in ~/.agentpipe stay)").option("-y, --yes", "don't ask").action(async (options) => uninstall(await ctx(), options));
|
|
15991
|
+
cli.command("doctor").description("Check what monoban and its runner need here (sign-in, agents, git, gh), and how to fix what's missing").addOption(json()).action(async (options) => doctor(await ctx(), options));
|
|
15280
15992
|
cli.command("upgrade").description("Check for a newer version, and say how to install it (Homebrew, npm…)").addOption(json()).action(async (options) => upgrade(await ctx(), options));
|
|
15281
15993
|
cli.command("completion").addArgument(new Argument("<shell>", "bash, zsh or fish").choices(SHELLS)).description("Print the script that makes Tab complete commands, projects, columns, tasks and tags").addHelpText("after", `
|
|
15282
15994
|
Load it in your shell:
|