neurastream 0.2.40 → 0.2.41
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 +2 -2
- package/package.json +1 -1
- package/src/adapters/omp/index.ts +1 -1
- package/src/cli/guard.ts +3 -0
- package/src/cli/incident.ts +4 -4
- package/src/core/adapter.ts +2 -0
- package/src/core/config.ts +10 -0
- package/src/core/guards.ts +21 -30
- package/src/core/incidents.ts +44 -3
- package/templates/config.yml +1 -0
package/README.md
CHANGED
|
@@ -348,9 +348,9 @@ Five sources feed it:
|
|
|
348
348
|
- Daily: at the first main-start or Main prompt of a day, M1-M5 for the last 24 hours against the mean of the 7 days before; a metric worse by `incidents.daily_worse_pct` and above its `incidents.daily_floor` floor is an incident.
|
|
349
349
|
- Weekly: when the metrics report is due, the code writes `<paths.notes>/metrics.md` itself and its worst ranked metric becomes an incident.
|
|
350
350
|
- Main itself: `neurastream incident add "<summary>" --kind <k>`.
|
|
351
|
-
- A subagent's
|
|
351
|
+
- A plan's Findings lines, a subagent's or Main's own: every new `## Progress` entry in a plan ends with a `Findings:` line (`Findings: none`, or one item per finding — bug, workaround, improvement, any repo — with `file:line` evidence, items separated by `;`). The plan-guard refuses and restores an entry without the line, and each item of an allowed edit becomes an incident (source `findings`; a subagent's item is kind `agent-finding`, Main's own kind `main-finding`; evidence = plan path + agent); the same text again dedupes into the open incident. The plan the entry is written in does not count as planning its finding — planning is `neurastream incident plan`.
|
|
352
352
|
|
|
353
|
-
While an incident is open (no plan, dismissal or fixed record), every Main prompt carries one `INCIDENT <id> [<source>/<kind>]: <summary>` line per open incident, Main's `task` spawns and bypass launches are refused unless the brief names a plan citing `INCIDENT <id>`, and Main cannot stop with an incident that has neither. The loop closes three ways: `neurastream incident plan <id> <plan.md>` (the plan must exist, be listed in the main index, cite `INCIDENT <id>`, and carry a fail-before phase — its regression test has to fail on the old code), `neurastream incident dismiss <id> --why "<text>"`, and `fixed` — written by the queue itself when it closes a plan that cites the incident. `neurastream metrics report` shows M6: incidents opened / planned / dismissed / fixed and the median hours from open to fixed.
|
|
353
|
+
While an incident is open (no plan, dismissal or fixed record), every Main prompt carries one `INCIDENT <id> [<source>/<kind>]: <summary>` line per open incident, Main's `task` spawns and bypass launches are refused unless the brief names a plan citing `INCIDENT <id>`, and Main cannot stop with an incident that has neither. A stop reply that only offers to plan is refused too: the reply Main stops with is matched against `guards.plan_offer` (case-insensitive; "want me to write a plan?", "should I plan") and a hit answers "don't offer it — write the plan and index it" — the two-idle-stops release does not lift that block. The loop closes three ways: `neurastream incident plan <id> <plan.md>` (the plan must exist, be listed in the main index, cite `INCIDENT <id>`, and carry a fail-before phase — its regression test has to fail on the old code), `neurastream incident dismiss <id> --why "<text>"` (a finding incident — `agent-finding` or `main-finding` — is dismissed only with the owner's own words: `--owner "<quote>"`, a substring of an owner message the inject hook saw in the last 24 h, so the agent that found the bug cannot also wave it away), and `fixed` — written by the queue itself when it closes a plan that cites the incident. `neurastream metrics report` shows M6: incidents opened / planned / dismissed / fixed and the median hours from open to fixed.
|
|
354
354
|
|
|
355
355
|
## Changing a script
|
|
356
356
|
|
package/package.json
CHANGED
|
@@ -1000,7 +1000,7 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
1000
1000
|
return undefined;
|
|
1001
1001
|
}
|
|
1002
1002
|
}
|
|
1003
|
-
const d = checkStop({ agent: "main", callsSinceStop, idleStops, ledgerText: ledgerText(cfg) }, cfg);
|
|
1003
|
+
const d = checkStop({ agent: "main", callsSinceStop, idleStops, ledgerText: ledgerText(cfg), reply: reply?.text ?? undefined }, cfg);
|
|
1004
1004
|
callsSinceStop = d.state?.callsSinceStop ?? 0;
|
|
1005
1005
|
idleStops = d.state?.idleStops ?? idleStops;
|
|
1006
1006
|
if (d.allow) {
|
package/src/cli/guard.ts
CHANGED
|
@@ -78,6 +78,9 @@ function decide(event: string, p: Record<string, unknown>, cfg: Config): Decisio
|
|
|
78
78
|
callsSinceStop: asNumber(p.callsSinceStop),
|
|
79
79
|
idleStops: asNumber(p.idleStops),
|
|
80
80
|
ledgerText: asString(p.ledgerText),
|
|
81
|
+
// P5 (20261028_0900, I-20261028-67): non-omp harnesses reach the plan-offer block
|
|
82
|
+
// through this CLI, so the reply text travels like the omp adapter's does.
|
|
83
|
+
...(p.reply === undefined ? {} : { reply: asString(p.reply) }),
|
|
81
84
|
};
|
|
82
85
|
return checkStop(e, cfg);
|
|
83
86
|
}
|
package/src/cli/incident.ts
CHANGED
|
@@ -17,7 +17,7 @@ export const INCIDENT_USAGE = [
|
|
|
17
17
|
"usage: neurastream incident list [--open] [--json]",
|
|
18
18
|
' neurastream incident add "<summary>" --kind <k> [--evidence <text>]',
|
|
19
19
|
" neurastream incident plan <id> <plan.md>",
|
|
20
|
-
' neurastream incident dismiss <id> --why "<text>"',
|
|
20
|
+
' neurastream incident dismiss <id> --why "<text>" [--owner "<quote>"]',
|
|
21
21
|
].join("\n");
|
|
22
22
|
|
|
23
23
|
function flagValue(args: string[], name: string): string | undefined {
|
|
@@ -77,12 +77,12 @@ export function planIncidentCmd(cfg: Config, id: string, planPath: string): numb
|
|
|
77
77
|
return 0;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
export function dismissIncidentCmd(cfg: Config, id: string, why: string | undefined): number {
|
|
80
|
+
export function dismissIncidentCmd(cfg: Config, id: string, why: string | undefined, owner: string | undefined): number {
|
|
81
81
|
if (!id || why === undefined) {
|
|
82
82
|
console.error(INCIDENT_USAGE);
|
|
83
83
|
return 2;
|
|
84
84
|
}
|
|
85
|
-
const problem = dismissIncident(cfg, id, why);
|
|
85
|
+
const problem = dismissIncident(cfg, id, why, owner);
|
|
86
86
|
if (problem) {
|
|
87
87
|
console.error(problem);
|
|
88
88
|
return 1;
|
|
@@ -103,7 +103,7 @@ export async function runIncident(args: string[]): Promise<number> {
|
|
|
103
103
|
if (sub === "list") return listIncidents(cfg, rest);
|
|
104
104
|
if (sub === "add") return addIncidentCmd(cfg, rest);
|
|
105
105
|
if (sub === "plan") return planIncidentCmd(cfg, rest[0] ?? "", rest[1] ?? "");
|
|
106
|
-
if (sub === "dismiss") return dismissIncidentCmd(cfg, rest[0] ?? "", flagValue(rest, "--why"));
|
|
106
|
+
if (sub === "dismiss") return dismissIncidentCmd(cfg, rest[0] ?? "", flagValue(rest, "--why"), flagValue(rest, "--owner"));
|
|
107
107
|
console.error(INCIDENT_USAGE);
|
|
108
108
|
return 2;
|
|
109
109
|
}
|
package/src/core/adapter.ts
CHANGED
|
@@ -135,6 +135,8 @@ export interface StopEvent {
|
|
|
135
135
|
callsSinceStop: number;
|
|
136
136
|
idleStops: number;
|
|
137
137
|
ledgerText: string;
|
|
138
|
+
/** The reply text Main is stopping with, when the harness has it (20261028_0900 P2: a reply that offers to plan instead of planning refuses the stop). */
|
|
139
|
+
reply?: string;
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
export const GUARD_EVENTS = ["pre-tool", "inject", "spawn", "plan-edit", "stop"] as const;
|
package/src/core/config.ts
CHANGED
|
@@ -119,6 +119,8 @@ export interface Config {
|
|
|
119
119
|
chat_unlock: boolean;
|
|
120
120
|
plan_read_max_hours: number;
|
|
121
121
|
idle_stops: number;
|
|
122
|
+
/** A Main stop reply matching this regex (case-insensitive) offers to plan instead of planning; the stop is refused (20261028_0900 P2). */
|
|
123
|
+
plan_offer: string;
|
|
122
124
|
/** Provider rate limits (src/core/rate-limit.ts): a turn that ends on one waits it out instead of
|
|
123
125
|
* asking again straight into the limit. The words and the waits come from here. */
|
|
124
126
|
rate_limit: {
|
|
@@ -435,6 +437,14 @@ function check(cfg: Config): void {
|
|
|
435
437
|
if (cfg.guards.sub_max_calls_cap < cfg.guards.sub_max_calls) {
|
|
436
438
|
throw new ConfigError("guards.sub_max_calls_cap must be >= guards.sub_max_calls");
|
|
437
439
|
}
|
|
440
|
+
if (typeof cfg.guards.plan_offer !== "string" || cfg.guards.plan_offer === "") {
|
|
441
|
+
throw new ConfigError("guards.plan_offer must be a non-empty regex string");
|
|
442
|
+
}
|
|
443
|
+
try {
|
|
444
|
+
new RegExp(cfg.guards.plan_offer, "i");
|
|
445
|
+
} catch {
|
|
446
|
+
throw new ConfigError(`guards.plan_offer: not a valid regex: ${cfg.guards.plan_offer}`);
|
|
447
|
+
}
|
|
438
448
|
if (!(cfg.rollover.max_session_mb > 0)) throw new ConfigError("rollover.max_session_mb must be > 0");
|
|
439
449
|
if (cfg.autonomy.tier !== "strict" && cfg.autonomy.tier !== "opinionated" && cfg.autonomy.tier !== "full")
|
|
440
450
|
throw new ConfigError('autonomy.tier must be "strict", "opinionated" or "full"');
|
package/src/core/guards.ts
CHANGED
|
@@ -28,7 +28,7 @@ import type { Decision, InjectEvent, PlanEditEvent, SpawnEvent, StopEvent, ToolE
|
|
|
28
28
|
import { currentTier, takeGo, type Tier } from "./autonomy.ts";
|
|
29
29
|
import { approvalProblem } from "./plan-approval.ts";
|
|
30
30
|
import type { Config } from "./config.ts";
|
|
31
|
-
import { addIncident, openIncidents, type IncidentView } from "./incidents.ts";
|
|
31
|
+
import { addIncident, openIncidents, ownerMessagesFile, ownerSaid, readOwnerMessages, type IncidentView, type OwnerMessage } from "./incidents.ts";
|
|
32
32
|
import { notifyProtectedPaths, notifySecretReadHit } from "./notify.ts";
|
|
33
33
|
import * as q from "./queue/lib.ts";
|
|
34
34
|
import type { Plan } from "./queue/lib.ts";
|
|
@@ -103,29 +103,8 @@ function staffingFile(): string {
|
|
|
103
103
|
return path.join(q.STATE_DIR, "staffing.json");
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
text: string;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function ownerMessagesFile(): string {
|
|
112
|
-
return path.join(q.STATE_DIR, "owner-messages.jsonl");
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function readOwnerMessages(): OwnerMessage[] {
|
|
116
|
-
try {
|
|
117
|
-
return readFileSync(ownerMessagesFile(), "utf8").split("\n").filter(Boolean)
|
|
118
|
-
.map(line => JSON.parse(line) as OwnerMessage);
|
|
119
|
-
} catch {
|
|
120
|
-
return [];
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function ownerSaid(words: string, messages: OwnerMessage[], now: number): boolean {
|
|
125
|
-
const quote = words.toLowerCase().replace(/\s+/g, " ").trim();
|
|
126
|
-
if (quote.split(" ").length < 4) return false;
|
|
127
|
-
return messages.some(m => now - m.at >= 0 && now - m.at <= 86400 && m.text.toLowerCase().replace(/\s+/g, " ").includes(quote));
|
|
128
|
-
}
|
|
106
|
+
// The owner-message store (owner-messages.jsonl) and its matcher live in src/core/incidents.ts
|
|
107
|
+
// (20261028_0900 P3): dismissIncident needs them too, and guards already imports incidents.
|
|
129
108
|
|
|
130
109
|
function recordOwnerMessage(text: string, cfg: Config): void {
|
|
131
110
|
if (text.trimStart().startsWith("main-guard:") || text.trimStart().startsWith("<system-notice>") || text.includes("<task-result")) return;
|
|
@@ -1126,18 +1105,20 @@ export function checkPlanEdit(e: PlanEditEvent, cfg: Config): PlanEditDecision {
|
|
|
1126
1105
|
}
|
|
1127
1106
|
|
|
1128
1107
|
/**
|
|
1129
|
-
* Each finding item of an allowed
|
|
1130
|
-
*
|
|
1131
|
-
*
|
|
1108
|
+
* Each finding item of an allowed plan edit becomes an incident (source "findings", evidence =
|
|
1109
|
+
* plan path + agent; the default fingerprint dedupes the same item text). A subagent's items are
|
|
1110
|
+
* kind "agent-finding"; Main's own are kind "main-finding" (20261028_0900 P1: a bug Main writes
|
|
1111
|
+
* down must block the stop like a subagent's). A store failure is logged and swallowed: it must
|
|
1112
|
+
* not break the verified edit.
|
|
1132
1113
|
*/
|
|
1133
|
-
function recordFindings(e: PlanEditEvent, cfg: Config): void {
|
|
1114
|
+
function recordFindings(e: PlanEditEvent, cfg: Config, kind: "agent-finding" | "main-finding" = "agent-finding"): void {
|
|
1134
1115
|
try {
|
|
1135
1116
|
const evidence = `${e.path} (${e.agent})`;
|
|
1136
1117
|
for (const block of newProgressEntries(e.before, e.after)) {
|
|
1137
1118
|
const value = findingsValue(block);
|
|
1138
1119
|
if (!value || /^none\.?$/i.test(value)) continue;
|
|
1139
1120
|
for (const item of value.split(";")) {
|
|
1140
|
-
if (item.trim()) addIncident(cfg, { source: "findings", kind
|
|
1121
|
+
if (item.trim()) addIncident(cfg, { source: "findings", kind, summary: item.trim(), evidence });
|
|
1141
1122
|
}
|
|
1142
1123
|
}
|
|
1143
1124
|
} catch (err) {
|
|
@@ -1181,7 +1162,10 @@ export function findingsValue(block: string): string | null {
|
|
|
1181
1162
|
// Main's plan text outside "## Progress" must rest on files Main read itself (planReadProblems).
|
|
1182
1163
|
// An empty `before` means the plan file did not exist yet; a refusal then deletes it.
|
|
1183
1164
|
function checkMainPlan(e: PlanEditEvent, cfg: Config): PlanEditDecision {
|
|
1184
|
-
if (q.outsideProgress(e.after) === q.outsideProgress(e.before))
|
|
1165
|
+
if (q.outsideProgress(e.after) === q.outsideProgress(e.before)) {
|
|
1166
|
+
recordFindings(e, cfg, "main-finding");
|
|
1167
|
+
return ALLOW;
|
|
1168
|
+
}
|
|
1185
1169
|
// A cited file Main did read lands in the list instead of the refusal (I-20261025-208): fix the
|
|
1186
1170
|
// text first, then judge the fixed text like any other edit.
|
|
1187
1171
|
const fix = autoListReads(e.after, e.path, cfg);
|
|
@@ -1191,6 +1175,7 @@ function checkMainPlan(e: PlanEditEvent, cfg: Config): PlanEditDecision {
|
|
|
1191
1175
|
const known = new Set(e.before ? planReadProblems(e.before, e.path, cfg) : []);
|
|
1192
1176
|
const problems = planReadProblems(fixed, e.path, cfg).filter(p => p === NO_SECTION || !known.has(p));
|
|
1193
1177
|
if (!problems.length) {
|
|
1178
|
+
recordFindings(e, cfg, "main-finding");
|
|
1194
1179
|
if (!fix) return ALLOW;
|
|
1195
1180
|
const list = fix.paths.join(", ");
|
|
1196
1181
|
log(cfg.paths.plan_guard_log, `AUTO-LIST ${e.path}: ${list}`);
|
|
@@ -1373,6 +1358,12 @@ export function liveSubagents(ledgerOut: string): string[] {
|
|
|
1373
1358
|
export function checkStop(e: StopEvent, cfg: Config): Decision {
|
|
1374
1359
|
if (e.agent !== "main") return ALLOW;
|
|
1375
1360
|
const state = { callsSinceStop: e.callsSinceStop, idleStops: e.idleStops };
|
|
1361
|
+
// 20261028_0900 P2: a reply that offers to plan instead of planning is refused for the offer
|
|
1362
|
+
// itself; the two-empty-stops valves below never release this block.
|
|
1363
|
+
if (e.reply && new RegExp(cfg.guards.plan_offer, "i").test(e.reply)) {
|
|
1364
|
+
log(cfg.paths.guard_log, "BLOCK stop: reply offers to plan instead of planning it");
|
|
1365
|
+
return { allow: false, reason: "main-guard: don't offer it — write the plan and index it", state };
|
|
1366
|
+
}
|
|
1376
1367
|
let open: string[];
|
|
1377
1368
|
try {
|
|
1378
1369
|
open = openQueue();
|
package/src/core/incidents.ts
CHANGED
|
@@ -195,14 +195,55 @@ export function planIncident(cfg: Config, id: string, planPath: string): string
|
|
|
195
195
|
return null;
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
// The owner's own words, as the inject hook saw them (<queue_state>/owner-messages.jsonl, last
|
|
199
|
+
// 50 messages). Guards match quotes against them (priority skip, autonomy go); incidents dismiss
|
|
200
|
+
// a finding only with them (20261028_0900 P3).
|
|
201
|
+
|
|
202
|
+
/** The kinds plan-guard's recordFindings writes; only the owner's own words dismiss them. */
|
|
203
|
+
const FINDING_KINDS: Record<string, true> = { "agent-finding": true, "main-finding": true };
|
|
204
|
+
|
|
205
|
+
export interface OwnerMessage {
|
|
206
|
+
at: number;
|
|
207
|
+
text: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function ownerMessagesFile(): string {
|
|
211
|
+
return join(q.STATE_DIR, "owner-messages.jsonl");
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function readOwnerMessages(): OwnerMessage[] {
|
|
215
|
+
try {
|
|
216
|
+
return readFileSync(ownerMessagesFile(), "utf8").split("\n").filter(Boolean)
|
|
217
|
+
.map(line => JSON.parse(line) as OwnerMessage);
|
|
218
|
+
} catch {
|
|
219
|
+
return [];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function ownerSaid(words: string, messages: OwnerMessage[], now: number): boolean {
|
|
224
|
+
const quote = words.toLowerCase().replace(/\s+/g, " ").trim();
|
|
225
|
+
if (quote.split(" ").length < 4) return false;
|
|
226
|
+
return messages.some(m => now - m.at >= 0 && now - m.at <= 86400 && m.text.toLowerCase().replace(/\s+/g, " ").includes(quote));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Records why an incident is not a bug (or not worth fixing); an empty why is refused. A finding
|
|
230
|
+
* incident (kind "agent-finding"/"main-finding") is dismissed only with `owner` — a quote
|
|
231
|
+
* `ownerSaid` matches against the owner's own messages of the last 24 h (20261028_0900 P3: the
|
|
232
|
+
* agent that found the bug cannot also wave it away). */
|
|
233
|
+
export function dismissIncident(cfg: Config, id: string, why: string, owner?: string): string | null {
|
|
200
234
|
const file = incidentsFile(cfg);
|
|
201
235
|
const store = readStore(file);
|
|
202
|
-
|
|
236
|
+
const rec = store.incidents.find(i => i.id === id);
|
|
237
|
+
if (!rec) return `unknown incident ${id}`;
|
|
203
238
|
const res = store.resolutions.filter(r => r.id === id).at(-1);
|
|
204
239
|
if (res) return `incident ${id} already has a ${res.type} record`;
|
|
205
240
|
if (!why.trim()) return "refused: an empty --why would hide the incident without a recorded reason";
|
|
241
|
+
if (FINDING_KINDS[rec.kind]) {
|
|
242
|
+
if (owner === undefined)
|
|
243
|
+
return `refused: a ${rec.kind} is dismissed only with the owner's words: --owner "<quote>" (part of an owner message of the last 24 h)`;
|
|
244
|
+
if (!ownerSaid(owner, readOwnerMessages(), nowSec()))
|
|
245
|
+
return "refused: the --owner quote is not part of an owner message of the last 24 h";
|
|
246
|
+
}
|
|
206
247
|
mkdirSync(dirname(file), { recursive: true });
|
|
207
248
|
appendFileSync(file, `${JSON.stringify({ type: "dismiss", id, why })}\n`);
|
|
208
249
|
return null;
|
package/templates/config.yml
CHANGED
|
@@ -122,6 +122,7 @@ guards:
|
|
|
122
122
|
chat_unlock: false # the owner's whole chat message "unlock"/"unlock N"/"lock" moves the guard unlock file
|
|
123
123
|
plan_read_max_hours: 24
|
|
124
124
|
idle_stops: 3
|
|
125
|
+
plan_offer: 'want me to (write|make) a plan|should i plan|shall i plan|if you want, i(''ll)? plan|plan it or' # a Main stop reply matching this (case-insensitive) is refused: don't offer it — write the plan and index it
|
|
125
126
|
rate_limit:
|
|
126
127
|
patterns: ["429", "rate_limit", "rate limit", "overloaded", "529"] # error-text substrings (case-insensitive) that mark a provider rate limit
|
|
127
128
|
default_wait_s: 300 # wait when the error text names no retry-after
|