neurastream 0.2.63 → 0.2.65
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/adapters/omp/index.ts +97 -20
- package/src/adapters/omp/launch.ts +105 -52
- package/src/cli/claim.ts +79 -0
- package/src/cli/commands.ts +4 -0
- package/src/cli/dispatch.ts +4 -0
- package/src/core/brief-lint.ts +13 -6
- package/src/core/claims.ts +140 -0
- package/src/core/config.ts +6 -1
- package/src/core/guards.ts +171 -14
- package/src/core/notify.ts +76 -6
- package/src/core/owner-ui.ts +59 -20
- package/src/core/queue/lib.ts +23 -4
- package/src/core/queue-check.ts +5 -2
- package/src/core/queue-close.ts +6 -0
- package/src/core/rollover.ts +3 -3
- package/src/core/trace-actions.ts +9 -0
- package/src/core/watch.ts +14 -2
- package/templates/config.yml +3 -0
package/src/core/owner-ui.ts
CHANGED
|
@@ -13,12 +13,14 @@ import os from "node:os";
|
|
|
13
13
|
import { basename, resolve } from "node:path";
|
|
14
14
|
import type { RunSource } from "./adapter.ts";
|
|
15
15
|
import { chatTier, currentTier, type Tier } from "./autonomy.ts";
|
|
16
|
+
import { fileClaimStore } from "./claims.ts";
|
|
16
17
|
import type { Config } from "./config.ts";
|
|
17
18
|
import { nowSec, strftime } from "./clock.ts";
|
|
18
19
|
import { cpuCount } from "./host.ts";
|
|
19
20
|
import { dismissIncident, isFindingKind, openIncidents } from "./incidents.ts";
|
|
20
21
|
import { byText, knowledgeManifest, readKnowledgeTopicFile, urlField, urlValue, type KnowledgeEntry } from "./knowledge.ts";
|
|
21
|
-
import {
|
|
22
|
+
import { isBusy } from "./file-lock.ts";
|
|
23
|
+
import { log, MAIN_ID_RE } from "./guards.ts";
|
|
22
24
|
import { publishedPages } from "./pages-expiry.ts";
|
|
23
25
|
import { readMetricEvents } from "./metrics.ts";
|
|
24
26
|
import { activePlans, chatUnlock, dependencyOrderProblems, expandHome, gitTop, stateDirPath, unlockPath, writeIndex, type Plan } from "./queue/lib.ts";
|
|
@@ -156,6 +158,8 @@ export interface QueueRow {
|
|
|
156
158
|
waiting: boolean;
|
|
157
159
|
/** `Summary:` header, else the first Goal bullet with a leading Owner/INCIDENT prefix cut off. */
|
|
158
160
|
summary: string | null;
|
|
161
|
+
/** The Main id holding this plan's claim, else null (P5 multi-main). */
|
|
162
|
+
holder: string | null;
|
|
159
163
|
/** Chip text: waits you, waits on a plan, not started, phase K of N, or all N done. */
|
|
160
164
|
state: string;
|
|
161
165
|
}
|
|
@@ -256,15 +260,20 @@ function queueState(p: Plan, plans: Plan[]): string {
|
|
|
256
260
|
|
|
257
261
|
export function queueRows(cfg: Config): QueueRow[] {
|
|
258
262
|
const plans = activePlans(cfg.paths.queue_index).filter(p => p.status === "open");
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
263
|
+
const claims = fileClaimStore(cfg.paths.queue_state, nowSec, cfg.queue.claim_ttl_min);
|
|
264
|
+
return plans.map(p => {
|
|
265
|
+
const holder = claims.holder(p.file)?.main ?? null;
|
|
266
|
+
return {
|
|
267
|
+
repo: basename(p.repo),
|
|
268
|
+
file: p.file,
|
|
269
|
+
title: p.title,
|
|
270
|
+
status: p.status ?? "?",
|
|
271
|
+
waiting: p.waiting,
|
|
272
|
+
summary: p.summary ?? (goalSummary(p.goal[0] ?? "") || null),
|
|
273
|
+
state: queueState(p, plans),
|
|
274
|
+
holder,
|
|
275
|
+
};
|
|
276
|
+
});
|
|
268
277
|
}
|
|
269
278
|
|
|
270
279
|
export function ciRows(cfg: Config): CiRow[] {
|
|
@@ -382,6 +391,29 @@ function ownerMessagesDir(): string {
|
|
|
382
391
|
return `${stateDirPath()}/owner-messages`;
|
|
383
392
|
}
|
|
384
393
|
|
|
394
|
+
/** Main ids with a live running.lock in their main state dir (P5 multi-main): the page's picker list and the @-routing target set. */
|
|
395
|
+
export function runningMains(cfg: Config): string[] {
|
|
396
|
+
let dirs: string[];
|
|
397
|
+
try {
|
|
398
|
+
dirs = readdirSync(`${cfg.paths.queue_state}/mains`);
|
|
399
|
+
} catch {
|
|
400
|
+
return [];
|
|
401
|
+
}
|
|
402
|
+
return dirs
|
|
403
|
+
.filter(d => MAIN_ID_RE.test(d) && isBusy(`${cfg.paths.queue_state}/mains/${d}/running.lock`))
|
|
404
|
+
.toSorted();
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** Resolves where a message goes (P5 multi-main): an `@<id> ` prefix or the picker's `to` field names one running Main; empty is every Main. A stale target is refused before anything is stored. */
|
|
408
|
+
export function ownerMessageTarget(text: string, cfg: Config, formTo = ""): { to: string } | { refuse: string } {
|
|
409
|
+
const at = /^@([a-z0-9-]{1,24})(?:\s|$)/.exec(text);
|
|
410
|
+
const target = (at ? at[1] : formTo) ?? "";
|
|
411
|
+
if (!target || !MAIN_ID_RE.test(target)) return { to: "" };
|
|
412
|
+
const running = runningMains(cfg);
|
|
413
|
+
if (running.includes(target)) return { to: target };
|
|
414
|
+
return { refuse: `Main ${target} is not running; running: ${running.length ? running.join(", ") : "none"}` };
|
|
415
|
+
}
|
|
416
|
+
|
|
385
417
|
export interface MessageRow {
|
|
386
418
|
id: string;
|
|
387
419
|
ts: number;
|
|
@@ -466,9 +498,10 @@ export function recentOwnerMessages(now: number): MessageRow[] {
|
|
|
466
498
|
// ---- rendering (consumes the rows above, never the readers directly) ----
|
|
467
499
|
|
|
468
500
|
/** The "Tell Main" card: one textarea, image picks, a Send button — no chat thread. Under it, "Sent today": this view's messages newer than the keep window, newest first, thumbnails served from /message-image. */
|
|
469
|
-
function messageCard(messages: MessageRow[] | null): string {
|
|
501
|
+
function messageCard(messages: MessageRow[] | null, running: string[]): string {
|
|
470
502
|
const form = `<form class="msgform" method="post" action="/message" enctype="multipart/form-data">
|
|
471
503
|
<textarea name="text" maxlength="${MESSAGE_MAX}" rows="3" placeholder="What Main should know — a fix, a link, a photo"></textarea>
|
|
504
|
+
<select name="to"><option value="">All</option>${running.map(id => `<option value="${esc(id)}">Main ${esc(id)}</option>`).join("")}</select>
|
|
472
505
|
<input type="file" name="images" accept="image/*" multiple>
|
|
473
506
|
<button class="btn pri" type="submit">Send</button>
|
|
474
507
|
</form>`;
|
|
@@ -553,7 +586,7 @@ function queueHtml(rows: QueueRow[], tab: string): string {
|
|
|
553
586
|
<span class="qhandle" title="Drag to reorder" aria-label="Drag ${esc(r.title)}">≡</span>
|
|
554
587
|
<span class="qrank">${i + 1}</span>
|
|
555
588
|
<span class="qtitle">${esc(r.title)}${r.summary ? `<span class="qsum">${esc(r.summary)}</span>` : ""}</span>
|
|
556
|
-
<span class="chip ${r.state.startsWith("waits") ? "c-wait" : "c-ready"}">${esc(r.state)}</span>
|
|
589
|
+
${r.holder ? `<span class="chip c-held">Main ${esc(r.holder)}</span>` : ""}<span class="chip ${r.state.startsWith("waits") ? "c-wait" : "c-ready"}">${esc(r.state)}</span>
|
|
557
590
|
<span class="qbtns"><button type="button" class="qmove" data-move="top">↑ top</button><button type="button" class="qmove" data-move="up">↑</button><button type="button" class="qmove" data-move="down">↓</button></span>
|
|
558
591
|
</li>`,
|
|
559
592
|
)
|
|
@@ -1255,7 +1288,7 @@ export function renderPage(cfg: Config, data: PageData, params: URLSearchParams,
|
|
|
1255
1288
|
const machine = data.machine === null ? na("Machine") : machineHtml(cfg, data.machine);
|
|
1256
1289
|
const body =
|
|
1257
1290
|
tab === "now"
|
|
1258
|
-
? `${messageCard(data.messages)}
|
|
1291
|
+
? `${messageCard(data.messages, runningMains(cfg))}
|
|
1259
1292
|
<h1>Today</h1>
|
|
1260
1293
|
<p class="sub">What your agents did in the last 24 hours.</p>
|
|
1261
1294
|
<div class="card">
|
|
@@ -1385,6 +1418,7 @@ details.bg ul{margin:4px 0 8px;padding-left:20px;color:var(--mut);font-size:13px
|
|
|
1385
1418
|
.c-wait{background:color-mix(in srgb,var(--warn) 18%,transparent);color:var(--warn)}
|
|
1386
1419
|
.c-run{background:color-mix(in srgb,var(--teal) 18%,transparent);color:var(--teal)}
|
|
1387
1420
|
.c-ready{background:color-mix(in srgb,var(--mut) 15%,transparent);color:var(--mut)}
|
|
1421
|
+
.c-held{background:color-mix(in srgb,var(--acc) 15%,transparent);color:var(--acc)}
|
|
1388
1422
|
.chip.bad{color:var(--red)}
|
|
1389
1423
|
.qbtns{display:flex;gap:4px;flex-wrap:wrap;margin-left:auto}
|
|
1390
1424
|
.qbtns button{min-height:32px;padding:2px 10px;font-size:12px;border-radius:999px;border:1px solid var(--bd);background:var(--card);color:var(--mut)}
|
|
@@ -1520,13 +1554,13 @@ function handleIncident(cfg: Config, fields: Record<string, string>, login: stri
|
|
|
1520
1554
|
if (wantsJson) return jsonSent("incident-closed", receiptText("incident-closed", new URLSearchParams()));
|
|
1521
1555
|
return redirect(sentTo(fields.tab ?? "", "sent=incident-closed"));
|
|
1522
1556
|
}
|
|
1523
|
-
storeOwnerMessage(`${id}: it's a bug — plan it`, login, []);
|
|
1557
|
+
storeOwnerMessage(`${id}: it's a bug — plan it`, login, [], "");
|
|
1524
1558
|
if (wantsJson) return jsonSent("incident-bug", receiptText("incident-bug", new URLSearchParams()));
|
|
1525
1559
|
return redirect(sentTo(fields.tab ?? "", "sent=incident-bug"));
|
|
1526
1560
|
}
|
|
1527
1561
|
|
|
1528
1562
|
/** Stores an owner message (text and images) under a new id and inboxes it for Main (P13/P14). */
|
|
1529
|
-
function storeOwnerMessage(text: string, login: string, images: { bytes: Uint8Array; kind: string }[]): void {
|
|
1563
|
+
function storeOwnerMessage(text: string, login: string, images: { bytes: Uint8Array; kind: string }[], to: string): void {
|
|
1530
1564
|
const ts = nowSec();
|
|
1531
1565
|
// The dir name starts with a whole-second ts: the sweep and the image route both parse it.
|
|
1532
1566
|
const id = `${Math.floor(ts)}-${randomUUID().slice(0, 6)}`;
|
|
@@ -1538,21 +1572,23 @@ function storeOwnerMessage(text: string, login: string, images: { bytes: Uint8Ar
|
|
|
1538
1572
|
writeFileSync(`${dir}/${name}`, images[i]!.bytes);
|
|
1539
1573
|
names.push(name);
|
|
1540
1574
|
}
|
|
1541
|
-
writeFileSync(`${dir}/message.json`, `${JSON.stringify({ ts, text, login, images: names })}\n`);
|
|
1575
|
+
writeFileSync(`${dir}/message.json`, `${JSON.stringify({ ts, text, login, to, images: names })}\n`);
|
|
1542
1576
|
mkdirSync(stateDirPath(), { recursive: true });
|
|
1543
1577
|
// The text stays out of owner-inbox.jsonl; Main reads message.json through the id (P14).
|
|
1544
|
-
appendFileSync(inboxPath(), `${JSON.stringify({ ts, kind: "message", id, login })}\n`);
|
|
1578
|
+
appendFileSync(inboxPath(), `${JSON.stringify({ ts, kind: "message", id, login, to })}\n`);
|
|
1545
1579
|
}
|
|
1546
1580
|
|
|
1547
1581
|
// ---- POST /message (plan P13): the owner's one-way note plus images, inboxed by id ----
|
|
1548
1582
|
|
|
1549
|
-
async function handleMessage(req: Request, login: string, wantsJson: boolean): Promise<Response> {
|
|
1583
|
+
async function handleMessage(req: Request, cfg: Config, login: string, wantsJson: boolean): Promise<Response> {
|
|
1550
1584
|
sweepOwnerMessages(nowSec());
|
|
1551
1585
|
const form = await req.formData();
|
|
1552
1586
|
let text = "";
|
|
1587
|
+
let toField = "";
|
|
1553
1588
|
const files: File[] = [];
|
|
1554
1589
|
for (const [key, value] of form.entries()) {
|
|
1555
1590
|
if (key === "text" && typeof value === "string") text = value.trim();
|
|
1591
|
+
else if (key === "to" && typeof value === "string") toField = value;
|
|
1556
1592
|
// A form sent with no file chosen still carries one empty, nameless file part (Bun parses it as a nameless Blob).
|
|
1557
1593
|
else if (key === "images" && (value as unknown) instanceof Blob) {
|
|
1558
1594
|
const part = value as unknown as File;
|
|
@@ -1571,7 +1607,10 @@ async function handleMessage(req: Request, login: string, wantsJson: boolean): P
|
|
|
1571
1607
|
if (!kind) return fail("attachments must be PNG, JPEG, GIF or WEBP images — the type is read from the file itself");
|
|
1572
1608
|
images.push({ bytes: data, kind });
|
|
1573
1609
|
}
|
|
1574
|
-
|
|
1610
|
+
// P5: an `@<id>` prefix or the picker's to field names one Main; a stale name is refused before anything is stored.
|
|
1611
|
+
const pick = ownerMessageTarget(text, cfg, toField);
|
|
1612
|
+
if ("refuse" in pick) return fail(pick.refuse);
|
|
1613
|
+
storeOwnerMessage(text, login, images, pick.to);
|
|
1575
1614
|
if (wantsJson) return jsonSent("message", receiptText("message", new URLSearchParams()));
|
|
1576
1615
|
return redirect("/?sent=message");
|
|
1577
1616
|
}
|
|
@@ -1816,7 +1855,7 @@ res = pageRes(cfg, source, url.searchParams, resultsBuild, pagesHost);
|
|
|
1816
1855
|
// The page's script asks for JSON on every POST (P11b); a no-JS form post gets today's 303s.
|
|
1817
1856
|
const wantsJson = (req.headers.get("accept") ?? "").includes("application/json");
|
|
1818
1857
|
if (url.pathname === "/message") {
|
|
1819
|
-
res = await handleMessage(req, login, wantsJson);
|
|
1858
|
+
res = await handleMessage(req, cfg, login, wantsJson);
|
|
1820
1859
|
code = res.status;
|
|
1821
1860
|
} else if (url.pathname === "/incident") {
|
|
1822
1861
|
res = handleIncident(cfg, await fieldsOf(req), login, wantsJson);
|
package/src/core/queue/lib.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { accessSync, appendFileSync, chmodSync, constants, existsSync, mkdirSync
|
|
|
6
6
|
import os from "node:os";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import type { Config } from "../config.ts";
|
|
9
|
+
import type { ClaimStore } from "../claims.ts";
|
|
10
|
+
import { strftime } from "../clock.ts";
|
|
9
11
|
|
|
10
12
|
// --- landing detection (plan 20261031_0911 P4/P5): lives here, not queue-close.ts, because
|
|
11
13
|
// queueProblems' landed lock needs it and lib must not import the closer that imports lib ---
|
|
@@ -927,7 +929,7 @@ const STOP = new Set(
|
|
|
927
929
|
);
|
|
928
930
|
function keyWords(text: string): string[] {
|
|
929
931
|
const words = text.toLowerCase().match(/[a-z0-9][a-z0-9_.-]{3,}/g) ?? [];
|
|
930
|
-
return [...new Set(words.map(w => w.replace(/[._-]+$/, "")).filter(w => w.length >= 4 && !STOP.has(w)))].
|
|
932
|
+
return [...new Set(words.map(w => w.replace(/[._-]+$/, "")).filter(w => w.length >= 4 && !STOP.has(w)))].toSorted();
|
|
931
933
|
}
|
|
932
934
|
export function planWords(text: string): string[] {
|
|
933
935
|
const title = text.match(/^# (.+)$/m)?.[1] ?? "";
|
|
@@ -1142,6 +1144,12 @@ export function queueProblems(index = INDEX, blockersDir = BLOCKERS_DIR, reviewA
|
|
|
1142
1144
|
return probs;
|
|
1143
1145
|
}
|
|
1144
1146
|
|
|
1147
|
+
/** Queue ranks of the open queue plans an open plan waits on (I-20261025-208); empty when it is free to start. */
|
|
1148
|
+
export function openWaits(p: Plan, plans: Plan[], rank: Map<string, number>): number[] {
|
|
1149
|
+
if (p.status !== "open") return [];
|
|
1150
|
+
return p.waitsOn.map(f => rank.get(f)).filter((at): at is number => at !== undefined && plans[at - 1]!.status === "open");
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1145
1153
|
// P4 (plan 20261027_0915): from this day on, a Progress entry claiming a phase done/complete/
|
|
1146
1154
|
// "nothing left"/"finished" must quote that phase's verify command (or the Done check) and its
|
|
1147
1155
|
// result, or queue-check fails the plan; entries without a date or dated before it are grandfathered.
|
|
@@ -1203,17 +1211,24 @@ export function holdWarnings(plans: Plan[]): string[] {
|
|
|
1203
1211
|
// and passes `cap = Infinity`.
|
|
1204
1212
|
export const SUMMARY_CAP = 10;
|
|
1205
1213
|
|
|
1206
|
-
export function queueSummary(index = INDEX, reviewAgents: string[] = [],
|
|
1214
|
+
export function queueSummary(index = INDEX, reviewAgents: string[] = [], staleOrClaims: ReadonlySet<string> | ClaimStore | null = null, cap: number = SUMMARY_CAP): string {
|
|
1207
1215
|
// Index order IS priority (20261025_0215_index_priority): the list is flat and ranked,
|
|
1208
1216
|
// rank 1 = the index's top line; repos only surface through each plan's own path.
|
|
1209
1217
|
const plans = activePlans(index);
|
|
1210
1218
|
const rank = new Map(plans.map((p, i) => [p.file, i + 1] as const));
|
|
1211
1219
|
const repos = [...new Set(plans.map(p => p.repo))];
|
|
1212
1220
|
const lines = [`Queue (${index}): ${plans.length ? `${plans.length} plan(s) in ${repos.length} repo(s)` : "empty, no open work"}`];
|
|
1221
|
+
let claimStore: ClaimStore | null = null;
|
|
1222
|
+
let stale: ReadonlySet<string> = new Set<string>();
|
|
1223
|
+
if (staleOrClaims != null && typeof (staleOrClaims as ClaimStore).holder === 'function') {
|
|
1224
|
+
claimStore = staleOrClaims as ClaimStore;
|
|
1225
|
+
} else {
|
|
1226
|
+
stale = staleOrClaims as ReadonlySet<string> ?? new Set<string>();
|
|
1227
|
+
}
|
|
1213
1228
|
plans.slice(0, cap).forEach((p, i) => {
|
|
1214
1229
|
const status = awaitingMerge(p) ? "complete, awaiting merge" : (p.status ?? "INVALID");
|
|
1215
1230
|
const ask = (p.waitingLine ?? "").slice(0, 80);
|
|
1216
|
-
const hold = p.waiting ? (stale
|
|
1231
|
+
const hold = p.waiting ? (stale?.has(p.file) ? `[STALE?] ${ask}` : `WAITING on owner: ${ask}`) : "";
|
|
1217
1232
|
// I-20261025-208: an open plan waiting on an open plan of the queue shows the target's rank.
|
|
1218
1233
|
const waits: string[] = [];
|
|
1219
1234
|
if (p.status === "open")
|
|
@@ -1223,7 +1238,11 @@ export function queueSummary(index = INDEX, reviewAgents: string[] = [], stale:
|
|
|
1223
1238
|
waits.push(`waits on #${at}`);
|
|
1224
1239
|
}
|
|
1225
1240
|
const done = p.phases.total ? `${p.phases.done}/${p.phases.total} done` : "";
|
|
1226
|
-
|
|
1241
|
+
// P4 multi-main (20261027_1300): with the claim store handed in (guards' inject and
|
|
1242
|
+
// queue-check pass it), every plan shows `held by <id> since HH:MM` or `free`.
|
|
1243
|
+
const holder = claimStore?.holder(p.file) ?? null;
|
|
1244
|
+
const claimFlag = claimStore ? (holder ? `held by ${holder.main} since ${strftime(holder.since, "%H:%M")}` : "free") : "";
|
|
1245
|
+
const flags = [status, done, hold, ...waits, claimFlag, p.priorityId ?? ""].filter(Boolean).join(", ");
|
|
1227
1246
|
const goal = items(sections(p.text).get("goal") ?? "")[0]?.slice(0, 100) ?? "";
|
|
1228
1247
|
lines.push(` ${i + 1}. ${p.file} [${flags}] ${goal}`);
|
|
1229
1248
|
});
|
package/src/core/queue-check.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Config } from "./config.ts";
|
|
2
|
+
import { fileClaimStore } from "./claims.ts";
|
|
3
|
+
import { nowSec } from "./clock.ts";
|
|
2
4
|
import { applyQueueEnv } from "./queue/env.ts";
|
|
3
5
|
import { activePlans, allowedAgents, holdWarnings, queueProblems, queueSummary, reviewAgentsProblem } from "./queue/lib.ts";
|
|
4
6
|
import { mrSweep } from "./mr-sweep.ts";
|
|
5
|
-
import { recheckHolds,
|
|
7
|
+
import { recheckHolds, staleHoldLines } from "./waiting-check.ts";
|
|
6
8
|
|
|
7
9
|
// One index (20261024_1400_one_index): the main index lists plan files directly, so there are no
|
|
8
10
|
// repo INDEX.md files to git-check and no work_roots scan; the queue problems carry the
|
|
@@ -13,9 +15,10 @@ export function queueCheck(args: string[], cfg: Config): number {
|
|
|
13
15
|
for (const p of activePlans()) if (p.priorityId && !p.waiting && p.status === "open") console.log(p.priorityId);
|
|
14
16
|
return 0;
|
|
15
17
|
}
|
|
18
|
+
const claims = fileClaimStore(cfg.paths.queue_state, nowSec, cfg.queue.claim_ttl_min);
|
|
16
19
|
const plans = activePlans();
|
|
17
20
|
const holds = recheckHolds(cfg, plans);
|
|
18
|
-
console.log(queueSummary(undefined, cfg.review.agents,
|
|
21
|
+
console.log(queueSummary(undefined, cfg.review.agents, claims, Infinity));
|
|
19
22
|
for (const line of staleHoldLines(holds, plans)) console.log(line);
|
|
20
23
|
// main-start prints the sweep itself and passes this so the child bin does not print it twice.
|
|
21
24
|
let fail = queueProblems(undefined, undefined, cfg.review.agents).length > 0;
|
package/src/core/queue-close.ts
CHANGED
|
@@ -2,7 +2,10 @@ 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
7
|
import type { Config } from "./config.ts";
|
|
8
|
+
import { mainId } from "./guards.ts";
|
|
6
9
|
import { applyQueueEnv } from "./queue/env.ts";
|
|
7
10
|
import { activePlans, cancelledFile, cancelledLine, closeLog, finishedEntry, finishedPath, gitOut as git, INDEX, landed, prependFinished, sha, STATE_DIR, writeIndex } from "./queue/lib.ts";
|
|
8
11
|
import { fixedIncident } from "./incidents.ts";
|
|
@@ -316,6 +319,9 @@ export function queueClose(args: string[], cfg: Config): number {
|
|
|
316
319
|
}
|
|
317
320
|
if (recorded.length) console.log(`queue-close: recorded fixed for ${recorded.join(", ")}`);
|
|
318
321
|
}
|
|
322
|
+
// Multi-main P3: closing the plan frees this Main's claim; another Main's claim stays
|
|
323
|
+
// (release is keyed by the holder).
|
|
324
|
+
fileClaimStore(cfg.paths.queue_state, nowSec, cfg.queue.claim_ttl_min).release(file, mainId());
|
|
319
325
|
console.log("queue-close: CLOSED");
|
|
320
326
|
return 0;
|
|
321
327
|
}
|
package/src/core/rollover.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
// the jobs and the note mtime, and performs the switch. No harness names here.
|
|
6
6
|
|
|
7
7
|
import { join } from "node:path";
|
|
8
|
+
import { mainStateDir } from "./guards.ts";
|
|
8
9
|
import { strftime } from "./clock.ts";
|
|
9
|
-
import { stateDirPath } from "./queue/lib.ts";
|
|
10
10
|
import type { OwnerAnswer, OwnerMessage } from "./incidents.ts";
|
|
11
11
|
|
|
12
12
|
export type RolloverState = "below" | "need-note" | "wait-jobs" | "ready";
|
|
@@ -167,11 +167,11 @@ export function noteRequest(path: string, reason = ""): string {
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
/** Where Main writes the handoff note for one session. */
|
|
170
|
-
export function notePath(sessionId: string, stateDir =
|
|
170
|
+
export function notePath(sessionId: string, stateDir = mainStateDir()): string {
|
|
171
171
|
return join(stateDir, "rollover", `${sessionId}.md`);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
/** The launcher's relaunch request file: written by the harness just before it exits under `neurastream main`. */
|
|
175
|
-
export function relaunchPath(stateDir =
|
|
175
|
+
export function relaunchPath(stateDir = mainStateDir()): string {
|
|
176
176
|
return join(stateDir, "rollover", "relaunch.json");
|
|
177
177
|
}
|
|
@@ -381,6 +381,12 @@ export interface OwnRun {
|
|
|
381
381
|
* it, so it replaces the final-text check below.
|
|
382
382
|
*/
|
|
383
383
|
claimedNone?: boolean;
|
|
384
|
+
/**
|
|
385
|
+
* Read paths named in the run's brief text (cfg.brief.path_prefixes), extracted the
|
|
386
|
+
* brief-lint way. A read whose target globMatches one is skipped as a D7 finding: the
|
|
387
|
+
* owner deliberately pointed the sub at that path in the brief.
|
|
388
|
+
*/
|
|
389
|
+
allowed?: string[];
|
|
384
390
|
}
|
|
385
391
|
|
|
386
392
|
export interface UnreportedFinding {
|
|
@@ -469,6 +475,9 @@ export function unreportedFindings(events: TraceEvent[], rules: ActionsRules, ow
|
|
|
469
475
|
const t = expandHome(raw, rules.home);
|
|
470
476
|
const repo = ownedRepoOf(t, rules.owned_repos);
|
|
471
477
|
if (repo === null || segKey(repo) === ownKey) continue;
|
|
478
|
+
// P10c: a read whose path matches a path the run's brief text names is not an
|
|
479
|
+
// unreported finding — the owner deliberately pointed the sub at it.
|
|
480
|
+
if (own.allowed?.some((p) => globMatch(p, t, rules.home))) continue;
|
|
472
481
|
const id = `${repo}:${t}`;
|
|
473
482
|
if (seen.has(id)) continue;
|
|
474
483
|
seen.add(id);
|
package/src/core/watch.ts
CHANGED
|
@@ -23,7 +23,7 @@ import { readBeats, type Heartbeat } from "./heartbeat.ts";
|
|
|
23
23
|
import { runDetectorsGated, type GatedInputs } from "./incident-detectors.ts";
|
|
24
24
|
import { log, readStaffingEntries } from "./guards.ts";
|
|
25
25
|
import { appendMetric, inWindow, readBlocks, readMetricEvents, reasonKey, type Window } from "./metrics.ts";
|
|
26
|
-
import { notifyProviders } from "./notify.ts";
|
|
26
|
+
import { notifyProviders, waitingOwnerMessages } from "./notify.ts";
|
|
27
27
|
import { addIncident, dismissIncident, openIncidents, readIncidents, type IncidentView } from "./incidents.ts";
|
|
28
28
|
import { m7, rowsOf, silentFailures, snap } from "./report.ts";
|
|
29
29
|
import { loadKnownSecrets, redactSecrets } from "./secret-redact.ts";
|
|
@@ -105,6 +105,8 @@ export interface WatchReport {
|
|
|
105
105
|
closed: IncidentView[];
|
|
106
106
|
/** Incidents the gated detectors folded themselves (their own sources and kinds). */
|
|
107
107
|
detectors: IncidentView[];
|
|
108
|
+
/** Owner messages that first crossed notify.answer_within_min this pass (M8, P9). */
|
|
109
|
+
ownerWaits: number;
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
/** One problem the watcher found: exactly one addIncident input plus the fields its ⚠ post
|
|
@@ -269,7 +271,17 @@ export function watchOnce(cfg: Config, deps: WatchDeps): WatchReport {
|
|
|
269
271
|
notify: text => deps.notify(cfg.secrets.redact ? redactSecrets(text, loadKnownSecrets(cfg), cfg.secrets.extra_patterns).text : text),
|
|
270
272
|
});
|
|
271
273
|
}
|
|
272
|
-
|
|
274
|
+
// (f) P9: an owner message that crossed notify.answer_within_min with no hand-back counts M8,
|
|
275
|
+
// one metric per message — the ledger is the once-only marker, not per-pass state.
|
|
276
|
+
let ownerWaits = 0;
|
|
277
|
+
const m8Done = new Set(readMetricEvents(cfg).filter(e => e.type === "m8").map(e => String(e.id)));
|
|
278
|
+
for (const m of waitingOwnerMessages(cfg, now)) {
|
|
279
|
+
if (m8Done.has(m.id)) continue;
|
|
280
|
+
appendMetric(cfg, { type: "m8", id: m.id, waited_sec: now - m.ts, ts: now });
|
|
281
|
+
ownerWaits++;
|
|
282
|
+
}
|
|
283
|
+
if (ownerWaits > 0) log(cfg.paths.guard_log, `watch: M8 ${ownerWaits} owner wait(s) past notify.answer_within_min`);
|
|
284
|
+
return { opened, deduped, closed, detectors, ownerWaits };
|
|
273
285
|
}
|
|
274
286
|
|
|
275
287
|
// ---- P11: the release verdict — is the new version better or worse? ----
|
package/templates/config.yml
CHANGED
|
@@ -111,6 +111,8 @@ queue:
|
|
|
111
111
|
auto_close_min: 15
|
|
112
112
|
repo_index: "INDEX.md"
|
|
113
113
|
cancelled_rel: "docs/plans/CANCELLED.md"
|
|
114
|
+
# Minutes without a heartbeat before a Main's plan claim frees (src/core/claims.ts).
|
|
115
|
+
claim_ttl_min: 30
|
|
114
116
|
waiting_check_ttl_sec: 600 # a hold's `still true if` result is reused this long (key: plan mtime, command, HEAD)
|
|
115
117
|
waiting_check_timeout_sec: 60 # one check may run this long; a timeout is "unknown" (card stays, no incident)
|
|
116
118
|
|
|
@@ -240,6 +242,7 @@ notify:
|
|
|
240
242
|
discord_webhook_file: "" # file holding the Discord webhook URL; "" = off (README: Notify the owner)
|
|
241
243
|
slack_webhook_file: "" # file holding the Slack webhook URL; "" = off
|
|
242
244
|
prefix: "" # optional label prepended to each posted reply, e.g. "Main:"
|
|
245
|
+
answer_within_min: 3 # minutes an owner message may wait before the tool-result steer steers Main to answer it now (0 = off)
|
|
243
246
|
|
|
244
247
|
secrets: # content redaction (src/core/secret-redact.ts); a hit prints as [REDACTED:<type>]
|
|
245
248
|
redact: true # every tool result, every notify post and `neurastream redact` go through the redactor
|