neurastream 0.3.17 → 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 +192 -195
- 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
package/src/cli/incident.ts
CHANGED
|
@@ -108,10 +108,10 @@ export function proposeIncidentCmd(cfg: Config, id: string, why: string | undefi
|
|
|
108
108
|
return 0;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
export async function runIncident(args: string[]): Promise<number> {
|
|
111
|
+
export async function runIncident(args: string[], injected?: Config): Promise<number> {
|
|
112
112
|
let cfg: Config;
|
|
113
113
|
try {
|
|
114
|
-
cfg = loadConfig();
|
|
114
|
+
cfg = injected ?? loadConfig();
|
|
115
115
|
} catch (err) {
|
|
116
116
|
console.error(err instanceof ConfigError ? err.message : String(err));
|
|
117
117
|
return 1;
|
package/src/cli/metrics.ts
CHANGED
|
@@ -51,7 +51,7 @@ export function recordCi(cfg: Config, repoDir: string, mr: string, now: number,
|
|
|
51
51
|
console.log(`ci: ${mr} needed ${r.tries} pipeline(s)`);
|
|
52
52
|
for (const s of r.skipped) console.error(s);
|
|
53
53
|
// A new CI record can change what a hold check sees, so every hold is re-checked now, not on its TTL.
|
|
54
|
-
const plans = activePlans(cfg.paths
|
|
54
|
+
const plans = activePlans(cfg.paths);
|
|
55
55
|
for (const line of staleHoldLines(recheckHolds(cfg, plans, run, now, true), plans)) console.log(line);
|
|
56
56
|
return 0;
|
|
57
57
|
}
|
package/src/cli/recall.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { ConfigError, loadConfig, type Config } from "../core/config.ts";
|
|
|
7
7
|
import { helpDoc, printText } from "../core/help.ts";
|
|
8
8
|
import { backfillOwnerLog, type LogEntry, searchEntries, showEntries } from "../core/owner-log.ts";
|
|
9
9
|
import { rangeEntries, runTopics, searchTopics, type Segment, type TopicsRun } from "../core/owner-topics.ts";
|
|
10
|
-
import { applyQueueEnv } from "../core/queue/env.ts";
|
|
11
10
|
|
|
12
11
|
const USAGE = "usage: neurastream recall <words>... [--since 7d|12h|YYYY-MM-DD] [--limit N] [--json]\n neurastream recall --show <id> [--json]";
|
|
13
12
|
const BACKFILL_USAGE = "usage: neurastream recall backfill [--since 7d|12h|YYYY-MM-DD]";
|
|
@@ -132,8 +131,6 @@ export function recallCli(args: string[], cfg: Config): number | Promise<number>
|
|
|
132
131
|
printText(helpDoc("recall"));
|
|
133
132
|
return 0;
|
|
134
133
|
}
|
|
135
|
-
// The log paths follow the queue state directory, so the config's queue env is applied first.
|
|
136
|
-
applyQueueEnv(cfg);
|
|
137
134
|
if (args[0] === "backfill") return backfillCli(args.slice(1), cfg);
|
|
138
135
|
if (args[0] === "topics") return topicsCli(args.slice(1), cfg);
|
|
139
136
|
const parsed = parseArgs(args);
|
|
@@ -143,7 +140,7 @@ export function recallCli(args: string[], cfg: Config): number | Promise<number>
|
|
|
143
140
|
}
|
|
144
141
|
if (parsed.show !== undefined) {
|
|
145
142
|
const parts = parsed.show.split("..");
|
|
146
|
-
const pair = parts.length === 2 ? rangeEntries(parts[0]!, parts[1]
|
|
143
|
+
const pair = parts.length === 2 ? rangeEntries(parts[0]!, parts[1]!, cfg.paths) : showEntries(parsed.show, cfg.paths);
|
|
147
144
|
if (pair === undefined || pair.length === 0) {
|
|
148
145
|
console.error(`no entry with id ${parsed.show}`);
|
|
149
146
|
return 2;
|
|
@@ -157,11 +154,11 @@ export function recallCli(args: string[], cfg: Config): number | Promise<number>
|
|
|
157
154
|
console.error(USAGE);
|
|
158
155
|
return 2;
|
|
159
156
|
}
|
|
160
|
-
const topics = searchTopics(parsed.words)
|
|
157
|
+
const topics = searchTopics(parsed.words, cfg.paths)
|
|
161
158
|
.filter((s) => parsed.sinceSec === undefined || s.at >= parsed.sinceSec)
|
|
162
159
|
.slice(0, parsed.limit);
|
|
163
160
|
const left = parsed.limit - topics.length;
|
|
164
|
-
const hits = left > 0 ? searchEntries({ words: parsed.words, sinceSec: parsed.sinceSec, limit: left }) : [];
|
|
161
|
+
const hits = left > 0 ? searchEntries({ words: parsed.words, sinceSec: parsed.sinceSec, limit: left }, cfg.paths) : [];
|
|
165
162
|
if (topics.length === 0 && hits.length === 0) {
|
|
166
163
|
console.log("no match");
|
|
167
164
|
return 1;
|
package/src/cli/results-build.ts
CHANGED
|
@@ -7,13 +7,11 @@ import { getAdapter } from "../adapters/index.ts";
|
|
|
7
7
|
import { nowSec } from "../core/clock.ts";
|
|
8
8
|
import { loadConfig } from "../core/config.ts";
|
|
9
9
|
import { computeResults, resultsCachePath } from "../core/owner-ui.ts";
|
|
10
|
-
import { applyQueueEnv } from "../core/queue/env.ts";
|
|
11
10
|
|
|
12
11
|
const cfg = loadConfig();
|
|
13
|
-
applyQueueEnv(cfg);
|
|
14
12
|
const at = nowSec();
|
|
15
13
|
const data = computeResults(cfg, getAdapter(cfg).runSource(cfg), at);
|
|
16
|
-
const path = resultsCachePath();
|
|
14
|
+
const path = resultsCachePath(cfg.paths);
|
|
17
15
|
// Write then rename: the page never reads a half-written file.
|
|
18
16
|
writeFileSync(`${path}.tmp`, JSON.stringify({ at, data }));
|
|
19
17
|
renameSync(`${path}.tmp`, path);
|
package/src/cli/workspace.ts
CHANGED
|
@@ -15,7 +15,6 @@ import { getAdapter } from "../adapters/index.ts";
|
|
|
15
15
|
import { ConfigError, loadConfig, type Config } from "../core/config.ts";
|
|
16
16
|
import { beat, errorLine } from "../core/heartbeat.ts";
|
|
17
17
|
import { startOwnerUi, type OwnerUiOptions, type OwnerUiServer } from "../core/owner-ui.ts";
|
|
18
|
-
import { applyQueueEnv } from "../core/queue/env.ts";
|
|
19
18
|
import { realTailscale, type Tailscale, untilIp4Changes } from "../core/tailscale.ts";
|
|
20
19
|
import { TEAM_NAME_HINT, TEAM_NAME_RE } from "../core/team-labels.ts";
|
|
21
20
|
import { addTeamMember, listTeamMembers, removeTeamMember, startTeamServer, type TeamServer, type TeamServerConfig, type TeamServerOptions } from "../core/team-server.ts";
|
|
@@ -110,7 +109,6 @@ export async function runWorkspace(args: string[] = [], deps: WorkspaceDeps = {}
|
|
|
110
109
|
return 1;
|
|
111
110
|
}
|
|
112
111
|
}
|
|
113
|
-
applyQueueEnv(cfg);
|
|
114
112
|
if (!cfg.workspace.enabled) {
|
|
115
113
|
console.error("neurastream workspace: workspace.enabled is false — set it in the config first");
|
|
116
114
|
return 1;
|
|
@@ -171,7 +169,6 @@ async function serveTeam(name: string, deps: WorkspaceDeps): Promise<number> {
|
|
|
171
169
|
console.error(state);
|
|
172
170
|
return 1;
|
|
173
171
|
}
|
|
174
|
-
applyQueueEnv(state.cfg);
|
|
175
172
|
const tailscale = deps.tailscale ?? realTailscale;
|
|
176
173
|
let server: TeamServer;
|
|
177
174
|
try {
|
package/src/core/autonomy.ts
CHANGED
|
@@ -9,23 +9,23 @@ import { appendFileSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSyn
|
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { configFile, loadConfig, type Config } from "./config.ts";
|
|
11
11
|
import { checkEdited, setConfigKeys, yamlValue } from "./config-edit.ts";
|
|
12
|
-
import {
|
|
12
|
+
import type { QueuePaths } from "./queue/lib.ts";
|
|
13
13
|
|
|
14
14
|
export type Tier = "strict" | "opinionated" | "full";
|
|
15
15
|
const TIERS: readonly Tier[] = ["strict", "opinionated", "full"];
|
|
16
16
|
|
|
17
|
-
export function tierFile(): string {
|
|
18
|
-
return path.join(
|
|
17
|
+
export function tierFile(paths: Pick<QueuePaths, "queue_state">): string {
|
|
18
|
+
return path.join(paths.queue_state, "autonomy-tier");
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export function goFile(): string {
|
|
22
|
-
return path.join(
|
|
21
|
+
export function goFile(paths: Pick<QueuePaths, "queue_state">): string {
|
|
22
|
+
return path.join(paths.queue_state, "autonomy-go");
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** The tier the guards follow: `<state dir>/autonomy-tier` when it names one of the three (one word), else the config value. */
|
|
26
26
|
export function currentTier(cfg: Config): Tier {
|
|
27
27
|
try {
|
|
28
|
-
const word = readFileSync(tierFile(), "utf8").trim().toLowerCase();
|
|
28
|
+
const word = readFileSync(tierFile(cfg.paths), "utf8").trim().toLowerCase();
|
|
29
29
|
if ((TIERS as readonly string[]).includes(word)) return word as Tier;
|
|
30
30
|
} catch {}
|
|
31
31
|
return cfg.autonomy.tier;
|
|
@@ -52,8 +52,8 @@ export function chatTier(text: string, cfg: Config, source: string, word: "chat"
|
|
|
52
52
|
const m = TIER_CMD.exec(text.trim());
|
|
53
53
|
if (!m) return { applied: false };
|
|
54
54
|
const tier = (m[1] ?? "").toLowerCase() as Tier;
|
|
55
|
-
mkdirSync(
|
|
56
|
-
writeFileSync(tierFile(), `${tier}\n`);
|
|
55
|
+
mkdirSync(cfg.paths.queue_state, { recursive: true });
|
|
56
|
+
writeFileSync(tierFile(cfg.paths), `${tier}\n`);
|
|
57
57
|
try {
|
|
58
58
|
appendFileSync(cfg.paths.plan_guard_log, `${new Date().toISOString()} TIER ${tier} ${word} source=${source}\n`);
|
|
59
59
|
} catch {}
|
|
@@ -80,8 +80,8 @@ const goWords = (s: string): string => s.trim().toLowerCase().replace(/\s+/g, "
|
|
|
80
80
|
export function chatGo(text: string, cfg: Config, source: string, word: "chat" | "ui" = "chat"): ChatGoResult {
|
|
81
81
|
if (!cfg.guards.chat_unlock) return { applied: false };
|
|
82
82
|
if (goWords(text) !== goWords(cfg.autonomy.go_phrase)) return { applied: false };
|
|
83
|
-
mkdirSync(
|
|
84
|
-
writeFileSync(goFile(), "");
|
|
83
|
+
mkdirSync(cfg.paths.queue_state, { recursive: true });
|
|
84
|
+
writeFileSync(goFile(cfg.paths), "");
|
|
85
85
|
try {
|
|
86
86
|
appendFileSync(cfg.paths.plan_guard_log, `${new Date().toISOString()} GO ${word} source=${source} minutes=${cfg.autonomy.go_minutes}\n`);
|
|
87
87
|
} catch {}
|
|
@@ -93,13 +93,14 @@ export function chatGo(text: string, cfg: Config, source: string, word: "chat" |
|
|
|
93
93
|
* autonomy.go_minutes; a stale or missing file is false (a stale one is removed).
|
|
94
94
|
*/
|
|
95
95
|
export function takeGo(cfg: Config, now = Date.now()): boolean {
|
|
96
|
+
const file = goFile(cfg.paths);
|
|
96
97
|
let mtimeMs: number;
|
|
97
98
|
try {
|
|
98
|
-
mtimeMs = statSync(
|
|
99
|
+
mtimeMs = statSync(file).mtimeMs;
|
|
99
100
|
} catch {
|
|
100
101
|
return false;
|
|
101
102
|
}
|
|
102
|
-
rmSync(
|
|
103
|
+
rmSync(file, { force: true });
|
|
103
104
|
return now - mtimeMs < cfg.autonomy.go_minutes * 60_000;
|
|
104
105
|
}
|
|
105
106
|
|
|
@@ -111,8 +112,8 @@ export function takeGo(cfg: Config, now = Date.now()): boolean {
|
|
|
111
112
|
export type PlannerMode = "main" | "delegated";
|
|
112
113
|
const PLANNER_MODES: readonly PlannerMode[] = ["main", "delegated"];
|
|
113
114
|
|
|
114
|
-
export function plannerFile(): string {
|
|
115
|
-
return path.join(
|
|
115
|
+
export function plannerFile(paths: Pick<QueuePaths, "queue_state">): string {
|
|
116
|
+
return path.join(paths.queue_state, "planner-mode");
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
// The effective mode facts are owner-only (P2 d). A guard baseline beside the config file records
|
|
@@ -130,10 +131,11 @@ export function plannerFile(): string {
|
|
|
130
131
|
export interface PlannerPin {
|
|
131
132
|
file: string;
|
|
132
133
|
home: string;
|
|
134
|
+
stateDir?: string;
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
export function plannerPin(cfg: Config): PlannerPin {
|
|
136
|
-
return { file: cfg.file ?? configFile(cfg.paths.home), home: cfg.paths.home };
|
|
138
|
+
return { file: cfg.file ?? configFile(cfg.paths.home), home: cfg.paths.home, stateDir: cfg.paths.queue_state };
|
|
137
139
|
}
|
|
138
140
|
|
|
139
141
|
/** The baseline file: beside the config file it describes. */
|
|
@@ -253,7 +255,8 @@ export function verifyPlannerMode(pin: PlannerPin): PlannerVerifyResult {
|
|
|
253
255
|
else if (base !== null) reverted = writeConfig(pin, base.config.bytes) || reverted;
|
|
254
256
|
}
|
|
255
257
|
// The state file: pinned by the baseline; with no baseline it may not exist at all.
|
|
256
|
-
const
|
|
258
|
+
const liveStateDir = pin.stateDir ?? facts?.queue_state ?? base?.state_dir ?? path.join(pin.home, ".local/state/queue");
|
|
259
|
+
const pinnedDir = base?.state_dir ?? liveStateDir;
|
|
257
260
|
const pinnedFile = path.join(pinnedDir, "planner-mode");
|
|
258
261
|
const want = base?.planner ?? { exists: false, bytes: null };
|
|
259
262
|
const cur = readPlannerState(pinnedFile);
|
|
@@ -268,7 +271,7 @@ export function verifyPlannerMode(pin: PlannerPin): PlannerVerifyResult {
|
|
|
268
271
|
reverted = true;
|
|
269
272
|
}
|
|
270
273
|
// A mode file beside the freshly configured state dir is foreign: the baseline pins the dir.
|
|
271
|
-
const live = plannerFile();
|
|
274
|
+
const live = plannerFile({ queue_state: liveStateDir });
|
|
272
275
|
if (live !== pinnedFile && readPlannerState(live).exists) {
|
|
273
276
|
rmSync(live, { force: true });
|
|
274
277
|
reverted = true;
|
|
@@ -285,7 +288,7 @@ export function stampPlannerMode(pin: PlannerPin): void {
|
|
|
285
288
|
try {
|
|
286
289
|
const text = readFileSync(pin.file, "utf8");
|
|
287
290
|
const facts = fileFacts(pin);
|
|
288
|
-
const dir =
|
|
291
|
+
const dir = pin.stateDir ?? facts.queue_state;
|
|
289
292
|
const base: PlannerBaseline = {
|
|
290
293
|
version: 1,
|
|
291
294
|
state_dir: dir,
|
|
@@ -300,7 +303,7 @@ export function stampPlannerMode(pin: PlannerPin): void {
|
|
|
300
303
|
/** The planner mode in force: the file twin of tierFile() when it names one of the two (one word), else the config value. */
|
|
301
304
|
export function currentPlanner(cfg: Config): PlannerMode {
|
|
302
305
|
try {
|
|
303
|
-
const word = readFileSync(plannerFile(), "utf8").trim().toLowerCase();
|
|
306
|
+
const word = readFileSync(plannerFile(cfg.paths), "utf8").trim().toLowerCase();
|
|
304
307
|
if ((PLANNER_MODES as readonly string[]).includes(word)) return word as PlannerMode;
|
|
305
308
|
} catch {}
|
|
306
309
|
return cfg.autonomy.planner;
|
|
@@ -331,8 +334,8 @@ export function chatPlanner(text: string, cfg: Config, source: string, word: "ch
|
|
|
331
334
|
// The owner's own switch: revert any dirt first, write, then record the new state. The mode
|
|
332
335
|
// file is written in-process, so no tool call sees it.
|
|
333
336
|
verifyPlannerMode(pin);
|
|
334
|
-
mkdirSync(
|
|
335
|
-
writeFileSync(plannerFile(), `${planner}\n`);
|
|
337
|
+
mkdirSync(cfg.paths.queue_state, { recursive: true });
|
|
338
|
+
writeFileSync(plannerFile(cfg.paths), `${planner}\n`);
|
|
336
339
|
stampPlannerMode(pin);
|
|
337
340
|
try {
|
|
338
341
|
appendFileSync(cfg.paths.plan_guard_log, `${new Date().toISOString()} PLANNER ${planner} ${word} source=${source}\n`);
|