neurastream 0.2.42 → 0.2.44
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 +5 -1
- package/package.json +1 -1
- package/src/cli/incident.ts +19 -1
- package/src/core/agents-md.ts +10 -2
- package/src/core/incidents.ts +55 -11
- package/src/core/owner-ui.ts +75 -20
package/README.md
CHANGED
|
@@ -32,12 +32,14 @@ flowchart LR
|
|
|
32
32
|
| Machine health (`machine-guard`, `main-start`, `heavy-run`) | Load, free memory, disk and `/tmp` limits; one heavy test run at a time. |
|
|
33
33
|
| Unlanded work (`wip-check`, `wip-snapshot`, `wip-backup`) | Lists branches on no remote and dirty worktrees; snapshots them as hidden commits; can push them to a backup repo. |
|
|
34
34
|
| Session rollover | When the main session file passes 5 MB, or the installed neurastream version differs from the running plugin, Main writes a handoff note; a fresh session then starts on its own under `neurastream main`. |
|
|
35
|
-
| Owner page (`neurastream ui`) | One phone-sized page over Tailscale (`ui.*` config): the plans waiting on the owner with answer buttons, the guard unlock, running agents, the queue, recent merges/CI, open incidents, agent scores, machine health. Serves only a tailnet peer whose `tailscale whois` login equals `ui.owner_login`, only with a Host header naming the tailnet address or the MagicDNS name — DNS rebinding and every other visitor get a 403. Answers land in the owner inbox and reach Main once each; agents cannot start the page or write the inbox. |
|
|
35
|
+
| Owner page (`neurastream ui`) | One phone-sized page over Tailscale (`ui.*` config): the plans waiting on the owner with answer buttons, the guard unlock, running agents, the queue, recent merges/CI, open incidents (a finding carries Main's reason and False alarm / It's a bug buttons), agent scores, machine health. Serves only a tailnet peer whose `tailscale whois` login equals `ui.owner_login`, only with a Host header naming the tailnet address or the MagicDNS name — DNS rebinding and every other visitor get a 403. Answers land in the owner inbox and reach Main once each; agents cannot start the page or write the inbox. |
|
|
36
36
|
|
|
37
37
|
## Main vs plain omp
|
|
38
38
|
|
|
39
39
|
neurastream runs only under `neurastream main`. That launcher sets `NEURASTREAM_MAIN_LAUNCHER=1` for the omp it starts, and only then does the adapter register its hooks and commands. Plain `omp` runs with no guard, queue summary, rules or rollover, as if neurastream were not installed.
|
|
40
40
|
|
|
41
|
+
Your own Main-only lines go in `MAIN.md` in `paths.agent_dir` (for example `~/.omp/agent/MAIN.md`); Main gets them after its managed rules.
|
|
42
|
+
|
|
41
43
|
```sh
|
|
42
44
|
neurastream main # Main: guards, queue, rules, rollover
|
|
43
45
|
omp -p "say hi" # plain omp: no neurastream hook, no guard-log line
|
|
@@ -360,6 +362,8 @@ Five sources feed it:
|
|
|
360
362
|
|
|
361
363
|
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.
|
|
362
364
|
|
|
365
|
+
A finding incident (`agent-finding`, `main-finding`) shows on the Agents tab with Main's latest reason and two buttons. Main writes the reason with `neurastream incident propose <id> --why "<file:line and reason>"`; the why must cite the proof as `file:line`, and the incident stays open. The owner taps **False alarm** (the incident closes; the reason is recorded as the dismissal with the owner's login) or **It's a bug — plan it** (the incident stays open and one message goes to Main's inbox). A finding with no reason yet says "Main has not said why yet".
|
|
366
|
+
|
|
363
367
|
## Changing a script
|
|
364
368
|
|
|
365
369
|
Edit the script in this repo. Green is `bun run typecheck` and `bun test`, both exit 0. Main tags the release. The publish workflow puts that tag on npm. Then:
|
package/package.json
CHANGED
package/src/cli/incident.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// `neurastream incident …`: the incident list Main must act on (store: src/core/incidents.ts).
|
|
2
2
|
// `list` prints incidents (--open: only the ones with no plan/dismiss/fixed yet; --json: the full
|
|
3
3
|
// records); `add` records Main's own finding (source "main"); `plan` records the plan that fixes
|
|
4
|
-
// an incident; `dismiss` records why an incident is not a bug
|
|
4
|
+
// an incident; `dismiss` records why an incident is not a bug; `propose` records Main's written reason
|
|
5
|
+
// (file:line proof) for a finding, which leaves the incident open.
|
|
5
6
|
|
|
6
7
|
import { ConfigError, loadConfig, type Config } from "../core/config.ts";
|
|
7
8
|
import {
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
dismissIncident,
|
|
10
11
|
openIncidents,
|
|
11
12
|
planIncident,
|
|
13
|
+
proposeIncident,
|
|
12
14
|
readIncidents,
|
|
13
15
|
type IncidentView,
|
|
14
16
|
} from "../core/incidents.ts";
|
|
@@ -16,6 +18,7 @@ import {
|
|
|
16
18
|
export const INCIDENT_USAGE = [
|
|
17
19
|
"usage: neurastream incident list [--open] [--json]",
|
|
18
20
|
' neurastream incident add "<summary>" --kind <k> [--evidence <text>]',
|
|
21
|
+
' neurastream incident propose <id> --why "<file:line and reason>"',
|
|
19
22
|
" neurastream incident plan <id> <plan.md>",
|
|
20
23
|
' neurastream incident dismiss <id> --why "<text>" [--owner "<quote>"]',
|
|
21
24
|
].join("\n");
|
|
@@ -91,6 +94,20 @@ export function dismissIncidentCmd(cfg: Config, id: string, why: string | undefi
|
|
|
91
94
|
return 0;
|
|
92
95
|
}
|
|
93
96
|
|
|
97
|
+
export function proposeIncidentCmd(cfg: Config, id: string, why: string | undefined): number {
|
|
98
|
+
if (!id || why === undefined) {
|
|
99
|
+
console.error(INCIDENT_USAGE);
|
|
100
|
+
return 2;
|
|
101
|
+
}
|
|
102
|
+
const problem = proposeIncident(cfg, id, why);
|
|
103
|
+
if (problem) {
|
|
104
|
+
console.error(problem);
|
|
105
|
+
return 1;
|
|
106
|
+
}
|
|
107
|
+
console.log(`incident ${id}: proposal recorded (still open)`);
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
94
111
|
export async function runIncident(args: string[]): Promise<number> {
|
|
95
112
|
let cfg: Config;
|
|
96
113
|
try {
|
|
@@ -104,6 +121,7 @@ export async function runIncident(args: string[]): Promise<number> {
|
|
|
104
121
|
if (sub === "add") return addIncidentCmd(cfg, rest);
|
|
105
122
|
if (sub === "plan") return planIncidentCmd(cfg, rest[0] ?? "", rest[1] ?? "");
|
|
106
123
|
if (sub === "dismiss") return dismissIncidentCmd(cfg, rest[0] ?? "", flagValue(rest, "--why"), flagValue(rest, "--owner"));
|
|
124
|
+
if (sub === "propose") return proposeIncidentCmd(cfg, rest[0] ?? "", flagValue(rest, "--why"));
|
|
107
125
|
console.error(INCIDENT_USAGE);
|
|
108
126
|
return 2;
|
|
109
127
|
}
|
package/src/core/agents-md.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// between two markers. Main puts them in its system prompt; install only strips an old copy from
|
|
3
3
|
// the owner's AGENTS.md, and everything outside the markers stays the owner's.
|
|
4
4
|
|
|
5
|
-
import { readFileSync } from "node:fs";
|
|
5
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6
6
|
import { dirname, join } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import type { Config } from "./config.ts";
|
|
@@ -14,7 +14,15 @@ export const END_MARK = "<!-- neurastream:end -->";
|
|
|
14
14
|
|
|
15
15
|
export function renderBlock(cfg: Config, template: string = readFileSync(AGENTS_TEMPLATE, "utf8")): string {
|
|
16
16
|
const body = template.trimEnd().split("{{AGENT_DIR}}").join(cfg.paths.agent_dir);
|
|
17
|
-
|
|
17
|
+
const own = ownMainRules(cfg.paths.agent_dir);
|
|
18
|
+
const tail = own === "" ? "" : `\n\n${own}`;
|
|
19
|
+
return `${BEGIN_MARK}\n${body}${tail}\n${END_MARK}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// The owner's own Main-only lines: MAIN.md in the agent dir, trimmed. "" when the file is missing or blank.
|
|
23
|
+
function ownMainRules(agentDir: string): string {
|
|
24
|
+
const file = join(agentDir, "MAIN.md");
|
|
25
|
+
return existsSync(file) ? readFileSync(file, "utf8").trim() : "";
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
function occurrences(text: string, mark: string): number[] {
|
package/src/core/incidents.ts
CHANGED
|
@@ -34,9 +34,19 @@ export type ResolutionRec =
|
|
|
34
34
|
/** `ts` is the close time; older records (written before plan P5) may lack it. */
|
|
35
35
|
| { type: "fixed"; id: string; plan: string; ts?: number };
|
|
36
36
|
|
|
37
|
+
/** Main's written reason that a finding is or is not a bug (`incident propose`). Not a resolution: the incident stays open. */
|
|
38
|
+
export interface ProposalRec {
|
|
39
|
+
type: "propose";
|
|
40
|
+
id: string;
|
|
41
|
+
why: string;
|
|
42
|
+
ts: number;
|
|
43
|
+
}
|
|
44
|
+
|
|
37
45
|
export interface IncidentView extends IncidentRec {
|
|
38
46
|
/** Last resolution record for the id; null while the incident is open. */
|
|
39
47
|
resolution: ResolutionRec | null;
|
|
48
|
+
/** Main's latest proposal for the id (`incident propose`); null when none. */
|
|
49
|
+
proposal: ProposalRec | null;
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
export interface IncidentInput {
|
|
@@ -57,7 +67,7 @@ export function defaultFingerprint(input: Pick<IncidentInput, "source" | "kind"
|
|
|
57
67
|
return q.sha(`${input.source}|${input.kind}|${input.summary.replace(/\s+/g, " ").trim().toLowerCase()}`);
|
|
58
68
|
}
|
|
59
69
|
|
|
60
|
-
function parseLine(line: string): IncidentRec | ResolutionRec | null {
|
|
70
|
+
function parseLine(line: string): IncidentRec | ResolutionRec | ProposalRec | null {
|
|
61
71
|
let rec: Record<string, unknown>;
|
|
62
72
|
try {
|
|
63
73
|
const parsed: unknown = JSON.parse(line);
|
|
@@ -77,6 +87,10 @@ function parseLine(line: string): IncidentRec | ResolutionRec | null {
|
|
|
77
87
|
if (typeof rec.why !== "string") return null;
|
|
78
88
|
return { type: "dismiss", id: rec.id, why: rec.why };
|
|
79
89
|
}
|
|
90
|
+
if (rec.type === "propose") {
|
|
91
|
+
if (typeof rec.why !== "string" || typeof rec.ts !== "number") return null;
|
|
92
|
+
return { type: "propose", id: rec.id, why: rec.why, ts: rec.ts };
|
|
93
|
+
}
|
|
80
94
|
if (rec.type !== undefined) return null;
|
|
81
95
|
if (typeof rec.fingerprint !== "string" || typeof rec.kind !== "string" || typeof rec.summary !== "string" || typeof rec.ts !== "number")
|
|
82
96
|
return null;
|
|
@@ -94,20 +108,22 @@ function parseLine(line: string): IncidentRec | ResolutionRec | null {
|
|
|
94
108
|
};
|
|
95
109
|
}
|
|
96
110
|
|
|
97
|
-
function readStore(file: string): { incidents: IncidentRec[]; resolutions: ResolutionRec[]; lines: string[] } {
|
|
111
|
+
function readStore(file: string): { incidents: IncidentRec[]; resolutions: ResolutionRec[]; proposals: ProposalRec[]; lines: string[] } {
|
|
98
112
|
let lines: string[] = [];
|
|
99
113
|
try {
|
|
100
114
|
lines = readFileSync(file, "utf8").split("\n").filter(l => l.trim());
|
|
101
115
|
} catch {}
|
|
102
116
|
const incidents: IncidentRec[] = [];
|
|
103
117
|
const resolutions: ResolutionRec[] = [];
|
|
118
|
+
const proposals: ProposalRec[] = [];
|
|
104
119
|
for (const line of lines) {
|
|
105
120
|
const rec = parseLine(line);
|
|
106
121
|
if (!rec) continue;
|
|
107
|
-
if ("type" in rec)
|
|
108
|
-
else
|
|
122
|
+
if (!("type" in rec)) incidents.push(rec);
|
|
123
|
+
else if (rec.type === "propose") proposals.push(rec);
|
|
124
|
+
else resolutions.push(rec);
|
|
109
125
|
}
|
|
110
|
-
return { incidents, resolutions, lines };
|
|
126
|
+
return { incidents, resolutions, proposals, lines };
|
|
111
127
|
}
|
|
112
128
|
|
|
113
129
|
function writeFile(cfg: Config, file: string, lines: string[]): void {
|
|
@@ -119,11 +135,16 @@ function writeFile(cfg: Config, file: string, lines: string[]): void {
|
|
|
119
135
|
export function readIncidents(cfg: Config): IncidentView[] {
|
|
120
136
|
const store = readStore(incidentsFile(cfg));
|
|
121
137
|
const views = new Map<string, IncidentView>();
|
|
122
|
-
for (const rec of store.incidents) views.set(rec.id, { ...rec, resolution: null });
|
|
138
|
+
for (const rec of store.incidents) views.set(rec.id, { ...rec, resolution: null, proposal: null });
|
|
123
139
|
for (const res of store.resolutions) {
|
|
124
140
|
const v = views.get(res.id);
|
|
125
141
|
if (v) v.resolution = res;
|
|
126
142
|
}
|
|
143
|
+
// A later propose replaces an earlier one: file order, last wins.
|
|
144
|
+
for (const p of store.proposals) {
|
|
145
|
+
const v = views.get(p.id);
|
|
146
|
+
if (v) v.proposal = p;
|
|
147
|
+
}
|
|
127
148
|
return [...views.values()];
|
|
128
149
|
}
|
|
129
150
|
|
|
@@ -148,7 +169,7 @@ export function addIncident(cfg: Config, input: IncidentInput, now = nowSec()):
|
|
|
148
169
|
return rec && !("type" in rec) && rec.id === open.id ? JSON.stringify(open) : line;
|
|
149
170
|
});
|
|
150
171
|
writeFile(cfg, file, lines);
|
|
151
|
-
return { incident: { ...open, resolution: null }, deduped: true };
|
|
172
|
+
return { incident: { ...open, resolution: null, proposal: null }, deduped: true };
|
|
152
173
|
}
|
|
153
174
|
const day = strftime(now, "%Y%m%d");
|
|
154
175
|
const prefix = `I-${day}-`;
|
|
@@ -166,7 +187,7 @@ export function addIncident(cfg: Config, input: IncidentInput, now = nowSec()):
|
|
|
166
187
|
};
|
|
167
188
|
mkdirSync(dirname(file), { recursive: true });
|
|
168
189
|
appendFileSync(file, `${JSON.stringify(rec)}\n`);
|
|
169
|
-
return { incident: { ...rec, resolution: null }, deduped: false };
|
|
190
|
+
return { incident: { ...rec, resolution: null, proposal: null }, deduped: false };
|
|
170
191
|
}
|
|
171
192
|
|
|
172
193
|
/**
|
|
@@ -202,6 +223,10 @@ export function planIncident(cfg: Config, id: string, planPath: string): string
|
|
|
202
223
|
/** The kinds plan-guard's recordFindings writes; only the owner's own words dismiss them. */
|
|
203
224
|
const FINDING_KINDS: Record<string, true> = { "agent-finding": true, "main-finding": true };
|
|
204
225
|
|
|
226
|
+
export function isFindingKind(kind: string): boolean {
|
|
227
|
+
return Object.hasOwn(FINDING_KINDS, kind);
|
|
228
|
+
}
|
|
229
|
+
|
|
205
230
|
export interface OwnerMessage {
|
|
206
231
|
at: number;
|
|
207
232
|
text: string;
|
|
@@ -226,11 +251,30 @@ export function ownerSaid(words: string, messages: OwnerMessage[], now: number):
|
|
|
226
251
|
return messages.some(m => now - m.at >= 0 && now - m.at <= 86400 && m.text.toLowerCase().replace(/\s+/g, " ").includes(quote));
|
|
227
252
|
}
|
|
228
253
|
|
|
254
|
+
/** The proof a proposal must cite: a file and a line, e.g. `src/core/guards.ts:40`. */
|
|
255
|
+
const PROOF_REF = /\S+:\d+/;
|
|
256
|
+
|
|
257
|
+
/** Records Main's reason that a finding is or is not a bug. A finding stays open after a proposal: the
|
|
258
|
+
* owner taps it on the phone page or a plan closes it. A newer proposal replaces the older one. */
|
|
259
|
+
export function proposeIncident(cfg: Config, id: string, why: string, now = nowSec()): string | null {
|
|
260
|
+
const file = incidentsFile(cfg);
|
|
261
|
+
const store = readStore(file);
|
|
262
|
+
const rec = store.incidents.find(i => i.id === id);
|
|
263
|
+
if (!rec) return `unknown incident ${id}`;
|
|
264
|
+
if (store.resolutions.some(r => r.id === id)) return `incident ${id} already has a resolution record`;
|
|
265
|
+
if (!isFindingKind(rec.kind)) return `refused: propose is for finding incidents (agent-finding, main-finding); ${id} is ${rec.kind}`;
|
|
266
|
+
if (!PROOF_REF.test(why)) return "refused: the why must cite the proof as file:line, e.g. src/core/guards.ts:40";
|
|
267
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
268
|
+
appendFileSync(file, `${JSON.stringify({ type: "propose", id, why: why.trim(), ts: now })}\n`);
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
|
|
229
272
|
/** Records why an incident is not a bug (or not worth fixing); an empty why is refused. A finding
|
|
230
273
|
* incident (kind "agent-finding"/"main-finding") is dismissed only with `owner` — a quote
|
|
231
274
|
* `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
|
-
|
|
275
|
+
* agent that found the bug cannot also wave it away). `tapLogin` is the owner's login from the
|
|
276
|
+
* owner page's authenticated POST /incident ("false alarm" tap); only that handler passes it. */
|
|
277
|
+
export function dismissIncident(cfg: Config, id: string, why: string, owner?: string, tapLogin?: string): string | null {
|
|
234
278
|
const file = incidentsFile(cfg);
|
|
235
279
|
const store = readStore(file);
|
|
236
280
|
const rec = store.incidents.find(i => i.id === id);
|
|
@@ -238,7 +282,7 @@ export function dismissIncident(cfg: Config, id: string, why: string, owner?: st
|
|
|
238
282
|
const res = store.resolutions.filter(r => r.id === id).at(-1);
|
|
239
283
|
if (res) return `incident ${id} already has a ${res.type} record`;
|
|
240
284
|
if (!why.trim()) return "refused: an empty --why would hide the incident without a recorded reason";
|
|
241
|
-
if (
|
|
285
|
+
if (isFindingKind(rec.kind) && tapLogin === undefined) {
|
|
242
286
|
if (owner === undefined)
|
|
243
287
|
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
288
|
if (!ownerSaid(owner, readOwnerMessages(), nowSec()))
|
package/src/core/owner-ui.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { chatTier, currentTier, type Tier } from "./autonomy.ts";
|
|
|
16
16
|
import type { Config } from "./config.ts";
|
|
17
17
|
import { nowSec, strftime } from "./clock.ts";
|
|
18
18
|
import { cpuCount } from "./host.ts";
|
|
19
|
-
import { openIncidents } from "./incidents.ts";
|
|
19
|
+
import { dismissIncident, isFindingKind, openIncidents } from "./incidents.ts";
|
|
20
20
|
import { byText, knowledgeManifest, readKnowledgeTopicFile, urlField, urlValue, type KnowledgeEntry } from "./knowledge.ts";
|
|
21
21
|
import { log } from "./guards.ts";
|
|
22
22
|
import { readMetricEvents } from "./metrics.ts";
|
|
@@ -165,6 +165,8 @@ export interface IncidentRow {
|
|
|
165
165
|
kind: string;
|
|
166
166
|
summary: string;
|
|
167
167
|
count: number;
|
|
168
|
+
/** Main's latest written reason for a finding incident; null when none or not a finding. */
|
|
169
|
+
proposal: string | null;
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
/** A markdown table from the ranking board plus every non-table line, kept in order. */
|
|
@@ -267,7 +269,13 @@ export function ciRows(cfg: Config): CiRow[] {
|
|
|
267
269
|
}
|
|
268
270
|
|
|
269
271
|
export function incidentRows(cfg: Config): IncidentRow[] {
|
|
270
|
-
return openIncidents(cfg).map(i => ({
|
|
272
|
+
return openIncidents(cfg).map(i => ({
|
|
273
|
+
id: i.id,
|
|
274
|
+
kind: i.kind,
|
|
275
|
+
summary: i.summary,
|
|
276
|
+
count: i.count,
|
|
277
|
+
proposal: isFindingKind(i.kind) ? (i.proposal?.why ?? null) : null,
|
|
278
|
+
}));
|
|
271
279
|
}
|
|
272
280
|
|
|
273
281
|
export function scoresData(cfg: Config): ScoresData {
|
|
@@ -563,9 +571,20 @@ function ciHtml(rows: CiRow[]): string {
|
|
|
563
571
|
.join("")}</ul>`;
|
|
564
572
|
}
|
|
565
573
|
|
|
566
|
-
function incidentsHtml(rows: IncidentRow[]): string {
|
|
574
|
+
function incidentsHtml(rows: IncidentRow[], tab: string): string {
|
|
567
575
|
return `<ul class="incidents">${rows
|
|
568
|
-
.map(r =>
|
|
576
|
+
.map(r => {
|
|
577
|
+
const head = `<span class="mono">${esc(r.id)}</span> <span class="chip bad">${esc(r.kind)}</span> ${esc(r.summary)}${r.count > 1 ? ` · ${r.count}x` : ""}`;
|
|
578
|
+
if (!isFindingKind(r.kind)) return `<li>${head}</li>`;
|
|
579
|
+
const why = r.proposal === null ? `<em>Main has not said why yet</em>` : esc(r.proposal);
|
|
580
|
+
return `<li>${head}<div class="sub">${why}</div>
|
|
581
|
+
<form method="post" action="/incident" class="inline">
|
|
582
|
+
<input type="hidden" name="id" value="${esc(r.id)}">
|
|
583
|
+
<input type="hidden" name="tab" value="${esc(tab)}">
|
|
584
|
+
<button class="btn" type="submit" name="choice" value="bug">It's a bug — plan it</button>
|
|
585
|
+
<button class="btn" type="submit" name="choice" value="false">False alarm</button>
|
|
586
|
+
</form></li>`;
|
|
587
|
+
})
|
|
569
588
|
.join("")}</ul>`;
|
|
570
589
|
}
|
|
571
590
|
|
|
@@ -667,6 +686,12 @@ function receiptText(sent: string, params: URLSearchParams): string | null {
|
|
|
667
686
|
case "message":
|
|
668
687
|
text = `Sent to Main · ${strftime(nowSec(), "%H:%M")}`;
|
|
669
688
|
break;
|
|
689
|
+
case "incident-closed":
|
|
690
|
+
text = `Marked as a false alarm · ${strftime(nowSec(), "%H:%M")}`;
|
|
691
|
+
break;
|
|
692
|
+
case "incident-bug":
|
|
693
|
+
text = `Sent to Main to plan the fix · ${strftime(nowSec(), "%H:%M")}`;
|
|
694
|
+
break;
|
|
670
695
|
case "unlock": {
|
|
671
696
|
const minutes = Number(params.get("minutes"));
|
|
672
697
|
text = Number.isInteger(minutes) && minutes > 0 ? `Unlocked for ${minutes} min` : "Unlocked";
|
|
@@ -935,7 +960,7 @@ export function renderPage(cfg: Config, data: PageData, params: URLSearchParams,
|
|
|
935
960
|
const working =
|
|
936
961
|
data.agents === null ? na("Working now") : data.agents.length ? `<ul class="agents">${data.agents.map(agentRowHtml).join("")}</ul>` : `<p class="empty">No agents running</p>`;
|
|
937
962
|
const scores = data.scores === null ? na("Agent scores") : scoresHtml(data.scores);
|
|
938
|
-
const incidents = data.incidents === null ? na("Incidents") : data.incidents.length ? incidentsHtml(data.incidents) : `<p class="empty">No open incidents</p>`;
|
|
963
|
+
const incidents = data.incidents === null ? na("Incidents") : data.incidents.length ? incidentsHtml(data.incidents, tab) : `<p class="empty">No open incidents</p>`;
|
|
939
964
|
const merges = data.ci === null ? na("Merges") : data.ci.length ? ciHtml(data.ci) : `<p class="empty">No CI runs recorded</p>`;
|
|
940
965
|
const machine = data.machine === null ? na("Machine") : machineHtml(cfg, data.machine);
|
|
941
966
|
const body =
|
|
@@ -1177,6 +1202,47 @@ function handleAnswer(cfg: Config, source: RunSource, fields: Record<string, str
|
|
|
1177
1202
|
return redirect(sentTo(fields.tab ?? "", "sent=answer"));
|
|
1178
1203
|
}
|
|
1179
1204
|
|
|
1205
|
+
// ---- POST /incident (plan P3): the owner's tap on a finding: "false alarm" closes it, "bug" plans it ----
|
|
1206
|
+
|
|
1207
|
+
function handleIncident(cfg: Config, fields: Record<string, string>, login: string, wantsJson: boolean): Response {
|
|
1208
|
+
const id = (fields.id ?? "").trim();
|
|
1209
|
+
const choice = (fields.choice ?? "").trim();
|
|
1210
|
+
const fail = (error: string, status: number): Response => (wantsJson ? jsonFail(error, status) : textRes(error, status));
|
|
1211
|
+
if (choice !== "bug" && choice !== "false") return fail("choice must be bug or false", 400);
|
|
1212
|
+
const view = openIncidents(cfg).find(i => i.id === id);
|
|
1213
|
+
if (!view) return fail("incident is not open", 409);
|
|
1214
|
+
if (!isFindingKind(view.kind)) return fail("only a finding is tapped here", 409);
|
|
1215
|
+
if (choice === "false") {
|
|
1216
|
+
const why = `owner tapped "false alarm" on the phone page (${login}): ${view.proposal?.why ?? "no reason given"}`;
|
|
1217
|
+
const err = dismissIncident(cfg, id, why, undefined, login);
|
|
1218
|
+
if (err) return fail(err, 409);
|
|
1219
|
+
if (wantsJson) return jsonSent("incident-closed", receiptText("incident-closed", new URLSearchParams()));
|
|
1220
|
+
return redirect(sentTo(fields.tab ?? "", "sent=incident-closed"));
|
|
1221
|
+
}
|
|
1222
|
+
storeOwnerMessage(`${id}: it's a bug — plan it`, login, []);
|
|
1223
|
+
if (wantsJson) return jsonSent("incident-bug", receiptText("incident-bug", new URLSearchParams()));
|
|
1224
|
+
return redirect(sentTo(fields.tab ?? "", "sent=incident-bug"));
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
/** Stores an owner message (text and images) under a new id and inboxes it for Main (P13/P14). */
|
|
1228
|
+
function storeOwnerMessage(text: string, login: string, images: { bytes: Uint8Array; kind: string }[]): void {
|
|
1229
|
+
const ts = nowSec();
|
|
1230
|
+
// The dir name starts with a whole-second ts: the sweep and the image route both parse it.
|
|
1231
|
+
const id = `${Math.floor(ts)}-${randomUUID().slice(0, 6)}`;
|
|
1232
|
+
const dir = `${ownerMessagesDir()}/${id}`;
|
|
1233
|
+
mkdirSync(dir, { recursive: true });
|
|
1234
|
+
const names: string[] = [];
|
|
1235
|
+
for (let i = 0; i < images.length; i++) {
|
|
1236
|
+
const name = `${i + 1}.${IMAGE_EXT[images[i]!.kind]}`;
|
|
1237
|
+
writeFileSync(`${dir}/${name}`, images[i]!.bytes);
|
|
1238
|
+
names.push(name);
|
|
1239
|
+
}
|
|
1240
|
+
writeFileSync(`${dir}/message.json`, `${JSON.stringify({ ts, text, login, images: names })}\n`);
|
|
1241
|
+
mkdirSync(stateDirPath(), { recursive: true });
|
|
1242
|
+
// The text stays out of owner-inbox.jsonl; Main reads message.json through the id (P14).
|
|
1243
|
+
appendFileSync(inboxPath(), `${JSON.stringify({ ts, kind: "message", id, login })}\n`);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1180
1246
|
// ---- POST /message (plan P13): the owner's one-way note plus images, inboxed by id ----
|
|
1181
1247
|
|
|
1182
1248
|
async function handleMessage(req: Request, login: string, wantsJson: boolean): Promise<Response> {
|
|
@@ -1204,21 +1270,7 @@ async function handleMessage(req: Request, login: string, wantsJson: boolean): P
|
|
|
1204
1270
|
if (!kind) return fail("attachments must be PNG, JPEG, GIF or WEBP images — the type is read from the file itself");
|
|
1205
1271
|
images.push({ bytes: data, kind });
|
|
1206
1272
|
}
|
|
1207
|
-
|
|
1208
|
-
// The dir name starts with a whole-second ts: the sweep and the image route both parse it.
|
|
1209
|
-
const id = `${Math.floor(ts)}-${randomUUID().slice(0, 6)}`;
|
|
1210
|
-
const dir = `${ownerMessagesDir()}/${id}`;
|
|
1211
|
-
mkdirSync(dir, { recursive: true });
|
|
1212
|
-
const names: string[] = [];
|
|
1213
|
-
for (let i = 0; i < images.length; i++) {
|
|
1214
|
-
const name = `${i + 1}.${IMAGE_EXT[images[i]!.kind]}`;
|
|
1215
|
-
writeFileSync(`${dir}/${name}`, images[i]!.bytes);
|
|
1216
|
-
names.push(name);
|
|
1217
|
-
}
|
|
1218
|
-
writeFileSync(`${dir}/message.json`, `${JSON.stringify({ ts, text, login, images: names })}\n`);
|
|
1219
|
-
mkdirSync(stateDirPath(), { recursive: true });
|
|
1220
|
-
// The text stays out of owner-inbox.jsonl; Main reads message.json through the id (P14).
|
|
1221
|
-
appendFileSync(inboxPath(), `${JSON.stringify({ ts, kind: "message", id, login })}\n`);
|
|
1273
|
+
storeOwnerMessage(text, login, images);
|
|
1222
1274
|
if (wantsJson) return jsonSent("message", receiptText("message", new URLSearchParams()));
|
|
1223
1275
|
return redirect("/?sent=message");
|
|
1224
1276
|
}
|
|
@@ -1463,6 +1515,9 @@ export function startOwnerUi(opts: OwnerUiOptions): OwnerUiServer {
|
|
|
1463
1515
|
if (url.pathname === "/message") {
|
|
1464
1516
|
res = await handleMessage(req, login, wantsJson);
|
|
1465
1517
|
code = res.status;
|
|
1518
|
+
} else if (url.pathname === "/incident") {
|
|
1519
|
+
res = handleIncident(cfg, await fieldsOf(req), login, wantsJson);
|
|
1520
|
+
code = res.status;
|
|
1466
1521
|
} else if (url.pathname === "/answer") {
|
|
1467
1522
|
res = handleAnswer(cfg, source, await fieldsOf(req), login, wantsJson);
|
|
1468
1523
|
code = res.status;
|