monoban 1.11.0 → 1.12.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.
Files changed (2) hide show
  1. package/dist/index.mjs +265 -27
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -5954,6 +5954,8 @@ const LOOP_DEFAULTS = {
5954
5954
  merge: true,
5955
5955
  deliverMaxOpen: 1,
5956
5956
  checksMinutes: 60,
5957
+ /** deliver: a run decides the questions only you can settle on its own, at once (no wait for your answer). */
5958
+ askMinutes: 0,
5957
5959
  /** deliver: agentpipe's own tier for its review step. */
5958
5960
  reviewTier: null,
5959
5961
  scavengeMaxOpen: 5
@@ -6365,7 +6367,8 @@ const PROBLEM_CODES = [
6365
6367
  "email_not_sent",
6366
6368
  "loops_off",
6367
6369
  "nothing_to_do",
6368
- "pr_open"
6370
+ "pr_open",
6371
+ "too_late"
6369
6372
  ];
6370
6373
  const CODES = new Set(PROBLEM_CODES);
6371
6374
  const isString = (v) => typeof v === "string";
@@ -6453,7 +6456,8 @@ const RUN_EVENT_KINDS = [
6453
6456
  "question",
6454
6457
  "warning",
6455
6458
  "error",
6456
- "activity"
6459
+ "activity",
6460
+ "answer"
6457
6461
  ];
6458
6462
  /** Where a run works. Only on the runner's machine for now; remote (a fresh clone) comes later. */
6459
6463
  const RUN_MODES = ["local"];
@@ -6469,6 +6473,10 @@ const RUN_LIMITS = {
6469
6473
  eventsPerBatch: 200,
6470
6474
  eventMessage: 2e3,
6471
6475
  reason: 1e3,
6476
+ /** An answer to a run's question (the check on task_run_answers.answer). */
6477
+ answer: 2e3,
6478
+ /** Answers per run (guard_task_run_answer). */
6479
+ answersPerRun: 100,
6472
6480
  workdir: 1024,
6473
6481
  runnerName: 64,
6474
6482
  runnersPerUser: 20
@@ -6485,6 +6493,8 @@ function formatDuration(ms) {
6485
6493
  if (minutes < 60) return `${minutes}m${String(seconds % 60).padStart(2, "0")}`;
6486
6494
  return `${Math.floor(minutes / 60)}h${String(minutes % 60).padStart(2, "0")}`;
6487
6495
  }
6496
+ /** A question's id, as agentpipe names it (`plan-2`): never an option (the check on task_run_answers.question_id). */
6497
+ const QUESTION_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,63}$/;
6488
6498
  /** A step's mark in a list: ✓ ok, ● running, ✗ failed, – skipped, ■ cancelled, ? needs you. */
6489
6499
  const STEP_MARKS = {
6490
6500
  running: "●",
@@ -7022,6 +7032,13 @@ const loopCommon = {
7022
7032
  /** Runs in a row that failed or need you before it pauses itself. */
7023
7033
  pauseAfter: wholeBetween(LOOP_LIMITS.pauseAfter)
7024
7034
  };
7035
+ /** ASK_MINUTES, one literal each (`z.literal` of a list keeps only the first in the OpenAPI document). */
7036
+ const ASK_MINUTES_SCHEMA = union([
7037
+ literal(0),
7038
+ literal(5),
7039
+ literal(15),
7040
+ literal(30)
7041
+ ]);
7025
7042
  const deliverFields = {
7026
7043
  ...loopCommon,
7027
7044
  /** The column it takes tasks from. */
@@ -7035,7 +7052,9 @@ const deliverFields = {
7035
7052
  /** How long `checks` waits for CI, in minutes. */
7036
7053
  checksMinutes: wholeBetween(LOOP_LIMITS.checksMinutes),
7037
7054
  /** The agentpipe tier its review step runs on (`--tier`); null: agentpipe's own. */
7038
- reviewTier: string().regex(TIER_NAME, "A tier's name, like light").nullable()
7055
+ reviewTier: string().regex(TIER_NAME, "A tier's name, like light").nullable(),
7056
+ /** How long a run waits for your answer to a question only you can settle, in minutes; 0: it doesn't wait. */
7057
+ askMinutes: ASK_MINUTES_SCHEMA
7039
7058
  };
7040
7059
  const scavengeFields = {
7041
7060
  ...loopCommon,
@@ -7061,7 +7080,8 @@ const DeliverOptionsSchema = strictObject({
7061
7080
  merge: deliverFields.merge.default(LOOP_DEFAULTS.merge),
7062
7081
  maxOpen: deliverFields.maxOpen.default(LOOP_DEFAULTS.deliverMaxOpen),
7063
7082
  checksMinutes: deliverFields.checksMinutes.default(LOOP_DEFAULTS.checksMinutes),
7064
- reviewTier: deliverFields.reviewTier.default(LOOP_DEFAULTS.reviewTier)
7083
+ reviewTier: deliverFields.reviewTier.default(LOOP_DEFAULTS.reviewTier),
7084
+ askMinutes: deliverFields.askMinutes.default(LOOP_DEFAULTS.askMinutes)
7065
7085
  }).refine(budgetFits, {
7066
7086
  message: BUDGET_FITS,
7067
7087
  path: ["budgetUsd"]
@@ -7210,6 +7230,16 @@ const RunProjectSchema = object({
7210
7230
  repo: string().nullable()
7211
7231
  }).meta({ id: "RunProject" });
7212
7232
  const RunToStartSchema = TaskRunSchema.extend({ project: RunProjectSchema }).meta({ id: "RunToStart" });
7233
+ string().regex(QUESTION_ID, "A question's id, like plan-2").meta({ example: "plan-2" });
7234
+ union([strictObject({ text: text().min(1, "Required").max(RUN_LIMITS.answer).regex(/^[^\u0001-\u0008\u000b\u000c\u000e-\u001f\u007f]*$/, "Lines and tabs only, no other control characters") }), strictObject({ skip: literal(true) })]).meta({ id: "RunAnswerCreate" });
7235
+ /** An answer you sent to a run's question: your words, or null for "you decide". What came of it is the run's events. */
7236
+ const RunAnswerSchema = object({
7237
+ id: IdSchema,
7238
+ runId: IdSchema,
7239
+ questionId: string(),
7240
+ text: string().nullable(),
7241
+ createdAt: Timestamp
7242
+ }).meta({ id: "RunAnswer" });
7213
7243
  /** Run an agent on a task, on one of your runners. */
7214
7244
  /** An absolute path on a runner's machine. */
7215
7245
  const Workdir = string().trim().min(1, "Required").max(RUN_LIMITS.workdir).refine(isAbsolutePath, "An absolute path, like /Users/you/code/project").meta({ pattern: "^/" });
@@ -7293,7 +7323,12 @@ object({
7293
7323
  loopId: IdSchema,
7294
7324
  workdir: string(),
7295
7325
  project: RunProjectSchema
7296
- }).meta({ id: "LoopWaiting" })).optional()
7326
+ }).meta({ id: "LoopWaiting" })).optional(),
7327
+ /**
7328
+ * Answers to its running runs' questions it hasn't said what came of yet (no `answer` event names them), oldest
7329
+ * first: it hands each to agentpipe (`agentpipe answer`) and reports the outcome (MON-259).
7330
+ */
7331
+ answers: array(RunAnswerSchema).optional()
7297
7332
  }).meta({ id: "RunnerWork" });
7298
7333
  /** At least one option, or the patch would change nothing (the refine, for JSON Schema: minProperties). */
7299
7334
  const someOption = (o) => Object.keys(o).length > 0;
@@ -8142,7 +8177,7 @@ function archivedByTime(task, archiveAfterDays, now = Date.now()) {
8142
8177
  }
8143
8178
  // src/version.ts
8144
8179
  /** This CLI's version, from package.json (set at build time by tsdown, and by vitest in tests). */
8145
- const VERSION = "1.11.0";
8180
+ const VERSION = "1.12.0";
8146
8181
  /** Sent as X-Monoban-Client, and shown in Settings › CLI sessions. */
8147
8182
  const CLIENT = `cli/${VERSION}`;
8148
8183
  // src/api.ts
@@ -11687,8 +11722,8 @@ const RELEASES = `https://github.com/thiagodmont/homebrew-tap/releases`;
11687
11722
  * agentpipe comes with a new monoban: change these three lines (from the release's checksums.txt) and release.
11688
11723
  */
11689
11724
  const AGENTPIPE = {
11690
- version: "0.10.0",
11691
- wheelSha256: "19f73117601ab8dabc8caabf63f6777c8eecf114e7e11acea2d6b40b653200d4",
11725
+ version: "0.11.0",
11726
+ wheelSha256: "7f6920a517bdd8f45f3943fe975b839b36b5a330a89434f62c8ef074ccaa6d6a",
11692
11727
  requirementsSha256: "41a8d073b0087efb80efafeb6a2b4750340d0f64920159cd4c723ed9167d0a98"
11693
11728
  };
11694
11729
  const agentpipeWheel = (version) => `agentpipe-${version}-py3-none-any.whl`;
@@ -11802,7 +11837,7 @@ async function latestVersion(ctx) {
11802
11837
  async function upgrade(ctx, options, kind = thisInstall()) {
11803
11838
  const latest = await latestVersion(ctx);
11804
11839
  const { how, command } = UPGRADE[kind];
11805
- const outdated = latest !== null && newer(latest, "1.11.0");
11840
+ const outdated = latest !== null && newer(latest, "1.12.0");
11806
11841
  if (options.json) {
11807
11842
  ctx.out(JSON.stringify({
11808
11843
  version: VERSION,
@@ -12450,6 +12485,20 @@ function agentpipeMapper(report) {
12450
12485
  /** `scout --track`: the tasks its `file` step filed (their refs, else their URLs), and `run.end`'s counts. */
12451
12486
  const filed = [];
12452
12487
  let counts = null;
12488
+ /** A window open for your answers (`run --ask-window`): when it closes, and the questions it still waits on. */
12489
+ let asking = null;
12490
+ /** The run's "now" while the window is open: the time it closes in `data` (each reader says it in their own words). */
12491
+ const waiting = (window, step, at) => report.event({
12492
+ kind: "activity",
12493
+ ...step && { step },
12494
+ message: `Waiting for your answer until ${window.until}`,
12495
+ data: {
12496
+ waitingUntil: window.until,
12497
+ questions: window.open.size,
12498
+ ids: [...window.open].join(",")
12499
+ },
12500
+ ...at && { at }
12501
+ });
12453
12502
  const spent = () => report.update({ costUsd: Math.round((total + shipped) * 1e4) / 1e4 });
12454
12503
  const flush = (cost) => {
12455
12504
  if (!pending) return;
@@ -12687,6 +12736,44 @@ function agentpipeMapper(report) {
12687
12736
  });
12688
12737
  return;
12689
12738
  }
12739
+ case "question.prompted": {
12740
+ const seconds = num(d.timeout_s) ?? 0;
12741
+ const ids = Array.isArray(d.ids) ? d.ids.flatMap((id) => str(id) ? [str(id)] : []) : [];
12742
+ if (seconds <= 0 || !ids.length) return;
12743
+ const from = Date.parse(at ?? "");
12744
+ asking = {
12745
+ until: new Date((Number.isNaN(from) ? Date.now() : from) + seconds * 1e3).toISOString(),
12746
+ open: new Set(ids)
12747
+ };
12748
+ waiting(asking, step, at);
12749
+ return;
12750
+ }
12751
+ case "question.settled": {
12752
+ const id = str(d.id);
12753
+ if (!asking || !id || !asking.open.delete(id)) return;
12754
+ if (asking.open.size) {
12755
+ waiting(asking, step, at);
12756
+ return;
12757
+ }
12758
+ asking = null;
12759
+ report.event({
12760
+ kind: "activity",
12761
+ ...step && { step },
12762
+ message: "Answered: it goes on",
12763
+ ...at && { at }
12764
+ });
12765
+ return;
12766
+ }
12767
+ case "question.timeout":
12768
+ if (!asking) return;
12769
+ asking = null;
12770
+ report.event({
12771
+ kind: "activity",
12772
+ ...step && { step },
12773
+ message: "No answer came: it decides on its own",
12774
+ ...at && { at }
12775
+ });
12776
+ return;
12690
12777
  case "error": {
12691
12778
  const text = str(d.message) ?? str(d.kind) ?? "Something went wrong.";
12692
12779
  report.event({
@@ -12798,7 +12885,12 @@ function agentpipeMapper(report) {
12798
12885
  /** What `scout --track` filed (refs, in order), and the numbers behind how it ended (`run.end`'s counts). */
12799
12886
  filed: () => [...filed],
12800
12887
  counts: () => counts,
12801
- flush: () => flush()
12888
+ flush: () => flush(),
12889
+ /**
12890
+ * Whether the run waits for an answer to this question now, with a moment to spare: agentpipe 0.10.0's `answer`
12891
+ * doesn't check, and settles it whenever it comes, over what the run decided once its window closed.
12892
+ */
12893
+ waitsFor: (questionId, now = Date.now()) => Boolean(asking?.open.has(questionId) && Date.parse(asking.until) - now > 3e3)
12802
12894
  };
12803
12895
  }
12804
12896
  /** One stdout line as an event, or null for agentpipe's plain lines ("profile: cached", the step table). */
@@ -12897,6 +12989,42 @@ function agentpipeCommand({ command = "agentpipe", args, cwd, env, monobanBin =
12897
12989
  }
12898
12990
  });
12899
12991
  }
12992
+ /**
12993
+ * Runs a short agentpipe command (`answer`) to its end: how it ended, and what it printed, on one line (its reason
12994
+ * first, then a hint; rich prints to stdout, and wraps it at the terminal's width unless told a wide one).
12995
+ */
12996
+ const execOutput = (command, args, env) => new Promise((resolve) => execFile(command, args, {
12997
+ timeout: 3e4,
12998
+ env: {
12999
+ ...env,
13000
+ COLUMNS: "1000"
13001
+ },
13002
+ maxBuffer: 1048576
13003
+ }, (err, stdout, stderr) => {
13004
+ const said = `${stdout}\n${stderr}`.split("\n").map((l) => l.trim()).filter(Boolean).join(" ");
13005
+ resolve({
13006
+ code: err ? typeof err.code === "number" ? err.code : null : 0,
13007
+ said: said || null
13008
+ });
13009
+ }));
13010
+ /**
13011
+ * `agentpipe answer` for an answer you sent from the browser (MON-259): your words after `--`, so nothing in them is
13012
+ * an option (`--agent-answer` is words here), or `--skip` for "you decide". An argv, never a shell.
13013
+ */
13014
+ function answerArgs(runId, questionId, text) {
13015
+ return text === null ? [
13016
+ "answer",
13017
+ runId,
13018
+ questionId,
13019
+ "--skip"
13020
+ ] : [
13021
+ "answer",
13022
+ runId,
13023
+ questionId,
13024
+ "--",
13025
+ text
13026
+ ];
13027
+ }
12900
13028
  /** Runs a short agentpipe command (`cancel`) to its end, whatever it says. */
12901
13029
  const exec = (command, args, env) => new Promise((resolve) => execFile(command, args, {
12902
13030
  timeout: 3e4,
@@ -18126,6 +18254,11 @@ var en_US_default = {
18126
18254
  "delete": {
18127
18255
  "label": "Delete {name}",
18128
18256
  "help": "Delete loop"
18257
+ },
18258
+ "accept": {
18259
+ "label": "Accept {ref}'s {count, plural, one {decision} other {# decisions}} and merge",
18260
+ "help": "Accept the decisions a run's merge waits on",
18261
+ "keywords": "accept ratify decision decisions approve merge provisional"
18129
18262
  }
18130
18263
  },
18131
18264
  archive: {
@@ -18259,6 +18392,10 @@ var en_US_default = {
18259
18392
  "reviewTier": "Review on",
18260
18393
  "reviewTierHint": "The models agentpipe reviews the pull request with: its tier (--tier).",
18261
18394
  "reviewTierDefault": "agentpipe's own tier",
18395
+ "askMinutes": "Wait for your answers",
18396
+ "askMinutesHint": "A question only you can settle waits this long for your answer before the run decides it on its own. While it waits, the run keeps its worktree and its runner.",
18397
+ "askNever": "Don't wait: it decides on its own",
18398
+ "askFor": "{minutes} minutes",
18262
18399
  "focus": "What to look for",
18263
18400
  "focusPlaceholder": "Tests that fail now and then, and why",
18264
18401
  "filesIn": "Files tasks in",
@@ -18271,7 +18408,7 @@ var en_US_default = {
18271
18408
  "budgetUsdPerDay": "Budget per day (US$)",
18272
18409
  "pauseAfter": "Pause after runs in a row",
18273
18410
  "summary": {
18274
- "deliver": "Every {interval}, on {runner}, it takes {tagged, select, yes {the tasks tagged #{tag} in {column}} other {every task in {column}}}, one at a time, up to {perDay} a day, and opens a pull request for each. {merge, select, yes {It merges each one when its checks pass.} other {It leaves each one for you to merge.}} It stops taking tasks while {maxOpen, plural, one {# pull request waits} other {# pull requests wait}} for you, spends at most {budget} a run and {budgetDay} a day, and pauses after {pauseAfter, plural, one {a run that fails or needs you} other {# runs in a row that fail or need you}}.",
18411
+ "deliver": "Every {interval}, on {runner}, it takes {tagged, select, yes {the tasks tagged #{tag} in {column}} other {every task in {column}}}, one at a time, up to {perDay} a day, and opens a pull request for each. {merge, select, yes {It merges each one when its checks pass.} other {It leaves each one for you to merge.}} It stops taking tasks while {maxOpen, plural, one {# pull request waits} other {# pull requests wait}} for you, spends at most {budget} a run and {budgetDay} a day, and pauses after {pauseAfter, plural, one {a run that fails or needs you} other {# runs in a row that fail or need you}}.{askMinutes, plural, =0 {} other { It waits up to # minutes for your answer to a question only you can settle.}}",
18275
18412
  "scavenge": "Every {interval}, on {runner}, it looks for: {focus}. It files what it finds in {column}, tagged #{tag}, and stops filing while {maxOpen, plural, one {# of those tasks is} other {# of those tasks are}} open. It spends at most {budget} a run and {budgetDay} a day, and pauses after {pauseAfter, plural, one {a run that fails or needs you} other {# runs in a row that fail or need you}}.",
18276
18413
  "incomplete": "Fill in the fields above to see what the loop will do."
18277
18414
  },
@@ -18321,7 +18458,17 @@ var en_US_default = {
18321
18458
  "queued": "{name} runs at its runner's next check-in.",
18322
18459
  "deleted": "Deleted {name}.",
18323
18460
  "failed": "That didn't work: try again.",
18324
- "continued": "{ref} continues from {step} at its runner's next check-in."
18461
+ "continued": "{ref} continues from {step} at its runner's next check-in.",
18462
+ "accepted": "{ref} merges at its runner's next check-in, with {count, plural, one {the decision} other {the # decisions}} accepted."
18463
+ },
18464
+ decisions: {
18465
+ "label": "{ref}'s merge waits on {count, plural, one {a decision} other {# decisions}} the agent made on its own",
18466
+ "why": "The agent decided without asking anyone. Read them against the <pr>pull request</pr> at {commit}: accepting them lets it merge that commit, not one pushed after.",
18467
+ "answer": "Its answer:",
18468
+ "accept": "{count, plural, one {Accept it and merge} other {Accept all # and merge}}",
18469
+ "paused": "The loop is paused: resume it, then accept them here.",
18470
+ "hint": "A run continues from merge at the runner's next check-in: it accepts them with agentpipe ratify, then merges. If the branch moved since, it waits for you again.",
18471
+ "accepting": "It accepts {count, plural, one {# decision} other {# decisions}} read at {commit}, then merges."
18325
18472
  }
18326
18473
  },
18327
18474
  notes: {
@@ -18550,7 +18697,8 @@ var en_US_default = {
18550
18697
  pr_open: "This task's pull request may still be open: continue it from a step, or close it first.",
18551
18698
  unreachable: "Couldn't reach monoban. Try again.",
18552
18699
  unreachableShort: "Couldn't reach monoban.",
18553
- cantDeleteAccount: "Couldn't delete your account. Try again."
18700
+ cantDeleteAccount: "Couldn't delete your account. Try again.",
18701
+ too_late: "Too late: the run no longer waits for that answer. It decided on its own; accept or change what it decided."
18554
18702
  },
18555
18703
  projects: {
18556
18704
  empty: {
@@ -18760,6 +18908,7 @@ var en_US_default = {
18760
18908
  "noneYet": "none yet",
18761
18909
  "none": "none",
18762
18910
  "now": "now",
18911
+ "waitingForAnswer": "Waiting for your {count, plural, one {answer} other {answers to # questions}} until {time}",
18763
18912
  "reported": "What it reported",
18764
18913
  "yoursToDecide": "only you can decide this",
18765
18914
  "latest": "latest",
@@ -21581,7 +21730,8 @@ function options(run) {
21581
21730
  const o = run.plan.options;
21582
21731
  return {
21583
21732
  checksMinutes: o.checksMinutes ?? LOOP_DEFAULTS.checksMinutes,
21584
- reviewTier: o.reviewTier ?? null
21733
+ reviewTier: o.reviewTier ?? null,
21734
+ askMinutes: o.askMinutes ?? LOOP_DEFAULTS.askMinutes
21585
21735
  };
21586
21736
  }
21587
21737
  /** The loop's review tier, if it names one: the preflight checks the folder's agentpipe has it. */
@@ -21589,11 +21739,14 @@ const reviewTierOf = (run) => options(run).reviewTier;
21589
21739
  /** Money as agentpipe takes it: dollars, to the cent. */
21590
21740
  const usd = (n) => (Math.floor(n * 100) / 100).toFixed(2);
21591
21741
  /**
21592
- * `agentpipe run` on the run's task: always `--autonomous` (nobody is there to answer), from an up-to-date base
21593
- * (`--fresh-base`), opening a draft pull request (`checks` marks it ready once it's green), on what is left of the
21594
- * budget. The dry run is the same command with `--dry-run`, so it checks what the run will do.
21742
+ * `agentpipe run` on the run's task: always `--autonomous` (it never stops to ask in a terminal nobody reads), from
21743
+ * an up-to-date base (`--fresh-base`), opening a draft pull request (`checks` marks it ready once it's green), on
21744
+ * what is left of the budget. A loop that waits for your answers (`askMinutes`) holds the questions only you can
21745
+ * settle open that long first (`--ask-window`, AGE-202); otherwise agentpipe decides them at once. The dry run is the
21746
+ * same command with `--dry-run`, so it checks what the run will do.
21595
21747
  */
21596
21748
  function implementArgs(run, budgetUsd) {
21749
+ const { askMinutes } = options(run);
21597
21750
  return [
21598
21751
  "run",
21599
21752
  run.workdir,
@@ -21604,9 +21757,12 @@ function implementArgs(run, budgetUsd) {
21604
21757
  "--fresh-base",
21605
21758
  "--draft",
21606
21759
  "--budget",
21607
- usd(budgetUsd)
21760
+ usd(budgetUsd),
21761
+ ...askMinutes > 0 ? ["--ask-window", String(askMinutes * 60)] : []
21608
21762
  ];
21609
21763
  }
21764
+ /** Whether the run's preview is implement's dry run: a run with its task that doesn't only merge. */
21765
+ const previewed = (run) => Boolean(run.ref) && run.plan.from !== "merge";
21610
21766
  /** `agentpipe review` on the pull request, fixing what it finds, on the loop's tier when it names one. */
21611
21767
  function reviewArgs(run, pr, budgetUsd) {
21612
21768
  const tier = options(run).reviewTier;
@@ -21786,8 +21942,9 @@ const deliver = {
21786
21942
  })
21787
21943
  }
21788
21944
  },
21789
- dryRun: (run) => run.ref && run.plan.from !== "merge" ? [...implementArgs(run, run.budgetUsd), "--dry-run"] : null,
21945
+ dryRun: (run) => previewed(run) ? [...implementArgs(run, run.budgetUsd), "--dry-run"] : null,
21790
21946
  tier: (run) => run.plan.from ? null : reviewTierOf(run),
21947
+ needs: (run) => previewed(run) && options(run).askMinutes > 0 ? ["run.ask_window"] : [],
21791
21948
  finished: ({ pr, last }) => {
21792
21949
  if (!pr) return null;
21793
21950
  if (last?.step === "merge" && last.status === "ok") return last.message ?? "Merged.";
@@ -21985,6 +22142,7 @@ function runRecipe(name, run, report, deps) {
21985
22142
  const feed = agentpipeMapper({
21986
22143
  event: (e) => {
21987
22144
  if (e.kind === "pr_opened" && known(e.data?.url)) return;
22145
+ if (e.kind === "activity") deps.onWaiting?.(Boolean(e.data?.waitingUntil));
21988
22146
  report.event({
21989
22147
  ...e,
21990
22148
  ...e.step !== void 0 && e.step !== null && { step: innerStep(outer, e.step) },
@@ -22047,7 +22205,8 @@ function runRecipe(name, run, report, deps) {
22047
22205
  process: started,
22048
22206
  externalId: null,
22049
22207
  shipping,
22050
- finishes: finishing
22208
+ finishes: finishing,
22209
+ waitsFor: feed.waitsFor
22051
22210
  };
22052
22211
  if (cancelled && !finishing) (shipping() ? started.terminate : started.interrupt)();
22053
22212
  const exit = await started.done;
@@ -22146,6 +22305,27 @@ function runRecipe(name, run, report, deps) {
22146
22305
  status: "failed",
22147
22306
  reason: clip(`The run stopped: ${err.message}`, 1e3)
22148
22307
  })),
22308
+ /**
22309
+ * Hands an answer you sent from the browser to agentpipe, while the command running now waits for it (MON-259),
22310
+ * and says what came of it. Not once it stopped waiting: agentpipe would take it over what it decided.
22311
+ */
22312
+ answer: async (a) => {
22313
+ const now = current;
22314
+ if (!now?.externalId || !now.waitsFor(a.questionId)) return {
22315
+ outcome: "too_late",
22316
+ message: `Too late: the run no longer waited for an answer to ${a.questionId}.`
22317
+ };
22318
+ const env = agentpipeEnv(deps.env, deps.monobanBin);
22319
+ const { code, said } = await (deps.execOutput ?? execOutput)(deps.command, answerArgs(now.externalId, a.questionId, a.text), env);
22320
+ if (code === 0) return {
22321
+ outcome: "reached",
22322
+ message: a.text === null ? `It decides ${a.questionId} on its own, as you asked.` : `Your answer to ${a.questionId} reached the run.`
22323
+ };
22324
+ return {
22325
+ outcome: "refused",
22326
+ message: clip(`agentpipe didn't take your answer to ${a.questionId}: ${said ?? `exit code ${code ?? "none"}`}`, 1e3)
22327
+ };
22328
+ },
22149
22329
  cancel: async () => {
22150
22330
  cancelled = true;
22151
22331
  const now = current;
@@ -22304,9 +22484,27 @@ function runBoard(api) {
22304
22484
  * A loop's run goes on with nobody watching, so the preview must also say agentpipe's sandbox is on: for each model
22305
22485
  * step (its `boundary`) and for the repository's own commands (`commands.sandbox`, `[commands] sandbox`), spike S9,
22306
22486
  * AGE-157. A preview that doesn't say refuses it too. And a tier the recipe names (`--tier`) must be one the folder's
22307
- * agentpipe has (`capabilities <folder> --json`, AGE-127).
22487
+ * agentpipe has (`capabilities <folder> --json`, AGE-127), as must every flag the loop's options need (before the
22488
+ * dry run, which would only say it has no such option).
22308
22489
  */
22309
22490
  async function preflight(run, recipe, deps) {
22491
+ let asked = null;
22492
+ const capabilities = () => {
22493
+ asked ??= (deps.capabilities ?? ((folder) => agentpipeCapabilities(deps.command, deps.env, folder)))(run.workdir);
22494
+ return asked;
22495
+ };
22496
+ const needs = recipe.needs?.(run) ?? [];
22497
+ if (needs.length) {
22498
+ const said = await capabilities();
22499
+ const missing = needs.filter((need) => {
22500
+ const [command = "", flag = ""] = need.split(".");
22501
+ return said?.commands?.[command]?.[flag] !== true;
22502
+ });
22503
+ if (missing.length) return clip(`The agentpipe here has no ${missing.map((need) => {
22504
+ const [command = "", flag = ""] = need.split(".");
22505
+ return `\`${command} --${flag.replaceAll("_", "-")}\``;
22506
+ }).join(" or ")}, which the loop's settings need: update it (\`monoban agentpipe update\`), or change the loop.`, 1e3);
22507
+ }
22310
22508
  const args = recipe.dryRun(run);
22311
22509
  if (args) {
22312
22510
  const refused = await dryRun(run, args, recipe.sandboxed ?? null, deps);
@@ -22314,7 +22512,7 @@ async function preflight(run, recipe, deps) {
22314
22512
  }
22315
22513
  const tier = recipe.tier?.(run) ?? null;
22316
22514
  if (tier) {
22317
- const said = await (deps.capabilities ?? ((folder) => agentpipeCapabilities(deps.command, deps.env, folder)))(run.workdir);
22515
+ const said = await capabilities();
22318
22516
  if (!said?.tiers) return `agentpipe couldn't say which tiers ${run.workdir} has, so the review tier ${tier} can't be checked.`;
22319
22517
  if (!said.tiers.includes(tier)) return clip(`agentpipe has no tier ${tier} in ${run.workdir} (it has ${said.tiers.join(", ") || "none"}).`, 1e3);
22320
22518
  }
@@ -22538,6 +22736,7 @@ async function runRunner(ctx, settings, deps, options = {}) {
22538
22736
  ctx.err(`Cancelling ${active.ref}: asked from the board.`);
22539
22737
  active.cancel();
22540
22738
  }
22739
+ for (const a of work.answers ?? []) if (a.runId === run.id) active.answer(a);
22541
22740
  } else if (first) {
22542
22741
  const status = run.recipe ? "cancelled" : "failed";
22543
22742
  await patch(api, run.id, {
@@ -22581,6 +22780,14 @@ async function runRunner(ctx, settings, deps, options = {}) {
22581
22780
  const outbox = new Outbox(api, run.id, now);
22582
22781
  let cancel = async () => {};
22583
22782
  let cancelled = false;
22783
+ /** Answers handed on (or being), so a check-in before the outcome is reported doesn't hand one on twice. */
22784
+ const answered = /* @__PURE__ */ new Set();
22785
+ /** Hands an answer to the run (a loop's run): none until it started. One at a time, in order. */
22786
+ let relay = null;
22787
+ let relaying = Promise.resolve();
22788
+ let reportOf = null;
22789
+ /** Its step's check-in rate (a window open for your answers makes it faster for a while). */
22790
+ let stepSeconds = 5;
22584
22791
  const self = {
22585
22792
  id: run.id,
22586
22793
  ref: ref ?? "a deleted task",
@@ -22590,6 +22797,27 @@ async function runRunner(ctx, settings, deps, options = {}) {
22590
22797
  await cancel();
22591
22798
  },
22592
22799
  flush: () => outbox.flush(),
22800
+ answer: (a) => {
22801
+ if (answered.has(a.id) || !relay || !reportOf) return;
22802
+ answered.add(a.id);
22803
+ const [hand, report] = [relay, reportOf];
22804
+ relaying = relaying.then(async () => {
22805
+ const said = await hand(a).catch((err) => ({
22806
+ outcome: "refused",
22807
+ message: `Couldn't hand on your answer: ${err.message}`
22808
+ }));
22809
+ report.event({
22810
+ kind: "answer",
22811
+ message: said.message,
22812
+ data: {
22813
+ answerId: a.id,
22814
+ questionId: a.questionId,
22815
+ outcome: said.outcome
22816
+ }
22817
+ });
22818
+ wake.abort();
22819
+ });
22820
+ },
22593
22821
  pollSeconds: 5
22594
22822
  };
22595
22823
  return {
@@ -22652,19 +22880,28 @@ async function runRunner(ctx, settings, deps, options = {}) {
22652
22880
  },
22653
22881
  update: (u) => outbox.update(u)
22654
22882
  };
22655
- const started = loopRun && deps.agentpipe ? runRecipe(run.recipe, loopRun, report, {
22883
+ const recipeRun = loopRun && deps.agentpipe ? runRecipe(run.recipe, loopRun, report, {
22656
22884
  ...deps.agentpipe,
22657
22885
  recheck: () => recheck(run.id),
22658
22886
  mayMerge: () => mayMerge(run.id),
22659
22887
  onStep: (seconds) => {
22660
- self.pollSeconds = seconds ?? settings.pollSeconds;
22888
+ stepSeconds = seconds ?? settings.pollSeconds;
22889
+ self.pollSeconds = stepSeconds;
22890
+ },
22891
+ onWaiting: (waiting) => {
22892
+ self.pollSeconds = waiting ? Math.min(stepSeconds, 5) : stepSeconds;
22661
22893
  }
22662
- }) : adapter.start({
22894
+ }) : null;
22895
+ const started = recipeRun ?? adapter.start({
22663
22896
  ref,
22664
22897
  workdir: run.workdir,
22665
22898
  options: run.options
22666
22899
  }, report);
22667
22900
  cancel = started.cancel;
22901
+ if (recipeRun) {
22902
+ relay = recipeRun.answer;
22903
+ reportOf = report;
22904
+ }
22668
22905
  if (cancelled) started.cancel();
22669
22906
  const ending = await started.done;
22670
22907
  await outbox.flush();
@@ -22758,6 +22995,7 @@ function describe$1(e) {
22758
22995
  }
22759
22996
  case "pr_opened": return `pull request ${e.message}`;
22760
22997
  case "question": return `? ${e.message}`;
22998
+ case "answer": return `↳ ${e.message}`;
22761
22999
  case "error": return `✗ ${e.message}`;
22762
23000
  default: return null;
22763
23001
  }
@@ -23270,7 +23508,7 @@ function describe({ state, running }, board, now) {
23270
23508
  const seenAgo = `checked in ${since(board.lastSeenAt, now)} ago (every ${board.pollSeconds}s)`;
23271
23509
  row("board", `${board.online ? "online" : "offline"} · ${seenAgo}`);
23272
23510
  } else if (!state.runnerId) row("board", "not on the board yet: it's starting");
23273
- if (state.version !== "1.11.0") {
23511
+ if (state.version !== "1.12.0") {
23274
23512
  const again = state.background ? "`monoban runner restart`" : "start it again in its terminal";
23275
23513
  row("update", `it runs monoban ${state.version}, this is ${VERSION}: ${again}`);
23276
23514
  }
@@ -23708,7 +23946,7 @@ async function checks(ctx, deps = {}) {
23708
23946
  const found = [];
23709
23947
  const latest = await (deps.latest ?? latestVersion)(ctx);
23710
23948
  const upgrade = UPGRADE[thisInstall()].command;
23711
- found.push(latest && newer(latest, "1.11.0") ? {
23949
+ found.push(latest && newer(latest, "1.12.0") ? {
23712
23950
  name: "monoban",
23713
23951
  status: "warn",
23714
23952
  detail: `${VERSION}; ${latest} is out`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monoban",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "description": "Your monoban.dev kanban board in the terminal: add, move and start tasks, and hand them to coding agents.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://monoban.dev",