neurastream 0.3.18 → 0.3.20
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/README.md +88 -490
- package/package.json +1 -1
- package/src/adapters/omp/index.ts +66 -54
- package/src/adapters/omp/launch.ts +4 -6
- package/src/cli/claim.ts +1 -3
- package/src/cli/dispatch.ts +25 -21
- package/src/cli/guard.ts +0 -3
- package/src/cli/incident.ts +2 -2
- package/src/cli/metrics.ts +1 -1
- package/src/cli/recall.ts +3 -6
- package/src/cli/results-build.ts +1 -3
- package/src/cli/workspace.ts +0 -3
- package/src/core/autonomy.ts +24 -21
- package/src/core/guards.ts +189 -192
- package/src/core/incidents.ts +13 -12
- package/src/core/main-start.ts +1 -1
- package/src/core/mr-sweep.ts +4 -2
- package/src/core/notify.ts +15 -15
- package/src/core/owner-log.ts +19 -17
- package/src/core/owner-topics.ts +36 -35
- package/src/core/owner-ui.ts +54 -51
- package/src/core/pages.ts +3 -4
- package/src/core/plan-approval.ts +18 -18
- package/src/core/queue/lib.ts +89 -105
- package/src/core/queue-cancel.ts +20 -10
- package/src/core/queue-check.ts +5 -7
- package/src/core/queue-close.ts +8 -8
- package/src/core/queue-finished.ts +9 -10
- package/src/core/queue-migrate.ts +1 -3
- package/src/core/queue-trim.ts +2 -4
- package/src/core/results.ts +0 -2
- package/src/core/rollover.ts +2 -3
- package/src/core/team-client.ts +5 -4
- package/src/core/watch.ts +3 -2
- package/src/core/queue/env.ts +0 -14
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import type { Config } from "./config.ts";
|
|
6
|
-
import { applyQueueEnv } from "./queue/env.ts";
|
|
7
6
|
import { finishedEntry, finishedKey, finishedPath, parsePlan, planRepo, prependFinished, repoRoot } from "./queue/lib.ts";
|
|
8
7
|
|
|
9
8
|
const USAGE = "usage: queue-finished --backfill | --dedupe | queue-finished <word>";
|
|
@@ -92,23 +91,24 @@ function backfill(cfg: Config): number {
|
|
|
92
91
|
} catch {
|
|
93
92
|
return null;
|
|
94
93
|
}
|
|
95
|
-
const plan = parsePlan(planRepo(file), file, raw);
|
|
94
|
+
const plan = parsePlan(planRepo(file), file, raw, cfg.paths.blockers, [], true, cfg.paths.agent_dir);
|
|
96
95
|
return plan.status === "complete" ? plan : null;
|
|
97
96
|
})
|
|
98
97
|
.filter(p => p !== null)
|
|
99
98
|
.sort((a, b) => (path.basename(a.file) < path.basename(b.file) ? -1 : 1));
|
|
100
99
|
let added = 0;
|
|
100
|
+
const target = finishedPath(cfg.paths);
|
|
101
101
|
// Oldest first so each prepend leaves the newer entry on top.
|
|
102
102
|
for (const plan of plans) {
|
|
103
|
-
if (prependFinished(finishedEntry(plan, plan.file, stampDate(plan.file)))) added++;
|
|
103
|
+
if (prependFinished(finishedEntry(plan, plan.file, stampDate(plan.file)), target)) added++;
|
|
104
104
|
}
|
|
105
105
|
console.log(`queue-finished: backfill added ${added} (${plans.length} complete archived)`);
|
|
106
106
|
return 0;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
/** Keeps the first entry for each finished key and drops later repeats. */
|
|
110
|
-
function dedupe(): number {
|
|
111
|
-
const file = finishedPath();
|
|
110
|
+
function dedupe(cfg: Config): number {
|
|
111
|
+
const file = finishedPath(cfg.paths);
|
|
112
112
|
let text = "";
|
|
113
113
|
try {
|
|
114
114
|
text = readFileSync(file, "utf8");
|
|
@@ -133,10 +133,10 @@ function entries(text: string): string[] {
|
|
|
133
133
|
return text.split(/^(?=## )/m).filter(p => p.startsWith("## ")).map(p => p.trimEnd());
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
function search(word: string): number {
|
|
136
|
+
function search(word: string, cfg: Config): number {
|
|
137
137
|
let text = "";
|
|
138
138
|
try {
|
|
139
|
-
text = readFileSync(finishedPath(), "utf8");
|
|
139
|
+
text = readFileSync(finishedPath(cfg.paths), "utf8");
|
|
140
140
|
} catch {}
|
|
141
141
|
const needle = word.toLowerCase();
|
|
142
142
|
const hits = entries(text).filter(e => e.toLowerCase().includes(needle));
|
|
@@ -149,17 +149,16 @@ function search(word: string): number {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
export function queueFinished(args: string[], cfg: Config): number {
|
|
152
|
-
applyQueueEnv(cfg);
|
|
153
152
|
if (args[0] === "--help" || args[0] === "-h") {
|
|
154
153
|
console.log(USAGE);
|
|
155
154
|
return 0;
|
|
156
155
|
}
|
|
157
156
|
if (args.includes("--backfill")) return backfill(cfg);
|
|
158
|
-
if (args.includes("--dedupe")) return dedupe();
|
|
157
|
+
if (args.includes("--dedupe")) return dedupe(cfg);
|
|
159
158
|
const word = args.filter(a => !a.startsWith("-")).join(" ").trim();
|
|
160
159
|
if (!word) {
|
|
161
160
|
console.error(USAGE);
|
|
162
161
|
return 2;
|
|
163
162
|
}
|
|
164
|
-
return search(word);
|
|
163
|
+
return search(word, cfg);
|
|
165
164
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { existsSync, rmSync, statSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import type { Config } from "./config.ts";
|
|
4
|
-
import { applyQueueEnv } from "./queue/env.ts";
|
|
5
4
|
import { gitTop, readIndex, writeIndex } from "./queue/lib.ts";
|
|
6
5
|
|
|
7
6
|
// One index (20261024_1400_one_index): fold the old two-level layout into the main index. Every
|
|
@@ -9,7 +8,6 @@ import { gitTop, readIndex, writeIndex } from "./queue/lib.ts";
|
|
|
9
8
|
// and the repo INDEX.md deleted. Idempotent: with plan lines only, nothing changes. A plan still
|
|
10
9
|
// inside a linked worktree is reported, not moved.
|
|
11
10
|
export function queueMigrate(args: string[], cfg: Config): number {
|
|
12
|
-
applyQueueEnv(cfg);
|
|
13
11
|
const index = cfg.paths.queue_index;
|
|
14
12
|
if (!existsSync(index)) {
|
|
15
13
|
console.log(`queue migrate: ${index} does not exist; nothing to migrate`);
|
|
@@ -44,7 +42,7 @@ export function queueMigrate(args: string[], cfg: Config): number {
|
|
|
44
42
|
rmSync(repoIndex);
|
|
45
43
|
}
|
|
46
44
|
const unique = [...new Set(kept)];
|
|
47
|
-
writeIndex(unique, { removed: "migrate" });
|
|
45
|
+
writeIndex(unique, { removed: "migrate" }, index);
|
|
48
46
|
console.log(`queue migrate: ${index} now lists ${unique.length} plan(s); folded ${folded} repo INDEX.md file(s)`);
|
|
49
47
|
for (const p of unique) {
|
|
50
48
|
const g = gitTop(p);
|
package/src/core/queue-trim.ts
CHANGED
|
@@ -5,13 +5,11 @@ import { existsSync } from "node:fs";
|
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { rekeySpawnFile } from "./guards.ts";
|
|
7
7
|
import type { Config } from "./config.ts";
|
|
8
|
-
import { applyQueueEnv } from "./queue/env.ts";
|
|
9
8
|
import * as q from "./queue/lib.ts";
|
|
10
9
|
|
|
11
10
|
const USAGE = "usage: queue-trim <plan file> [--keep N]";
|
|
12
11
|
|
|
13
12
|
export function queueTrim(args: string[], cfg: Config): number {
|
|
14
|
-
applyQueueEnv(cfg);
|
|
15
13
|
if (args[0] === "--help" || args[0] === "-h") {
|
|
16
14
|
console.log(USAGE);
|
|
17
15
|
return 0;
|
|
@@ -30,7 +28,7 @@ export function queueTrim(args: string[], cfg: Config): number {
|
|
|
30
28
|
return 2;
|
|
31
29
|
}
|
|
32
30
|
const file = path.resolve(planArg);
|
|
33
|
-
if (!existsSync(file) || !q.planAt(file, q.activePlans())) {
|
|
31
|
+
if (!existsSync(file) || !q.planAt(file, q.activePlans(cfg.paths))) {
|
|
34
32
|
console.error(`queue-trim: ${file} is not an indexed plan`);
|
|
35
33
|
return 2;
|
|
36
34
|
}
|
|
@@ -39,7 +37,7 @@ export function queueTrim(args: string[], cfg: Config): number {
|
|
|
39
37
|
console.log(`queue-trim: ${file} has no more than ${keep} Progress entries; nothing moved`);
|
|
40
38
|
return 0;
|
|
41
39
|
}
|
|
42
|
-
rekeySpawnFile(file, t.before, t.after);
|
|
40
|
+
rekeySpawnFile(file, t.before, t.after, cfg.paths);
|
|
43
41
|
console.log(`queue-trim: moved ${t.count} older Progress entries of ${file} to ${t.archive}`);
|
|
44
42
|
return 0;
|
|
45
43
|
}
|
package/src/core/results.ts
CHANGED
|
@@ -8,7 +8,6 @@ import path from "node:path";
|
|
|
8
8
|
import type { Run } from "./adapter.ts";
|
|
9
9
|
import type { Config } from "./config.ts";
|
|
10
10
|
import type { Ev } from "./metrics.ts";
|
|
11
|
-
import { applyQueueEnv } from "./queue/env.ts";
|
|
12
11
|
import { gitTop, parsePlan } from "./queue/lib.ts";
|
|
13
12
|
import { repoRoots, walkMd } from "./queue-finished.ts";
|
|
14
13
|
|
|
@@ -65,7 +64,6 @@ function realRepo(p: string): string {
|
|
|
65
64
|
|
|
66
65
|
/** Every dated plan under docs/plans/** of each repo the queue knows (work_roots plus one level of children). A git worktree carries a copy of docs/plans and gitTop maps it to the main checkout, so one node per (canonical repo, stem) survives: an archived or closed copy beats an open one, else the newest mtime wins. */
|
|
67
66
|
export function loadPlans(cfg: Config): PlanNode[] {
|
|
68
|
-
applyQueueEnv(cfg);
|
|
69
67
|
const best = new Map<string, { node: PlanNode; mtime: number }>();
|
|
70
68
|
for (const repo of repoRoots(cfg.paths.work_roots)) {
|
|
71
69
|
const files: string[] = [];
|
package/src/core/rollover.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
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";
|
|
9
8
|
import { strftime } from "./clock.ts";
|
|
10
9
|
import type { OwnerAnswer, OwnerMessage } from "./incidents.ts";
|
|
11
10
|
|
|
@@ -167,11 +166,11 @@ export function noteRequest(path: string, reason = ""): string {
|
|
|
167
166
|
}
|
|
168
167
|
|
|
169
168
|
/** Where Main writes the handoff note for one session. */
|
|
170
|
-
export function notePath(sessionId: string, stateDir
|
|
169
|
+
export function notePath(sessionId: string, stateDir: string): string {
|
|
171
170
|
return join(stateDir, "rollover", `${sessionId}.md`);
|
|
172
171
|
}
|
|
173
172
|
|
|
174
173
|
/** The launcher's relaunch request file: written by the harness just before it exits under `neurastream main`. */
|
|
175
|
-
export function relaunchPath(stateDir
|
|
174
|
+
export function relaunchPath(stateDir: string): string {
|
|
176
175
|
return join(stateDir, "rollover", "relaunch.json");
|
|
177
176
|
}
|
package/src/core/team-client.ts
CHANGED
|
@@ -106,14 +106,15 @@ function markDown(name: string, clock: () => number): void {
|
|
|
106
106
|
downUntil.set(name, clock() + OUTAGE_MEMO_SEC);
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/** One request through the send seam, with the memo: down answers at once; transport failures and 5xx mark the team down. Returns "down" when the server did not answer. */
|
|
109
|
+
/** One request through the send seam, with the memo: down answers at once; transport failures and 5xx mark the team+server down. Returns "down" when the server did not answer. */
|
|
110
110
|
function askRaw(team: TeamEntry, req: WireRequest, opts: RawOpts = {}): WireResponse | "down" {
|
|
111
111
|
const clock = opts.clock ?? nowSec;
|
|
112
112
|
const send = opts.send ?? defaultSend;
|
|
113
|
-
|
|
113
|
+
const memoKey = `${team.name}\0${team.server}`;
|
|
114
|
+
if (memoDown(memoKey, clock)) return "down";
|
|
114
115
|
const res = send(req);
|
|
115
116
|
if (res === null || res.error !== undefined || typeof res.status !== "number" || res.status >= 500) {
|
|
116
|
-
markDown(
|
|
117
|
+
markDown(memoKey, clock);
|
|
117
118
|
return "down";
|
|
118
119
|
}
|
|
119
120
|
return res;
|
|
@@ -528,7 +529,7 @@ export function syncTeam(team: TeamEntry, cfg: Config, run: CommandRunner = defa
|
|
|
528
529
|
if (typeof row?.id === "string" && typeof row.sha === "string" && rec[row.id]?.sha !== row.sha) pullPlan(team, cfg, row.id);
|
|
529
530
|
}
|
|
530
531
|
}
|
|
531
|
-
for (const plan of activePlans(cfg.paths
|
|
532
|
+
for (const plan of activePlans(cfg.paths)) {
|
|
532
533
|
if (planShare(plan, cfg, run) !== team.name) continue;
|
|
533
534
|
const id = pathId(team, cfg, plan.file, run);
|
|
534
535
|
if (id === null) continue;
|
package/src/core/watch.ts
CHANGED
|
@@ -28,6 +28,7 @@ import { addIncident, dismissIncident, openIncidents, readIncidents, type Incide
|
|
|
28
28
|
import { m7, rowsOf, silentFailures, snap } from "./report.ts";
|
|
29
29
|
import { loadKnownSecrets, redactSecrets } from "./secret-redact.ts";
|
|
30
30
|
import { ciScan } from "./ci.ts";
|
|
31
|
+
import type { QueuePaths } from "./queue/lib.ts";
|
|
31
32
|
import type { CommandRunner } from "./mr-sweep.ts";
|
|
32
33
|
import type { ReleaseTag } from "./results.ts";
|
|
33
34
|
import { levelFor, readLevels, writeLevels, type Level, type RuleLevels } from "./rule-levels.ts";
|
|
@@ -618,9 +619,9 @@ function judgeRelease(cfg: Config, tag: string, before: Window, after: Window, d
|
|
|
618
619
|
}
|
|
619
620
|
|
|
620
621
|
/** The plan files a timer run treats as staffed: a plan whose newest spawn (staffing.json) names tasks and is newer than `ciRedHours` before `now`. An older spawn's agent is gone, so its red MR is not held back (I-20261031-265). A timer run has no live job list, so the spawn record is the only signal it has. */
|
|
621
|
-
export function timerStaffedPlans(now: number, ciRedHours: number): string[] {
|
|
622
|
+
export function timerStaffedPlans(now: number, ciRedHours: number, paths: Pick<QueuePaths, "queue_state">): string[] {
|
|
622
623
|
const since = now - ciRedHours * 3600;
|
|
623
|
-
return Object.entries(readStaffingEntries()).filter(([, e]) => e.names.length > 0 && e.at > since).map(([file]) => file);
|
|
624
|
+
return Object.entries(readStaffingEntries(paths)).filter(([, e]) => e.names.length > 0 && e.at > since).map(([file]) => file);
|
|
624
625
|
}
|
|
625
626
|
|
|
626
627
|
/** The watcher's unit files under one home: the systemd user service and timer on Linux, the
|
package/src/core/queue/env.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Config } from "../config.ts";
|
|
2
|
-
import { refreshQueuePaths } from "./lib.ts";
|
|
3
|
-
|
|
4
|
-
/** Map merged config into the env vars the queue library reads (same as live setup). */
|
|
5
|
-
export function applyQueueEnv(cfg: Config, env: NodeJS.ProcessEnv = process.env): void {
|
|
6
|
-
env.QUEUE_AGENT = cfg.paths.agent_dir;
|
|
7
|
-
env.QUEUE_INDEX = cfg.paths.queue_index;
|
|
8
|
-
env.QUEUE_BLOCKERS = cfg.paths.blockers;
|
|
9
|
-
env.QUEUE_STATE = cfg.paths.queue_state;
|
|
10
|
-
env.QUEUE_SUBAGENTS = cfg.paths.subagents;
|
|
11
|
-
env.QUEUE_CANCELLED = cfg.paths.cancelled;
|
|
12
|
-
env.QUEUE_UNLOCK = cfg.paths.unlock;
|
|
13
|
-
refreshQueuePaths();
|
|
14
|
-
}
|