Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pm-stack/projector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ local source you don't commit.
| `/hot/checkpoints` | POST | bearer | ack a checkpoint `{consumer, cursor, highWater}` |
| `/reconcile` | POST | bearer | trigger a reconciliation poll |

### Integrated queue/PM view — machine face (#7078, #2072 slice 3)

`bun run src/cli.ts queue-view --tasks <tasks.json> [--window-hours 24] [--consumer queue-view] [--no-ack]`
prints one read-only JSON view joining fleet queue task records (JSON
exported from the queue broker: an array, or `{ "tasks": [...] }`) with
this projector's slice-2 hot list, consumed through a consumer
checkpoint (pinned high-water; the checkpoint is acked only after the
view prints, unless `--no-ack`). The view lists queued items in claim
order, items claimed inside the window with their claiming
system/lane, snapshot counts by status (which reconcile with
`fleet queue health` when fed the full task list), and links to the
existing aggregator/projector trend stores. It writes nothing and
collects nothing new; the human face is a later slice-3 piece.

**Subjects** are external keys:

- `kaneo:<projectSlug>/<taskId>` — a Kaneo board item (e.g. `kaneo:code/CODE-107`)
Expand Down
61 changes: 59 additions & 2 deletions pm-stack/projector/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,75 @@
// CLI: one-off reconciliation against the live GitHub API.
// CLI: one-off jobs against the live stores.
// bun run src/cli.ts reconcile
// bun run src/cli.ts queue-view --tasks <tasks.json> [--window-hours 24]
// [--consumer queue-view] [--no-ack]
//
// queue-view (#7078, #2072 slice 3 first piece) is the read-only
// integrated queue/PM view, machine face: it joins fleet queue task
// records (JSON exported from the queue broker — an array, or an object
// with a `tasks` array) with the slice-2 hot list consumed through a
// consumer checkpoint, and prints the view as JSON on stdout. The
// checkpoint is acked only after the view has been printed, unless
// --no-ack is passed.
import { readFileSync } from "node:fs";
import { openDb, migrate } from "./store";
import { reconcileRepos } from "./reconcile";
import { buildQueueView, consumeHotList, defaultTrendLinks, type QueueTaskRecord } from "./queue-view";

const cmd = process.argv[2] ?? "reconcile";
const env = process.env as Record<string, string | undefined>;

function arg(name: string): string | undefined {
const i = process.argv.indexOf(`--${name}`);
return i >= 0 ? process.argv[i + 1] : undefined;
}

const db = openDb(env);
await migrate(db);

if (cmd === "reconcile") {
const { reconcileRepos } = await import("./reconcile");
console.log("[projector] reconcile start:", env.PM_REPOS);
const result = await reconcileRepos(db, env);
console.log(JSON.stringify(result, null, 2));
} else if (cmd === "queue-view") {
const tasksPath = arg("tasks");
if (!tasksPath) {
console.error("queue-view: --tasks <file> is required (queue task records as JSON)");
process.exit(2);
}
const parsed = JSON.parse(readFileSync(tasksPath, "utf8")) as
| QueueTaskRecord[]
| { tasks: QueueTaskRecord[] };
const tasks = Array.isArray(parsed) ? parsed : parsed.tasks;
if (!Array.isArray(tasks)) {
console.error("queue-view: tasks file must be a JSON array or { tasks: [...] }");
process.exit(2);
}
const windowHours = Number(arg("window-hours") ?? "24");
const consumer = arg("consumer") ?? "queue-view";
// Consume BEFORE capturing the window end: consumeHotList pins the
// hot-list high-water, and the window end must be at or after that
// pin. Capturing `until` first would let an event appended after
// `until` but before the pin be consumed, filtered out of the view
// by the window, and then acked past — lost for good. With this
// order every consumed event has received_at <= pin <= until, and
// anything appended after the pin is neither consumed nor acked.
// (Codex finding on PR #8481, 2026-11-11.)
const consumed = await consumeHotList(db, consumer);
const until = new Date();
const since = new Date(until.getTime() - windowHours * 3_600_000);
const view = buildQueueView(tasks, consumed.events, {
since: since.toISOString(),
until: until.toISOString(),
consumer,
fromSeq: consumed.fromSeq,
highWater: consumed.highWater,
links: defaultTrendLinks(env),
});
console.log(JSON.stringify(view, null, 2));
if (!process.argv.includes("--no-ack")) {
const cursor = await consumed.ack();
console.error(`[projector] queue-view: consumer ${consumer} checkpoint acked at ${cursor}`);
}
} else {
console.error(`unknown command: ${cmd}`);
process.exit(2);
Expand Down
Loading
Loading