neurastream 0.2.85 → 0.3.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.
package/src/core/pages.ts CHANGED
@@ -23,7 +23,7 @@ export function startPagesServer(opts: PagesOptions): PagesServer {
23
23
  if (req.method !== "GET" && req.method !== "HEAD" && req.method !== "POST") return plain("method not allowed", 405);
24
24
  const peer = peerOf(req, srv);
25
25
  const login = isLoopback(peer) ? null : isTailnet(peer) ? opts.tailscale.whois(peer) : null;
26
- if (!isLoopback(peer) && (!login || login !== opts.cfg.ui.owner_login)) return plain("forbidden", 403);
26
+ if (!isLoopback(peer) && (!login || login !== opts.cfg.workspace.owner_login)) return plain("forbidden", 403);
27
27
  const url = new URL(req.url);
28
28
  // The one POST a page may make (plan 20261026 P6): the notes its script collected become owner-inbox
29
29
  // rows Main delivers. Same origin only, so another site's tab cannot write to the inbox; nothing here
@@ -346,7 +346,7 @@ function executable(p: string): boolean {
346
346
  }
347
347
  }
348
348
 
349
- function headerField(text: string, name: string): string | null {
349
+ export function headerField(text: string, name: string): string | null {
350
350
  const m = text.split(/^## /m)[0]?.match(new RegExp(`^${name}:\\s*(.+?)\\s*$`, "m"));
351
351
  const v = m?.[1];
352
352
  return v ? v.replace(/`/g, "").trim() || null : null;
@@ -371,7 +371,12 @@ function reuseProblems(repo: string, file: string, secs: Map<string, string>, re
371
371
  return probs;
372
372
  }
373
373
 
374
- export function parsePlan(repo: string, file: string, text: string | null, blockersDir = blockersDirPath(), reviewAgents: string[] = []): Plan {
374
+ /**
375
+ * `localPaths` false is for text that came from a team server (P4): it names paths on its
376
+ * author's machine, so nothing here may stat this machine's disk — no blocker executable()
377
+ * check and no reuse existsSync. Its blockers are `[]`; every other field is parsed as usual.
378
+ */
379
+ export function parsePlan(repo: string, file: string, text: string | null, blockersDir = blockersDirPath(), reviewAgents: string[] = [], localPaths = true): Plan {
375
380
  const empty = { repo, file, text: "", status: null, blockers: [], doneCheck: null, worktree: null, branch: null, appliesTo: [], waiting: false, waitingLine: null, waitingAsk: null, waitingBlocked: null, waitingWhy: null, waitingCheck: null, waitsOn: [], priorityId: null, title: path.basename(file), goal: [], summary: null, phases: { done: 0, total: 0 }, started: false };
376
381
  if (text === null) return { ...empty, errors: ["plan file listed in the index does not exist"] };
377
382
  const errors: string[] = [];
@@ -383,7 +388,7 @@ export function parsePlan(repo: string, file: string, text: string | null, block
383
388
  const stamp = /^(\d{8}_\d{4})/.exec(path.basename(file))?.[1] ?? "";
384
389
  if (stamp >= READ_CUTOVER && !items(secs.get("code read by main") ?? "").length)
385
390
  errors.push(`missing or empty "## Code read by Main" section (plans stamped ${READ_CUTOVER} or later list each file they cite)`);
386
- for (const problem of reuseProblems(repo, file, secs, reviewAgents)) errors.push(problem);
391
+ for (const problem of localPaths ? reuseProblems(repo, file, secs, reviewAgents) : []) errors.push(problem);
387
392
  const known = new Set([...REQUIRED, "applies to", "background", "code read by main", "reuse"]);
388
393
  for (const s of secs.keys()) if (!known.has(s)) errors.push(`unknown section "## ${s}" (allowed: ${[...known].join(", ")})`);
389
394
  const status = statusOf(text);
@@ -391,7 +396,7 @@ export function parsePlan(repo: string, file: string, text: string | null, block
391
396
  if (status === "cancelled" && !/^Cancelled by owner:\s*\S.{5,}/m.test(progressBody(text)))
392
397
  errors.push('a cancelled plan needs a Progress line: Cancelled by owner: <date> "<the owner\'s words>"');
393
398
  const blockers: Blocker[] = [];
394
- for (const line of items(secs.get("blockers") ?? "")) {
399
+ for (const line of localPaths ? items(secs.get("blockers") ?? "") : []) {
395
400
  const [ref = "", ...args] = line.replace(/`/g, "").split(/\s+/);
396
401
  const script = ref.includes("/") ? path.resolve(path.dirname(file), expandHome(ref)) : path.join(blockersDir, ref);
397
402
  if (!executable(script)) errors.push(`blocker "${ref}": ${script} missing or not executable`);
@@ -407,6 +412,9 @@ export function parsePlan(repo: string, file: string, text: string | null, block
407
412
  if (secs.has("done check") && !doneCheck) errors.push('"## Done check" needs one command in backticks (exit 0 = done)');
408
413
  const bg = (secs.get("background") ?? "").split("\n").filter(l => l.trim()).length;
409
414
  if (bg > BACKGROUND_MAX_LINES) errors.push(`"## Background" has ${bg} lines (max ${BACKGROUND_MAX_LINES}); link a separate file for long context`);
415
+ const queue = headerField(text, "Queue");
416
+ if (queue !== null && queue !== "team" && queue !== "personal")
417
+ errors.push(`Queue: header must be "team" or "personal" (got "${queue}"; absent means personal)`);
410
418
  const wt = headerField(text, "Worktree");
411
419
  const waitingLine = text.match(/^WAITING on owner:[ \t]*(.*)$/m)?.[1] ?? null;
412
420
  const waitingParts = waitingLine === null ? { ask: null, blocked: null, why: null, check: null } : splitWaiting(waitingLine);
@@ -1159,8 +1167,11 @@ export function openWaits(p: Plan, plans: Plan[], rank: Map<string, number>): nu
1159
1167
  // result, or queue-check fails the plan; entries without a date or dated before it are grandfathered.
1160
1168
  export const DONE_CLAIM_SINCE = "2026-11-01";
1161
1169
 
1162
- const DONE_WORD = /\b(?:done|completed?|nothing left|finished)\b/i;
1170
+ // "Done check" is a plan section name, not a claim.
1171
+ const DONE_WORD_SRC = String.raw`(?:done(?!\s+check)|completed?|nothing left|finished)`;
1163
1172
  const NOT_DONE = /\b(?:not|never)\s+(?:done|completed?|finished)\b/i;
1173
+ // A reviewer's PLAN/CODE REVIEW entry critiques a plan; it claims no phase done.
1174
+ const REVIEW_ENTRY = /\b(?:PLAN|CODE) REVIEW:/;
1164
1175
  const RESULT_MARK = /\bexit(?: code|ed)?\s*\d|\b\d+ pass|\b\d+ fail|\bpass(?:ed|ing)?\b|\bfail(?:ed|ing)?\b|\bresult\b/i;
1165
1176
 
1166
1177
  /** Progress entries: the "- " line plus the lines up to the next entry start (trimProgressBody's rule). */
@@ -1177,6 +1188,12 @@ function progressEntryBlocks(text: string): string[] {
1177
1188
  return blocks;
1178
1189
  }
1179
1190
 
1191
+ /** Phase ids the entry says are done: a done word within 40 characters of the id, in the same sentence. */
1192
+ function claimedPhases(entry: string): string[] {
1193
+ const ids = new Set([...entry.matchAll(/\b(P\d+[a-z]?)\b/g)].map(m => m[1]!));
1194
+ return [...ids].filter(id => new RegExp(String.raw`\b${id}\b[^.;\n]{0,40}\b${DONE_WORD_SRC}\b|\b${DONE_WORD_SRC}\b[^.;\n]{0,40}\b${id}\b`, "i").test(entry)).map(id => id.toUpperCase());
1195
+ }
1196
+
1180
1197
  /** A dated done claim about phase Pn must quote Pn's verify (or the Done check) with its result; else one problem per entry. */
1181
1198
  function doneClaimProblems(p: Plan): QueueProblem[] {
1182
1199
  const probs: QueueProblem[] = [];
@@ -1188,8 +1205,8 @@ function doneClaimProblems(p: Plan): QueueProblem[] {
1188
1205
  }
1189
1206
  for (const entry of progressEntryBlocks(p.text)) {
1190
1207
  const date = /^- (\d{4}-\d{2}-\d{2})/.exec(entry)?.[1];
1191
- if (!date || date < DONE_CLAIM_SINCE || !DONE_WORD.test(entry) || NOT_DONE.test(entry)) continue;
1192
- const ids = [...entry.matchAll(/\b(P\d+[a-z]?)\b/g)].map(m => m[1]!.toUpperCase());
1208
+ if (!date || date < DONE_CLAIM_SINCE || REVIEW_ENTRY.test(entry.split("\n")[0]!) || NOT_DONE.test(entry)) continue;
1209
+ const ids = claimedPhases(entry);
1193
1210
  if (!ids.length) continue;
1194
1211
  const backings = [...new Set(ids.flatMap(id => verifies.get(id) ?? []))];
1195
1212
  if (p.doneCheck) backings.push(p.doneCheck);
@@ -1215,17 +1232,17 @@ export function holdWarnings(plans: Plan[]): string[] {
1215
1232
  // and passes `cap = Infinity`.
1216
1233
  export const SUMMARY_CAP = 10;
1217
1234
 
1218
- export function queueSummary(index = INDEX, reviewAgents: string[] = [], staleOrClaims: ReadonlySet<string> | ClaimStore | null = null, cap: number = SUMMARY_CAP): string {
1235
+ export function queueSummary(index = INDEX, reviewAgents: string[] = [], staleOrClaims: ReadonlySet<string> | Pick<ClaimStore, "holder"> | null = null, cap: number = SUMMARY_CAP): string {
1219
1236
  // Index order IS priority (20261025_0215_index_priority): the list is flat and ranked,
1220
1237
  // rank 1 = the index's top line; repos only surface through each plan's own path.
1221
1238
  const plans = activePlans(index);
1222
1239
  const rank = new Map(plans.map((p, i) => [p.file, i + 1] as const));
1223
1240
  const repos = [...new Set(plans.map(p => p.repo))];
1224
1241
  const lines = [`Queue (${index}): ${plans.length ? `${plans.length} plan(s) in ${repos.length} repo(s)` : "empty, no open work"}`];
1225
- let claimStore: ClaimStore | null = null;
1242
+ let claimStore: Pick<ClaimStore, "holder"> | null = null;
1226
1243
  let stale: ReadonlySet<string> = new Set<string>();
1227
- if (staleOrClaims != null && typeof (staleOrClaims as ClaimStore).holder === 'function') {
1228
- claimStore = staleOrClaims as ClaimStore;
1244
+ if (staleOrClaims != null && typeof (staleOrClaims as Pick<ClaimStore, "holder">).holder === 'function') {
1245
+ claimStore = staleOrClaims as Pick<ClaimStore, "holder">;
1229
1246
  } else {
1230
1247
  stale = staleOrClaims as ReadonlySet<string> ?? new Set<string>();
1231
1248
  }
@@ -1245,7 +1262,13 @@ export function queueSummary(index = INDEX, reviewAgents: string[] = [], staleOr
1245
1262
  // P4 multi-main (20261027_1300): with the claim store handed in (guards' inject and
1246
1263
  // queue-check pass it), every plan shows `held by <id> since HH:MM` or `free`.
1247
1264
  const holder = claimStore?.holder(p.file) ?? null;
1248
- const claimFlag = claimStore ? (holder ? `held by ${holder.main} since ${strftime(holder.since, "%H:%M")}` : "free") : "";
1265
+ const claimFlag = claimStore
1266
+ ? (holder === null
1267
+ ? "free"
1268
+ : "unreachable" in holder
1269
+ ? `team server ${holder.unreachable} unreachable`
1270
+ : `held by ${holder.main} since ${strftime(holder.since, "%H:%M")}`)
1271
+ : "";
1249
1272
  const flags = [status, done, hold, ...waits, claimFlag, p.priorityId ?? ""].filter(Boolean).join(", ");
1250
1273
  const goal = items(sections(p.text).get("goal") ?? "")[0]?.slice(0, 100) ?? "";
1251
1274
  lines.push(` ${i + 1}. ${p.file} [${flags}] ${goal}`);
@@ -1,9 +1,8 @@
1
1
  import type { Config } from "./config.ts";
2
- import { fileClaimStore } from "./claims.ts";
3
- import { nowSec } from "./clock.ts";
4
2
  import { applyQueueEnv } from "./queue/env.ts";
5
3
  import { activePlans, allowedAgents, holdWarnings, queueProblems, queueSummary, reviewAgentsProblem } from "./queue/lib.ts";
6
4
  import { mrSweep } from "./mr-sweep.ts";
5
+ import { summaryHolder, teamSummaryLines, teamViews } from "./team-client.ts";
7
6
  import { recheckHolds, staleHoldLines } from "./waiting-check.ts";
8
7
 
9
8
  // One index (20261024_1400_one_index): the main index lists plan files directly, so there are no
@@ -15,10 +14,13 @@ export function queueCheck(args: string[], cfg: Config): number {
15
14
  for (const p of activePlans()) if (p.priorityId && !p.waiting && p.status === "open") console.log(p.priorityId);
16
15
  return 0;
17
16
  }
18
- const claims = fileClaimStore(cfg.paths.queue_state, nowSec, cfg.queue.claim_ttl_min);
17
+ // P4 (20261027_1305): one GET /view per team, read once for the holder and the team lines.
18
+ const views = teamViews(cfg);
19
+ const claims = summaryHolder(cfg, {}, views);
19
20
  const plans = activePlans();
20
21
  const holds = recheckHolds(cfg, plans);
21
22
  console.log(queueSummary(undefined, cfg.review.agents, claims, Infinity));
23
+ for (const line of teamSummaryLines(cfg, views, Infinity)) console.log(line);
22
24
  for (const line of staleHoldLines(holds, plans)) console.log(line);
23
25
  // main-start prints the sweep itself and passes this so the child bin does not print it twice.
24
26
  let fail = queueProblems(undefined, undefined, cfg.review.agents).length > 0;
@@ -2,8 +2,8 @@ import { spawnSync } from "node:child_process";
2
2
  import { appendFileSync, existsSync, fstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
3
3
  import os from "node:os";
4
4
  import path from "node:path";
5
- import { fileClaimStore } from "./claims.ts";
6
- import { nowSec } from "./clock.ts";
5
+ import { claimStoreFor } from "./team-client.ts";
6
+
7
7
  import type { Config } from "./config.ts";
8
8
  import { mainId } from "./guards.ts";
9
9
  import { applyQueueEnv } from "./queue/env.ts";
@@ -321,7 +321,7 @@ export function queueClose(args: string[], cfg: Config): number {
321
321
  }
322
322
  // Multi-main P3: closing the plan frees this Main's claim; another Main's claim stays
323
323
  // (release is keyed by the holder).
324
- fileClaimStore(cfg.paths.queue_state, nowSec, cfg.queue.claim_ttl_min).release(file, mainId());
324
+ claimStoreFor(file, cfg).release(file, mainId());
325
325
  console.log("queue-close: CLOSED");
326
326
  return 0;
327
327
  }