pi-straw-boss 0.77.2 → 0.78.1

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.
@@ -218,7 +218,22 @@ var tabs = async (run4, workspace) => (await result(run4, ["tab", "list", "--wor
218
218
  async function panes(run4, workspace) {
219
219
  return (await result(run4, ["pane", "list", ...workspace ? ["--workspace", workspace] : []])).panes;
220
220
  }
221
- var herdrCall = (socketPath = herdrSocket()) => (method, params, timeoutMs = 5e3) => new Promise((resolve4, reject) => {
221
+ var READS = /* @__PURE__ */ new Set(["workspace.list", "pane.list", "tab.list", "pane.current", "pane.get", "pane.read", "pane.process_info", "pane.layout", "session.snapshot"]);
222
+ var RETRY_MS = 250;
223
+ var RETRIED = /* @__PURE__ */ new Set(["timeout", "closed"]);
224
+ var herdrCall = (socketPath = herdrSocket()) => {
225
+ const once = callOnce(socketPath);
226
+ return async (method, params, timeoutMs) => {
227
+ try {
228
+ return await once(method, params, timeoutMs);
229
+ } catch (error) {
230
+ if (!READS.has(method) || !(error instanceof HerdrError) || !RETRIED.has(error.code)) throw error;
231
+ await new Promise((resolve4) => setTimeout(resolve4, RETRY_MS));
232
+ return once(method, params, timeoutMs);
233
+ }
234
+ };
235
+ };
236
+ var callOnce = (socketPath) => (method, params, timeoutMs = 5e3) => new Promise((resolve4, reject) => {
222
237
  const socket = createConnection(localEndpoint(socketPath)), text4 = new StringDecoder("utf8");
223
238
  let reply = "";
224
239
  const fail = (code, message) => (clearTimeout(timer), socket.destroy(), reject(new HerdrError(code, `herdr ${method} failed: ${code} ${message}`.trim())));
@@ -4142,7 +4157,7 @@ var PENDING = /^(pending|todo|tbd|waiting|open|not[ _-]?run)$/i;
4142
4157
  var ON_FIELDS = ["head"];
4143
4158
  var present2 = (value) => value !== void 0;
4144
4159
  var text = (value, max = 1e3) => typeof value === "string" && value.trim() !== "" && value.length <= max;
4145
- var SLIP_KEYS = ["car", "tickets", "branch", "head", "tested-on", "review", "light", "migrations", "lane", "deploy", "departs", "accept", "uat", "auth", "coordinator"];
4160
+ var SLIP_KEYS = ["car", "app", "tickets", "branch", "head", "tested-on", "review", "light", "migrations", "lane", "deploy", "departs", "accept", "uat", "auth", "coordinator"];
4146
4161
  function segments(line) {
4147
4162
  const parts = [];
4148
4163
  let depth2 = 0, quoted = false, from = 0;
@@ -4178,14 +4193,21 @@ function parseSlip(slip) {
4178
4193
  else fields[key2] = value;
4179
4194
  }
4180
4195
  });
4196
+ if (fields.app !== void 0) {
4197
+ if (fields.car === void 0) fields.car = fields.app;
4198
+ else if (fields.car !== fields.app) problems.push(`sb: slip: app: ${shown(fields.app)} and car: ${shown(fields.car)} name two apps: car: names the car's app (app: is the same field), and its tickets go in tickets:`);
4199
+ }
4181
4200
  const tickets = (fields.tickets ?? "").replace(/\([^)]*\)/g, " ").split(/[\s,]+/).filter(Boolean);
4182
4201
  return { fields, tickets, entries, problems };
4183
4202
  }
4203
+ var SLIP_START = /^\s*(?:car:|app:[^|\n]*\|\s*(?:car|tickets):)/i;
4204
+ var startsSlip = (line) => SLIP_START.test(line);
4205
+ var slipLines = (body) => body.replace(/([^\s|])[ \t]+((?:car|app):[ \t]*[A-Za-z0-9._-]+[ \t]*\|[ \t]*(?:tickets|car):)/gi, "$1\n$2");
4184
4206
  function slipBlocks(text4) {
4185
4207
  const header = [], blocks = [];
4186
4208
  let open2 = false;
4187
4209
  for (const line of text4.split(/\r?\n/)) {
4188
- if (/^\s*car:/i.test(line)) blocks.push([line]), open2 = true;
4210
+ if (startsSlip(line)) blocks.push([line]), open2 = true;
4189
4211
  else if (open2 && line.trim() !== "" && /^\s*[A-Za-z][A-Za-z0-9-]*:/.test(line)) blocks.at(-1).push(line);
4190
4212
  else {
4191
4213
  open2 = false;
@@ -4422,7 +4444,7 @@ function noTrainRefusal(dir, apps) {
4422
4444
  if (!read.ok) return `sb: ${read.refusal.replace(/, so integration\.accept of the app is unknown$/, "")}, so no app here takes the merge train`;
4423
4445
  for (const app of apps) {
4424
4446
  const entry = read.apps.find((a) => a.name === app);
4425
- if (!entry) return `sb: ${read.file} has no app named ${app}, so its car takes no train`;
4447
+ if (!entry) return `sb: ${read.file} has no app named ${app}, so its car takes no train (the slip's car: names the car's app as apps.json names it, not a ticket)`;
4426
4448
  if (!isObject2(entry.integration)) return `sb: ${read.file}: app ${app} has no integration, so it takes no train`;
4427
4449
  }
4428
4450
  return void 0;
@@ -4434,6 +4456,11 @@ function openRefusal(dir, app) {
4434
4456
  const out = named2.flatMap((a) => isObject2(a.integration) ? integrationRefusals(read.file, String(a.name), a.integration) : []);
4435
4457
  return out.length ? `sb: ${out.join("; ")}` : void 0;
4436
4458
  }
4459
+ function projectAppsDir(dir) {
4460
+ if (appsFile(dir).exists) return dir;
4461
+ const main = repoRoot(dir);
4462
+ return appsFile(main).exists ? main : void 0;
4463
+ }
4437
4464
  function repoRoot(dir) {
4438
4465
  const real2 = (path) => {
4439
4466
  try {
@@ -4489,7 +4516,7 @@ function trainFromRequest(request2) {
4489
4516
  if (!isCode(code)) return { refusal: `The manifest's code "${String(code).slice(0, 80)}" is not a train code (YYYY-MM-DD-<one or two lowercase letters>)` };
4490
4517
  return { project, code };
4491
4518
  }
4492
- var appFromRequest = (request2) => /^\s*app:\s*([A-Za-z0-9._-]{1,64})\s*$/m.exec(request2.split(/\r?\n(?=\s*car:)/i)[0] ?? request2)?.[1];
4519
+ var appFromRequest = (request2) => /^\s*app:\s*([A-Za-z0-9._-]{1,64})\s*$/m.exec(request2.split(/\r?\n(?=\s*(?:car:|app:[^|\n]*\|\s*(?:car|tickets):))/i)[0] ?? request2)?.[1];
4493
4520
  function maxTrainsOf(value) {
4494
4521
  if (value === void 0) return DEFAULT_MAX_TRAINS;
4495
4522
  return typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= MAX_TRAINS_CAP ? value : { refusal: `apps.json: integration.maxTrains must be a whole number from 1 to ${MAX_TRAINS_CAP}, not ${JSON.stringify(value)?.slice(0, 40)}` };
@@ -4823,7 +4850,7 @@ function factsOf(read, life) {
4823
4850
  // src/train/cars.ts
4824
4851
  var CAR_STATES = ["received", "returned", "dropped", "landed"];
4825
4852
  var TERMINAL_STATES = ["returned", "dropped", "landed"];
4826
- var RETRY_MS = [3e4, 12e4, 3e5];
4853
+ var RETRY_MS2 = [3e4, 12e4, 3e5];
4827
4854
  var MAX_REASON = 600;
4828
4855
  var present4 = (value) => value !== void 0;
4829
4856
  var text3 = (value, max) => typeof value === "string" && value.trim() !== "" && value.length <= max;
@@ -4985,12 +5012,12 @@ function noticeStatus(record, state) {
4985
5012
  var landedWord = (ticket, head, how) => `sb: car ${ticket} (${head.slice(0, 12)}) ${how}, so it takes no train again: a car lands once. Return it with this word (train_car returned), which tells its coordinator`;
4986
5013
  var headsIn = (text4) => [...new Set([...text4.matchAll(/(?:^|[\s|])head:\s*([0-9a-f]{40})(?![0-9a-f])/gim)].map((m) => m[1]))];
4987
5014
  function slipsInText(body) {
4988
- const lines = body.replace(/(\S)[ \t]+(car:[ \t]*[A-Za-z0-9._-]+[ \t]*\|[ \t]*tickets:)/gi, "$1\n$2");
5015
+ const lines = slipLines(body);
4989
5016
  return slipBlocks(lines).blocks.flatMap((block) => {
4990
5017
  const parsed = parseSlip(block), f = parsed.fields;
4991
5018
  if (!f.car || !isName(f.car) || !parsed.tickets.length || !f.branch || !SHA_RE.test(f.head ?? "")) return [];
4992
5019
  const over = ticketBound(parsed.tickets).join("; "), tickets = over ? parsed.tickets.slice(0, MAX_CAR_TICKETS).map((t) => t.slice(0, MAX_TICKET_CHARS)) : parsed.tickets;
4993
- return [{ app: f.car, tickets, ...over ? { over } : {}, branch: f.branch, head: f.head, ...f.coordinator ? { coordinator: f.coordinator } : {} }];
5020
+ return [{ app: f.car, tickets, ...over ? { over } : {}, branch: f.branch, head: f.head, ...f.coordinator ? { coordinator: f.coordinator } : {}, ...parsed.problems.length ? { problems: parsed.problems } : {} }];
4994
5021
  });
4995
5022
  }
4996
5023
  var coordinatorWord = (ticket, coordinator, sender) => `sb: car ${ticket} names coordinator ${coordinator}, but ${sender} sent it; the slip is refused`;
@@ -6699,10 +6726,12 @@ export {
6699
6726
  checkEvidence,
6700
6727
  checkCar,
6701
6728
  parseAppAccept,
6729
+ appsFile,
6702
6730
  readApps,
6703
6731
  readAppIntegration,
6704
6732
  noTrainRefusal,
6705
6733
  openRefusal,
6734
+ projectAppsDir,
6706
6735
  repoRoot,
6707
6736
  checkoutProject,
6708
6737
  TRAIN,
@@ -6786,7 +6815,7 @@ export {
6786
6815
  boardState,
6787
6816
  expired,
6788
6817
  factsOf,
6789
- RETRY_MS,
6818
+ RETRY_MS2 as RETRY_MS,
6790
6819
  validateStateFields,
6791
6820
  endOf,
6792
6821
  emptyCar,
@@ -9,6 +9,7 @@ import {
9
9
  TOWER_LABEL,
10
10
  VERSION,
11
11
  answers,
12
+ appsFile,
12
13
  boardPath,
13
14
  boardState,
14
15
  callControl,
@@ -51,8 +52,8 @@ import {
51
52
  passGate,
52
53
  plain,
53
54
  probe,
55
+ projectAppsDir,
54
56
  readAppIntegration,
55
- readApps,
56
57
  readBoard,
57
58
  readFrom,
58
59
  readGate,
@@ -60,6 +61,7 @@ import {
60
61
  readRecord,
61
62
  readStartError,
62
63
  readTrainboards,
64
+ repoRoot,
63
65
  report,
64
66
  restart,
65
67
  result,
@@ -86,10 +88,10 @@ import {
86
88
  writeBoard,
87
89
  writeJson,
88
90
  writerAlive
89
- } from "./chunk-ENYILM47.mjs";
91
+ } from "./chunk-QVDSQ4NU.mjs";
90
92
 
91
93
  // src/server/cli.ts
92
- import { existsSync as existsSync2, realpathSync as realpathSync2 } from "node:fs";
94
+ import { existsSync as existsSync2, realpathSync as realpathSync3 } from "node:fs";
93
95
  import { fileURLToPath } from "node:url";
94
96
 
95
97
  // src/server/desk.ts
@@ -221,7 +223,7 @@ async function runProcs(ctx, flags, { out, err }) {
221
223
  }
222
224
 
223
225
  // src/server/traincmds.ts
224
- import { existsSync, lstatSync, readdirSync, readFileSync } from "node:fs";
226
+ import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync as realpathSync2 } from "node:fs";
225
227
  import { availableParallelism, loadavg, userInfo } from "node:os";
226
228
  import { dirname as dirname2, join, resolve as resolve3 } from "node:path";
227
229
  var MAX_INPUT = 256 * 1024;
@@ -284,11 +286,16 @@ function check(flags, io) {
284
286
  if (slip?.refusal) refusals.push(slip.refusal);
285
287
  if (!setting.ok) refusals.push(setting.refusal);
286
288
  let required = setting.ok ? setting.accept : [];
287
- if (!accept.refusal && !slip?.refusal && setting.ok && !readApps(cwd).missing) {
289
+ if (!accept.refusal && !slip?.refusal && setting.ok) {
288
290
  const app = typeof flags.app === "string" ? flags.app : slip ? parseSlip(slip.text).fields.car : evidenceApp(accept.text);
289
- const found = app ? readAppIntegration(cwd, app) : { ok: false, refusal: "sb: the project has an apps.json, so name the app to check against: --app <name>" };
290
- if (found.ok) required = [.../* @__PURE__ */ new Set([...required, ...found.accept])];
291
- else refusals.push(found.refusal);
291
+ const dir = projectAppsDir(cwd);
292
+ if (dir === void 0) {
293
+ if (app) refusals.push(`sb: app ${app} could not be checked: ${noAppsWhere(cwd)}; run train check in the project's checkout`);
294
+ } else {
295
+ const found = app ? readAppIntegration(dir, app) : { ok: false, refusal: "sb: the project has an apps.json, so name the app to check against: --app <name>" };
296
+ if (found.ok) required = [.../* @__PURE__ */ new Set([...required, ...found.accept])];
297
+ else refusals.push(found.refusal);
298
+ }
292
299
  }
293
300
  if (!accept.refusal && !slip?.refusal && setting.ok && !refusals.length) {
294
301
  const exists = io.exists ?? ((path) => existsSync(resolve3(cwd, path)));
@@ -308,6 +315,17 @@ function check(flags, io) {
308
315
  `);
309
316
  return refusals.length ? 2 : 0;
310
317
  }
318
+ function noAppsWhere(cwd) {
319
+ const real2 = (path) => {
320
+ try {
321
+ return realpathSync2(path);
322
+ } catch {
323
+ return path;
324
+ }
325
+ };
326
+ const here = appsFile(real2(cwd)).both, main2 = appsFile(repoRoot(cwd)).both;
327
+ return `no apps.json at ${here}${main2 === here ? "" : `, nor in the main checkout of this repository (${main2})`}`;
328
+ }
311
329
  function evidenceApp(text) {
312
330
  try {
313
331
  const car = JSON.parse(text ?? "null")?.car;
@@ -1747,7 +1765,7 @@ var loadMain = () => main ??= import(new URL(import.meta.url.endsWith(".ts") ? "
1747
1765
  var selfPath = () => fileURLToPath(import.meta.url.split("?")[0]);
1748
1766
  var realpath = (path) => {
1749
1767
  try {
1750
- return realpathSync2(path);
1768
+ return realpathSync3(path);
1751
1769
  } catch {
1752
1770
  return path;
1753
1771
  }