pi-straw-boss 0.80.0 → 0.80.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.
@@ -4393,7 +4393,7 @@ function checkStages(stages) {
4393
4393
 
4394
4394
  // src/train/appsconfig.ts
4395
4395
  import { existsSync as existsSync8, readFileSync as readFileSync12, realpathSync as realpathSync2, statSync as statSync7 } from "node:fs";
4396
- import { basename as basename2, dirname as dirname6, join as join12, resolve as resolve2 } from "node:path";
4396
+ import { basename as basename2, dirname as dirname6, join as join12, resolve as resolve2, sep as sep2 } from "node:path";
4397
4397
  var MIGRATION = "see docs/how-it-works.md, Moving a project to 0.65.0";
4398
4398
  function gitRoot(dir) {
4399
4399
  for (let d = dir; ; d = dirname6(d)) {
@@ -4479,6 +4479,30 @@ function repoRoot(dir) {
4479
4479
  return real2(root);
4480
4480
  }
4481
4481
  }
4482
+ function carRepos(dir, app, fallback = dir) {
4483
+ const read = readApps(dir), at2 = read.ok ? read.apps.find((a) => a.name === app)?.dir : void 0;
4484
+ if (typeof at2 !== "string") return [fallback];
4485
+ const home = repoRoot(dir);
4486
+ const inside2 = (path, root) => path.startsWith(root + sep2);
4487
+ const ownGitDir = (folder) => {
4488
+ const dot = join12(folder, ".git");
4489
+ if (statSync7(dot).isDirectory()) return true;
4490
+ const named2 = /^gitdir:\s*(.+)$/m.exec(readFileSync12(dot, "utf8"))?.[1]?.trim();
4491
+ return named2 !== void 0 && inside2(realpathSync2(resolve2(folder, named2)), home);
4492
+ };
4493
+ const own2 = (root) => {
4494
+ const folder = resolve2(root, at2);
4495
+ if (!inside2(folder, root) || !existsSync8(join12(folder, ".git"))) return [];
4496
+ try {
4497
+ const real2 = realpathSync2(folder);
4498
+ return inside2(real2, realpathSync2(root)) && ownGitDir(real2) ? [real2] : [];
4499
+ } catch {
4500
+ return [];
4501
+ }
4502
+ };
4503
+ const found = [.../* @__PURE__ */ new Set([...own2(resolve2(gitRoot(dir))), ...own2(home)])];
4504
+ return found.length ? found : [fallback];
4505
+ }
4482
4506
  function checkoutProject(dir) {
4483
4507
  const { file } = appsFile(dir);
4484
4508
  let config;
@@ -6734,6 +6758,7 @@ export {
6734
6758
  openRefusal,
6735
6759
  projectAppsDir,
6736
6760
  repoRoot,
6761
+ carRepos,
6737
6762
  checkoutProject,
6738
6763
  TRAIN,
6739
6764
  isSessionRole,
@@ -13,6 +13,7 @@ import {
13
13
  boardPath,
14
14
  boardState,
15
15
  callControl,
16
+ carRepos,
16
17
  carsFolderOk,
17
18
  checkAcceptRef,
18
19
  checkCar,
@@ -88,7 +89,7 @@ import {
88
89
  writeBoard,
89
90
  writeJson,
90
91
  writerAlive
91
- } from "./chunk-GEBLT4XW.mjs";
92
+ } from "./chunk-S2XBGLRM.mjs";
92
93
 
93
94
  // src/server/cli.ts
94
95
  import { existsSync as existsSync2, realpathSync as realpathSync3 } from "node:fs";
@@ -285,7 +286,7 @@ function check(flags, io) {
285
286
  if (accept.refusal) refusals.push(accept.refusal);
286
287
  if (slip?.refusal) refusals.push(slip.refusal);
287
288
  if (!setting.ok) refusals.push(setting.refusal);
288
- let required = setting.ok ? setting.accept : [];
289
+ let required = setting.ok ? setting.accept : [], repos = [cwd];
289
290
  if (!accept.refusal && !slip?.refusal && setting.ok) {
290
291
  const app = typeof flags.app === "string" ? flags.app : slip ? parseSlip(slip.text).fields.car : evidenceApp(accept.text);
291
292
  const dir = projectAppsDir(cwd);
@@ -293,20 +294,20 @@ function check(flags, io) {
293
294
  if (app) refusals.push(`sb: app ${app} could not be checked: ${noAppsWhere(cwd)}; run train check in the project's checkout`);
294
295
  } else {
295
296
  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
+ if (found.ok) required = [.../* @__PURE__ */ new Set([...required, ...found.accept])], repos = carRepos(dir, app, cwd);
297
298
  else refusals.push(found.refusal);
298
299
  }
299
300
  }
300
301
  if (!accept.refusal && !slip?.refusal && setting.ok && !refusals.length) {
301
302
  const exists = io.exists ?? ((path) => existsSync(resolve3(cwd, path)));
302
- const isAncestor = io.isAncestor ?? ((older, newer2) => {
303
+ const isAncestor = io.isAncestor ?? ((older, newer2) => repos.some((at) => {
303
304
  try {
304
- execFileSyncExe("git", ["merge-base", "--is-ancestor", older, newer2], { cwd, stdio: "ignore", timeout: 15e3, killSignal: "SIGKILL" });
305
+ execFileSyncExe("git", ["merge-base", "--is-ancestor", older, newer2], { cwd: at, stdio: "ignore", timeout: 15e3, killSignal: "SIGKILL" });
305
306
  return true;
306
307
  } catch {
307
308
  return false;
308
309
  }
309
- });
310
+ }));
310
311
  const options = { appAccept: required, exists, isAncestor };
311
312
  refusals.push(...slip ? checkCar(slip.text, accept.text, options) : none ? checkAcceptRef("none", required) : checkEvidence(accept.text, options));
312
313
  }
@@ -212,7 +212,7 @@ import {
212
212
  writeStartError,
213
213
  writerAlive,
214
214
  yardPath
215
- } from "./chunk-GEBLT4XW.mjs";
215
+ } from "./chunk-S2XBGLRM.mjs";
216
216
 
217
217
  // src/server/main.ts
218
218
  import { homedir as homedir15 } from "node:os";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-straw-boss",
3
- "version": "0.80.0",
3
+ "version": "0.80.1",
4
4
  "description": "Straw Boss coordination for pi in Herdr: sessions join a tab's net by choice, the first joiner is its main agent, a workspace tower opens on demand with a live monitoring dashboard, and boss_broadcast reaches the rest",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -3,7 +3,7 @@ import { availableParallelism, loadavg, userInfo } from "node:os";
3
3
  import { dirname, join, resolve } from "node:path";
4
4
  import { execFileSyncExe } from "../exe.mjs";
5
5
  import { checkAcceptRef, checkCar, checkEvidence, parseAppAccept, parseSlip } from "../train/accept.ts";
6
- import { appsFile, projectAppsDir, readAppIntegration, repoRoot } from "../train/appsconfig.ts";
6
+ import { appsFile, carRepos, projectAppsDir, readAppIntegration, repoRoot } from "../train/appsconfig.ts";
7
7
  import { type Board, boardPath, boardState, MAX_TRAINS, trainboardDir, factsOf, MAX_CLEARS, readBoard, readTrainboards, type Writer, writeBoard } from "../train/board.ts";
8
8
  import { isName, isObject, validateStep } from "../train/spec.ts";
9
9
  import { noticeStatus, stateLine, type Attempt } from "../train/cars.ts";
@@ -26,7 +26,7 @@ export interface TrainIo {
26
26
  now?: () => number;
27
27
  alive?: (writer: Writer) => boolean;
28
28
  user?: string;
29
- /** `git merge-base --is-ancestor` in `cwd`, and whether a file is there: replaced by tests. */
29
+ /** `git merge-base --is-ancestor` in `cwd` (in the app's own repository when the app is a submodule of the project), and whether a file is there: replaced by tests. */
30
30
  isAncestor?: (older: string, newer: string) => boolean;
31
31
  exists?: (path: string) => boolean;
32
32
  load?: () => { now: number; cores: number } | undefined;
@@ -95,7 +95,8 @@ function check(flags: Record<string, string | true>, io: TrainIo): number {
95
95
  // What the app requires is the file's (TB-F001): the project's apps.json, for the app `--app` names, else the slip's `car:` (or `app:`), else the evidence's `car.app`. `--app-accept` can only add to it. The file is this folder's, else
96
96
  // that of the repository's main checkout (a coordinator's linked worktree may have none, and the tower reads the project's). When neither has one, a named app could not be checked, and the check says so instead of ok (0.77.3);
97
97
  // with no app named, the flag alone is checked.
98
- let required: string[] = setting.ok ? setting.accept : [];
98
+ // Where git answers about the car's commits: `cwd`, or the app's own repository when the app is one (a submodule of the project, `carRepos`; 0.80.1).
99
+ let required: string[] = setting.ok ? setting.accept : [], repos = [cwd];
99
100
  if (!accept.refusal && !slip?.refusal && setting.ok) {
100
101
  const app = typeof flags.app === "string" ? flags.app : slip ? parseSlip(slip.text!).fields.car : evidenceApp(accept.text);
101
102
  const dir = projectAppsDir(cwd);
@@ -103,20 +104,20 @@ function check(flags: Record<string, string | true>, io: TrainIo): number {
103
104
  if (app) refusals.push(`sb: app ${app} could not be checked: ${noAppsWhere(cwd)}; run train check in the project's checkout`);
104
105
  } else {
105
106
  const found = app ? readAppIntegration(dir, app) : { ok: false as const, refusal: "sb: the project has an apps.json, so name the app to check against: --app <name>" };
106
- if (found.ok) required = [...new Set([...required, ...found.accept])];
107
+ if (found.ok) (required = [...new Set([...required, ...found.accept])], repos = carRepos(dir, app, cwd));
107
108
  else refusals.push(found.refusal);
108
109
  }
109
110
  }
110
111
  if (!accept.refusal && !slip?.refusal && setting.ok && !refusals.length) {
111
112
  const exists = io.exists ?? ((path: string) => existsSync(resolve(cwd, path)));
112
- const isAncestor = io.isAncestor ?? ((older: string, newer: string) => {
113
+ const isAncestor = io.isAncestor ?? ((older: string, newer: string) => repos.some((at) => {
113
114
  try {
114
- execFileSyncExe("git", ["merge-base", "--is-ancestor", older, newer], { cwd, stdio: "ignore", timeout: 15_000, killSignal: "SIGKILL" });
115
+ execFileSyncExe("git", ["merge-base", "--is-ancestor", older, newer], { cwd: at, stdio: "ignore", timeout: 15_000, killSignal: "SIGKILL" });
115
116
  return true;
116
117
  } catch {
117
118
  return false;
118
119
  }
119
- });
120
+ }));
120
121
  const options = { appAccept: required, exists, isAncestor };
121
122
  refusals.push(...(slip ? checkCar(slip.text!, accept.text, options) : none ? checkAcceptRef("none", required) : checkEvidence(accept.text!, options)));
122
123
  }
@@ -1,5 +1,5 @@
1
1
  import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
2
- import { basename, dirname, join, resolve } from "node:path";
2
+ import { basename, dirname, join, resolve, sep } from "node:path";
3
3
  import { checkStages, parseAppAccept } from "./accept.ts";
4
4
  import { isName, isObject } from "./spec.ts";
5
5
 
@@ -106,6 +106,33 @@ export function repoRoot(dir: string): string {
106
106
  } catch { return real(root); }
107
107
  }
108
108
 
109
+ /**
110
+ * The folders git is asked in about the commits of a car of `app` (0.80.1). When the app is a repository of its own (a git submodule of the project, or a clone inside it), they are the app's `dir` of the apps.json of `dir`, under the git root of `dir` and under the
111
+ * main checkout of that repository: in a linked worktree of the project the submodule may not be checked out, or keeps objects of its own. Otherwise (the app's folder holds no `.git` of its own, is the root, or leaves it; no app is named) the app's commits are the
112
+ * project's, and the one folder is `fallback`, where git was asked before. Whether a delta's `on.head` is an ancestor of the car's head was asked in the project's root, where a submodule's commits do not exist. Which folder answers decides only whether git knows
113
+ * the two commits: a commit's ancestors are fixed by its hash.
114
+ */
115
+ export function carRepos(dir: string, app: string | undefined, fallback = dir): string[] {
116
+ const read = readApps(dir), at = read.ok ? read.apps.find((a) => a.name === app)?.dir : undefined;
117
+ if (typeof at !== "string") return [fallback];
118
+ const home = repoRoot(dir);
119
+ // R0801-F001: inside the root after realpath, and its git dir (a submodule's `.git` file names one under the repository's `.git`) inside the repository, so a symlink or a `gitdir:` pointer leads git to no folder outside the project.
120
+ const inside = (path: string, root: string) => path.startsWith(root + sep);
121
+ const ownGitDir = (folder: string): boolean => {
122
+ const dot = join(folder, ".git");
123
+ if (statSync(dot).isDirectory()) return true;
124
+ const named = /^gitdir:\s*(.+)$/m.exec(readFileSync(dot, "utf8"))?.[1]?.trim();
125
+ return named !== undefined && inside(realpathSync(resolve(folder, named)), home);
126
+ };
127
+ const own = (root: string): string[] => {
128
+ const folder = resolve(root, at);
129
+ if (!inside(folder, root) || !existsSync(join(folder, ".git"))) return [];
130
+ try { const real = realpathSync(folder); return inside(real, realpathSync(root)) && ownGitDir(real) ? [real] : []; } catch { return []; }
131
+ };
132
+ const found = [...new Set([...own(resolve(gitRoot(dir))), ...own(home)])];
133
+ return found.length ? found : [fallback];
134
+ }
135
+
109
136
  export type CheckoutProject = { ok: true; project: string; /** Where the name is from, in words. */ from: string; file: string } | { ok: false; refusal: string };
110
137
 
111
138
  /**
package/src/trainguard.ts CHANGED
@@ -9,7 +9,7 @@ import { startOf } from "./startof.ts";
9
9
  import { snapshotOfBranch } from "./todo.ts";
10
10
  import { type Acceptance, acceptanceOf, checkAcceptRef, checkCar, checkEvidence, type EvidenceOptions, parseSlip, slipBlocks } from "./train/accept.ts";
11
11
  import { checkContract, type Contract, type SkillCommand } from "./train/contract.ts";
12
- import { type AppIntegration, readAppIntegration } from "./train/appsconfig.ts";
12
+ import { type AppIntegration, carRepos, readAppIntegration } from "./train/appsconfig.ts";
13
13
  import { type BoardRead, type BoardStep, boardPath, capBoard, type CarRow, factsOf, readBoard, readTrainboards, validateTrainTodo, type Writer, writeBoard, writeYard } from "./train/board.ts";
14
14
  import { type CarView, coordinatorWord, forwardsFor, forwardsOf, noticeSatisfied, receivedTold, type TerminalState } from "./train/cars.ts";
15
15
  import { fieldsOf } from "./headerfields.ts";
@@ -71,7 +71,7 @@ export function manifestText(entries: readonly unknown[]): string | undefined {
71
71
  export { slipBlocks };
72
72
 
73
73
  /** What the manifest check needs besides the text: the app's `integration` from apps.json, and the files and git of the train's own folder. */
74
- export interface ManifestCheck { config(app: string | undefined): AppIntegration; exists(path: string): boolean; isAncestor(older: string, newer: string): boolean }
74
+ export interface ManifestCheck { config(app: string | undefined): AppIntegration; exists(path: string): boolean; /** `app` is the manifest's: git is asked in that app's own repository when it is one (a submodule). */ isAncestor(older: string, newer: string, app?: string): boolean }
75
75
  /** The refusals of a slip against what its app requires (TB-F001): the kinds the evidence lacks, `accept: none` where something is required, and an evidence file that did not read. */
76
76
  const OWED = /^sb: (acceptance evidence lacks |accept: none is allowed only |accept: .* names an evidence file, but it was not read)/;
77
77
 
@@ -87,7 +87,7 @@ export function parseManifest(text: string, read: (path: string) => string | und
87
87
  const owed = config.ok ? (appAccept.length ? refusals.find((r) => OWED.test(r)) : undefined) : config.refusal;
88
88
  const word = asked ?? (owed ? `sb: car ${ticket}: ${owed.replace(/^sb: /, "")}` : undefined);
89
89
  const head = /^[0-9a-f]{40}$/.test(parsed.fields.head ?? "") ? parsed.fields.head! : undefined;
90
- const shown: Acceptance = config.ok ? acceptanceOf(accept ?? "none", evidence, { appAccept, ...(head ? { head } : {}), exists: check.exists, isAncestor: check.isAncestor }) : { unverified: true };
90
+ const shown: Acceptance = config.ok ? acceptanceOf(accept ?? "none", evidence, { appAccept, ...(head ? { head } : {}), exists: check.exists, isAncestor: (older, newer) => check.isAncestor(older, newer, app) }) : { unverified: true };
91
91
  const f = parsed.fields, row: CarRow = { tickets: parsed.tickets, branch: f.branch ?? "", head: head ?? "", coordinator: f.coordinator ?? "", departs: f.departs ?? "next", accept: accept ?? "none", ...shown };
92
92
  cars.push({ ticket, slip, ...(head ? { head } : {}), ...(evidence ? { evidence } : {}), ...(row.tickets.length && row.branch && row.head && row.coordinator ? { row } : {}) });
93
93
  if (word) leftOut.push({ ticket, head: head ?? "", word });
@@ -248,8 +248,8 @@ export function createTrainGuard(pi: GuardPi, env: GuardEnv) {
248
248
  return text === undefined ? undefined : (manifest = parseManifest(text, readText(ctx), manifestCheck(ctx)));
249
249
  };
250
250
  const appsDir = (ctx: Ctx) => ctx.cwd ?? process.cwd();
251
- const isAncestorIn = (ctx: Ctx) => (older: string, newer: string): boolean => { try { git(appsDir(ctx), ["merge-base", "--is-ancestor", older, newer]); return true; } catch { return false; } };
252
- const manifestCheck = (ctx: Ctx): ManifestCheck => ({ config: (app) => (app ? readAppIntegration(appsDir(ctx), app) : { ok: false, refusal: "sb: the manifest names no app, so integration.accept of the app is unknown" }), exists: (path) => existsSync(expand(path, ctx)), isAncestor: isAncestorIn(ctx) });
251
+ const isAncestorIn = (ctx: Ctx, app: string | undefined) => (older: string, newer: string): boolean => carRepos(appsDir(ctx), app).some((dir) => { try { git(dir, ["merge-base", "--is-ancestor", older, newer]); return true; } catch { return false; } });
252
+ const manifestCheck = (ctx: Ctx): ManifestCheck => ({ config: (app) => (app ? readAppIntegration(appsDir(ctx), app) : { ok: false, refusal: "sb: the manifest names no app, so integration.accept of the app is unknown" }), exists: (path) => existsSync(expand(path, ctx)), isAncestor: (older, newer, app) => isAncestorIn(ctx, app)(older, newer) });
253
253
  const writer = (): Writer => {
254
254
  const pid = env.pid ?? process.pid, said = startOf(pid), at = said ? startMs(said) : Number.NaN;
255
255
  return { session: env.session().id, ...(env.session().pane ? { pane: env.session().pane } : {}), pid, started: Number.isNaN(at) ? created : new Date(at).toISOString() };
@@ -418,7 +418,7 @@ export function createTrainGuard(pi: GuardPi, env: GuardEnv) {
418
418
  if (!refusals.length && isObject(sb) && isObject(sb.spec)) {
419
419
  // What the app requires is read from its apps.json here and in the train's manifest check, never from a flag a model passes (TB-F001); a file that cannot be read refuses (TB-F002 too: stages that list uat).
420
420
  const cars = (sb.spec.cars as CarRow[]) ?? [], config = readAppIntegration(appsDir(ctx), String(sb.app));
421
- refusals.push(...(config.ok ? [...claimedRefusals(cars), ...evidenceRefusals(cars, ctx, config.accept)] : [config.refusal]));
421
+ refusals.push(...(config.ok ? [...claimedRefusals(cars), ...evidenceRefusals(cars, ctx, String(sb.app), config.accept)] : [config.refusal]));
422
422
  }
423
423
  // The manifest goes to the tower only when every car is received, its slip came from the coordinator the tower's forward names, and sb has told that coordinator (§5.5, §7.4).
424
424
  if (!refusals.length && effect.status === "in_progress" && rows.find((r) => r.id === effect.id)?.status !== "in_progress" && isObject(sb) && isObject(sb.spec)) {
@@ -445,13 +445,13 @@ export function createTrainGuard(pi: GuardPi, env: GuardEnv) {
445
445
  /** A car's acceptance is what the checked evidence shows; the yard states it from there (TB-F003), so a todo that carries a word of its own about it is refused. */
446
446
  const claimedRefusals = (cars: readonly CarRow[]): string[] => cars.flatMap((car) => (car.accepted !== undefined || car.unverified !== undefined ? [`sb: car ${car.tickets[0]}: accepted is set by Straw Boss from the checked evidence; leave accepted and unverified out of the car`] : []));
447
447
  /** `train check --accept` on each car's evidence, with the kinds the app requires: the evidence is complete for what the file says and for what the app asks, names the car's head, and asks the train for nothing (§5.2, §5.4). */
448
- function evidenceRefusals(cars: readonly CarRow[], ctx: Ctx, appAccept: readonly string[]): string[] {
448
+ function evidenceRefusals(cars: readonly CarRow[], ctx: Ctx, app: string, appAccept: readonly string[]): string[] {
449
449
  const out: string[] = [], read = readText(ctx);
450
450
  for (const car of cars) {
451
451
  if (car.accept.trim().toLowerCase() === "none") { out.push(...checkAcceptRef("none", appAccept).map((r) => `sb: car ${car.tickets[0]}: ${r.replace(/^sb: /, "")}`)); continue; }
452
452
  const text = read(car.accept);
453
453
  if (text === undefined) { out.push(`sb: car ${car.tickets[0]}: cannot read the evidence file ${car.accept}`); continue; }
454
- const options: EvidenceOptions = { appAccept, head: car.head, exists: (path) => existsSync(expand(path, ctx)), isAncestor: isAncestorIn(ctx) };
454
+ const options: EvidenceOptions = { appAccept, head: car.head, exists: (path) => existsSync(expand(path, ctx)), isAncestor: isAncestorIn(ctx, app) };
455
455
  out.push(...checkEvidence(text, options));
456
456
  }
457
457
  return out;
@@ -463,7 +463,7 @@ export function createTrainGuard(pi: GuardPi, env: GuardEnv) {
463
463
  if (!configs.has(app)) configs.set(app, readAppIntegration(appsDir(ctx), app));
464
464
  const config = configs.get(app)!;
465
465
  if (!config.ok) return { unverified: true };
466
- return acceptanceOf(car.accept, car.accept.trim().toLowerCase() === "none" ? undefined : read(car.accept), { appAccept: config.accept, head: car.head, exists: (path) => existsSync(expand(path, ctx)), isAncestor: isAncestorIn(ctx) });
466
+ return acceptanceOf(car.accept, car.accept.trim().toLowerCase() === "none" ? undefined : read(car.accept), { appAccept: config.accept, head: car.head, exists: (path) => existsSync(expand(path, ctx)), isAncestor: isAncestorIn(ctx, app) });
467
467
  };
468
468
  }
469
469