pi-straw-boss 0.126.0 → 0.127.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/package.json +1 -1
- package/src/train/moves.ts +34 -0
- package/src/trainguard.ts +10 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-straw-boss",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.127.0",
|
|
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",
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isObject, type Json } from "./spec.ts";
|
|
2
|
+
|
|
3
|
+
// A main's `todo move` batch under the train rules (pi-todo-ledger 0.12.0; MOVE-F005, docs/specs/2026-11-30-boss-fork.md, The train guard on a move). Pure: the ledger's change comes in, the refusal lines go out.
|
|
4
|
+
|
|
5
|
+
const ids = (value: unknown): number[] => (Array.isArray(value) ? value.filter((d): d is number => Number.isInteger(d)) : []);
|
|
6
|
+
const live = (t: Json) => t.status !== "deleted";
|
|
7
|
+
const isTrain = (t: Json) => isObject(t.metadata) && t.metadata.sb !== undefined;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* What the train holds in a move batch, judged on the whole batch before anything moves: a todo that carries `metadata.sb` (only an integrator imports one, and the source cannot see where the batch goes), a todo that
|
|
11
|
+
* waits on one, and a todo one waits on, even when `dropBlockers` would cut the edge. Each is named with its reason, and a last line says nothing moved; none when the batch holds nothing of the train.
|
|
12
|
+
*/
|
|
13
|
+
export function heldInMove(change: { params: Record<string, unknown>; before: readonly unknown[]; after: readonly unknown[] }): string[] {
|
|
14
|
+
const tasks = change.before.filter((t): t is Json => isObject(t) && Number.isInteger(t.id));
|
|
15
|
+
const trains = tasks.filter((t) => live(t) && isTrain(t));
|
|
16
|
+
// The batch: the ids the call names, and any task the ledger would take that the call did not name (a tombstone in `after` that `before` had live).
|
|
17
|
+
const batch = new Set(ids(change.params.ids));
|
|
18
|
+
for (const t of change.after) if (isObject(t) && t.status === "deleted" && tasks.some((b) => b.id === t.id && live(b))) batch.add(t.id as number);
|
|
19
|
+
const lines: string[] = [], held: number[] = [];
|
|
20
|
+
for (const t of tasks.filter((x) => live(x) && batch.has(x.id as number)).sort((a, b) => (a.id as number) - (b.id as number))) {
|
|
21
|
+
const id = t.id as number;
|
|
22
|
+
const why = [
|
|
23
|
+
...(isTrain(t) ? [`sb: todo #${id} is a train todo (metadata.sb): it stays with the integrator that holds it`] : []),
|
|
24
|
+
...trains.filter((s) => ids(t.blockedBy).includes(s.id as number)).map((s) => `sb: todo #${id} waits on train todo #${String(s.id)}: it stays with the train todo it waits on`),
|
|
25
|
+
...trains.filter((s) => ids(s.blockedBy).includes(id)).map((s) => `sb: todo #${id} blocks train todo #${String(s.id)}: it stays with the train todo that waits on it`),
|
|
26
|
+
];
|
|
27
|
+
if (why.length) (lines.push(...why), held.push(id));
|
|
28
|
+
}
|
|
29
|
+
// A train todo the batch would change otherwise (an edge the ledger drops that the rules above did not name): kept whole too.
|
|
30
|
+
const was = new Map(tasks.map((t) => [t.id as number, JSON.stringify(t)] as const));
|
|
31
|
+
const changed = change.after.find((t): t is Json => isObject(t) && isTrain(t) && live(t) && was.get(t.id as number) !== JSON.stringify(t));
|
|
32
|
+
if (!lines.length && changed) lines.push(`sb: todo #${String(changed.id)} is a train todo (metadata.sb): this move would change its edges, and it stays as it is`);
|
|
33
|
+
return lines.length ? [...lines, `sb: nothing moved; move the others without ${held.length ? held.map((id) => `#${id}`).join(", ") : "changing it"}`] : [];
|
|
34
|
+
}
|
package/src/trainguard.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { type BoardRead, type BoardStep, boardPath, capBoard, type CarRow, facts
|
|
|
15
15
|
import { type CarView, coordinatorWord, forwardsFor, forwardsOf, noticeSatisfied, receivedTold, type TerminalState } from "./train/cars.ts";
|
|
16
16
|
import { fieldsOf } from "./headerfields.ts";
|
|
17
17
|
import { type Effect, isObject, type Json, shortCode, STEP_REQUIRED, todoEffects, validateStep } from "./train/spec.ts";
|
|
18
|
+
import { heldInMove } from "./train/moves.ts";
|
|
18
19
|
import { type FactStep, stepWaits, type TrainFacts, type Wait, waitMessage } from "./train/waits.ts";
|
|
19
20
|
import { type Acceptor, buildBoard, buildYard, freezeStep, type Row } from "./trainboard.ts";
|
|
20
21
|
import type { MainDuty } from "./mainduty.ts";
|
|
@@ -558,16 +559,18 @@ export function createTrainGuard(pi: GuardPi, env: GuardEnv) {
|
|
|
558
559
|
if (input.action === "import") {
|
|
559
560
|
if (me) return ["sb: a train's list is never imported"];
|
|
560
561
|
if (!env.isMain() || !after) return []; // only the ledger supports import; its check, not tool_call, receives the list
|
|
561
|
-
|
|
562
|
-
//
|
|
562
|
+
// An append (a move file's tasks, docs/specs/2026-11-30-boss-fork.md) is judged on what it appends: the tasks from the list's next id on, never those already in it. Its train todos must be of the
|
|
563
|
+
// project of the train todos the list holds, as a create of one must (integratorTodo): a train of another project is another integrator's.
|
|
564
|
+
const held = input.append === true ? state().rows.map(sbOf).find((s) => s?.kind === "train")?.project : undefined;
|
|
565
|
+
let project = typeof held === "string" ? held : undefined, carried = false;
|
|
563
566
|
for (const t of input.append === true ? after.filter((t) => isObject(t) && (t.id as number) >= state().nextId) : after) {
|
|
564
567
|
if (!isObject(t) || !isObject(t.metadata) || t.metadata.sb === undefined) continue;
|
|
565
568
|
if (env.duty() !== "integrator") return [NOT_INTEGRATOR];
|
|
566
569
|
const sb = t.metadata.sb, refusals = trainRefusals(sb, ctx, t.status as string, t.id as number, project);
|
|
567
570
|
if (refusals.length) return refusals;
|
|
568
|
-
if (isObject(sb) && typeof sb.project === "string") project = sb.project;
|
|
571
|
+
if (isObject(sb) && typeof sb.project === "string") (project = sb.project, carried = true);
|
|
569
572
|
}
|
|
570
|
-
return
|
|
573
|
+
return carried ? contractRefusal() : [];
|
|
571
574
|
}
|
|
572
575
|
const integrators = !me && env.isMain() && (hasSb(input) || changesTrainTodo(input, state));
|
|
573
576
|
const reasons = me ? await trainTodo(input, ctx, me, state) : integrators ? (env.duty() === "integrator" ? await integratorTodo(input, ctx, state) : [NOT_INTEGRATOR]) : [];
|
|
@@ -590,16 +593,13 @@ export function createTrainGuard(pi: GuardPi, env: GuardEnv) {
|
|
|
590
593
|
}
|
|
591
594
|
}
|
|
592
595
|
/**
|
|
593
|
-
* A move batch (pi-todo-ledger 0.12.0; MOVE-F005, docs/specs/2026-11-30-boss-fork.md) under the rules a removal already has: a train's list is never imported and never moves, and a main keeps
|
|
594
|
-
*
|
|
596
|
+
* A move batch (pi-todo-ledger 0.12.0; MOVE-F005, docs/specs/2026-11-30-boss-fork.md) under the rules a removal already has: a train's list is never imported and never moves, and a main keeps what the train holds,
|
|
597
|
+
* judged on the whole batch (train/moves.ts). Everything else passes, as the delete of a plain todo does; a todo whose child still runs is the live-child guard's (`sb-fork`, forkmain.ts).
|
|
595
598
|
*/
|
|
596
599
|
function moveReasons(change: LedgerChange): string[] {
|
|
597
600
|
if (env.train()) return [TRAIN_STAYS];
|
|
598
601
|
if (env.pending?.()) return [UNSETTLED];
|
|
599
|
-
|
|
600
|
-
const was = new Map(change.before.flatMap((t) => (isObject(t) && Number.isInteger(t.id) ? [[t.id as number, JSON.stringify(t)] as const] : [])));
|
|
601
|
-
const held = change.after.find((t): t is Json => isObject(t) && isObject(t.metadata) && t.metadata.sb !== undefined && was.get(t.id as number) !== JSON.stringify(t));
|
|
602
|
-
return held ? [`sb: todo #${String(held.id)} is a train todo (metadata.sb): it stays with the integrator that holds it, and this move would ${held.status === "deleted" ? "take it away" : "change its edges"}. Move the others without it`] : [];
|
|
602
|
+
return env.isMain() ? heldInMove(change) : [];
|
|
603
603
|
}
|
|
604
604
|
const contractRefusal = (): string[] => { const contract = contractNow(); return contract && !contract.ok ? [contract.refusal] : []; };
|
|
605
605
|
// A guard that fails does not let the call through: the train's checks are enforcement.
|