neurastream 0.2.58 → 0.2.59
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/doctor.ts +28 -1
- package/src/adapters/omp/index.ts +6 -0
- package/src/core/page-notes.ts +9 -0
- package/src/core/pages-setup.ts +26 -3
- package/src/core/pages.ts +10 -3
- package/templates/AGENTS.md +1 -1
- package/templates/skills/architecture-drilldown/SKILL.md +1 -1
package/package.json
CHANGED
|
@@ -14,6 +14,8 @@ import { loadConfig } from "../../core/config.ts";
|
|
|
14
14
|
import { notifyFindings } from "../../core/notify.ts";
|
|
15
15
|
import { loadKnownSecrets, proxyOnPath } from "../../core/secret-redact.ts";
|
|
16
16
|
import { allowedAgents, readIndex, reviewAgentsProblem } from "../../core/queue/lib.ts";
|
|
17
|
+
import { systemRunner, type Runner } from "../../core/pages-setup.ts";
|
|
18
|
+
import { packageJsonPath } from "./package-root.ts";
|
|
17
19
|
import { realTailscale, type Tailscale } from "../../core/tailscale.ts";
|
|
18
20
|
|
|
19
21
|
const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
|
|
@@ -167,7 +169,24 @@ function npmViewVersion(name: string, env: NodeJS.ProcessEnv): { version: string
|
|
|
167
169
|
return { version };
|
|
168
170
|
}
|
|
169
171
|
|
|
170
|
-
|
|
172
|
+
/** The pages service's start as epoch ms, or null when it is not running or the stamp is unreadable (P6). */
|
|
173
|
+
export function pagesServiceStartMs(runner: Runner): number | null {
|
|
174
|
+
const r = runner(["--user", "show", "neurastream-pages.service", "--property=ActiveEnterTimestamp", "--value"]);
|
|
175
|
+
const m = r.status === 0 ? /^\w{3} (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})/.exec((r.stdout ?? "").trim()) : null;
|
|
176
|
+
// systemctl prints local wall time; a TZ-less ISO stamp parses as local too, so both sides agree
|
|
177
|
+
// (Date.parse alone returns NaN on the weekday prefix and zone abbrev).
|
|
178
|
+
return m === null ? null : Date.parse(`${m[1]}T${m[2]}`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function packageMtimeMs(): number | null {
|
|
182
|
+
try {
|
|
183
|
+
return statSync(packageJsonPath()).mtimeMs;
|
|
184
|
+
} catch {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function doctorReport(home: string, env: NodeJS.ProcessEnv = process.env, tailscale: Tailscale = realTailscale, systemctl: Runner = systemRunner): DoctorReport {
|
|
171
190
|
const pkg = readPackage(PACKAGE_ROOT);
|
|
172
191
|
const name = pkg.name ?? "neurastream";
|
|
173
192
|
const installed = pkg.version ?? "";
|
|
@@ -190,6 +209,14 @@ export function doctorReport(home: string, env: NodeJS.ProcessEnv = process.env,
|
|
|
190
209
|
const agents = liveAgentsMd(home);
|
|
191
210
|
const text = existsSync(agents) ? readFileSync(agents, "utf8") : "";
|
|
192
211
|
const cfg = loadConfig({ home, env });
|
|
212
|
+
// P6 (plan 20261031_0917): a pages server started before the installed package changed keeps old
|
|
213
|
+
// code — the owner's tap hit the pre-0.2.57 handler and the approval was lost (2026-10-31 09:34).
|
|
214
|
+
if (cfg.pages.enabled) {
|
|
215
|
+
const startedAt = pagesServiceStartMs(systemctl);
|
|
216
|
+
const installedAt = packageMtimeMs();
|
|
217
|
+
if (startedAt !== null && installedAt !== null && startedAt < installedAt)
|
|
218
|
+
problems.push("neurastream-pages.service is running code older than the installed package; run: systemctl --user restart neurastream-pages.service");
|
|
219
|
+
}
|
|
193
220
|
// The owner page (plan 20261024_2230): when it is switched on, the login must be set and
|
|
194
221
|
// tailscale must answer, or the unit will start and refuse, or serve nobody.
|
|
195
222
|
if (cfg.ui.enabled) {
|
|
@@ -469,6 +469,12 @@ export function ownerInboxMessage(rec: Record<string, unknown>): string | ({ typ
|
|
|
469
469
|
}
|
|
470
470
|
case "lock":
|
|
471
471
|
return "Owner locked the guards from the phone page.";
|
|
472
|
+
case "approval": {
|
|
473
|
+
const page = asString(rec.page);
|
|
474
|
+
const plan = asString(rec.plan);
|
|
475
|
+
if (page === "" || plan === "") return null;
|
|
476
|
+
return `Owner approved ${basename(plan)} on page ${page}.`;
|
|
477
|
+
}
|
|
472
478
|
case "reorder": {
|
|
473
479
|
const plan = asString(rec.plan);
|
|
474
480
|
const from = num(rec.from);
|
package/src/core/page-notes.ts
CHANGED
|
@@ -97,6 +97,15 @@ export interface AnsweredNote {
|
|
|
97
97
|
|
|
98
98
|
const ANSWERED_RE = /<section id="ns-answered"[\s\S]*?<\/section>\n?/i;
|
|
99
99
|
const APPROVE_RE = /<section id="ns-approve"[\s\S]*?<\/section>\n?/i;
|
|
100
|
+
const STYLE_RE = /<style data-ns-page-notes>[\s\S]*?<\/style>\n?/i;
|
|
101
|
+
const PANEL_RE = /<section id="ns-notes"[\s\S]*?<\/section>\n?/i;
|
|
102
|
+
const FAB_RE = /<button id="ns-note-fab"[\s\S]*?<\/button>\n?/i;
|
|
103
|
+
const SCRIPT_RE = /<script data-ns-page-notes>[\s\S]*?<\/script>\n?/i;
|
|
104
|
+
|
|
105
|
+
/** The html with the injected notes chrome gone, so a publish-time check sees the built page again (plan 20261031_0917 P2). */
|
|
106
|
+
export function stripPageNotes(html: string): string {
|
|
107
|
+
return [STYLE_RE, PANEL_RE, APPROVE_RE, ANSWERED_RE, FAB_RE, SCRIPT_RE].reduce((text, re) => text.replace(re, ""), html);
|
|
108
|
+
}
|
|
100
109
|
|
|
101
110
|
/** What the Approve bar needs: the page it approves, the notes still open on it and what the
|
|
102
111
|
* diagram check found (P9, P10). */
|
package/src/core/pages-setup.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { dirname, join, basename, extname, resolve } from "node:path";
|
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { configFile, loadConfig } from "./config.ts";
|
|
7
7
|
import { repoKey } from "./knowledge.ts";
|
|
8
|
-
import { injectPageNotes, type NotesGate } from "./page-notes.ts";
|
|
8
|
+
import { injectPageNotes, stripPageNotes, type NotesGate } from "./page-notes.ts";
|
|
9
9
|
import { recordPagePlan } from "./plan-approval.ts";
|
|
10
10
|
import { checkDiagram } from "./diagram-check.ts";
|
|
11
11
|
import { gitRaw } from "./proc.ts";
|
|
@@ -13,9 +13,11 @@ import { recordPublish } from "./pages-expiry.ts";
|
|
|
13
13
|
import { realTailscale, type Tailscale } from "./tailscale.ts";
|
|
14
14
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
15
15
|
export const PAGES_UNIT_TEMPLATE = join(HERE, "../../templates/systemd/neurastream-pages.service");
|
|
16
|
-
|
|
16
|
+
const DATA_MARK = "/* === DATA === */";
|
|
17
|
+
const END_DATA_MARK = "/* === END DATA === */";
|
|
18
|
+
export interface RunnerResult { status: number | null; stderr: string; stdout?: string }
|
|
17
19
|
export type Runner = (args: string[]) => RunnerResult;
|
|
18
|
-
export const systemRunner: Runner = args => { const r = spawnSync("systemctl", args, { encoding:"utf8" }); return { status:r.status, stderr:r.stderr ?? "" }; };
|
|
20
|
+
export const systemRunner: Runner = args => { const r = spawnSync("systemctl", args, { encoding:"utf8" }); return { status:r.status, stderr:r.stderr ?? "", stdout:r.stdout ?? "" }; };
|
|
19
21
|
export interface Setup { home?: string; runner?: Runner; tailscale?: Tailscale }
|
|
20
22
|
function editBlock(text: string | null, values: { enabled: boolean; port: number; dir: string }): string {
|
|
21
23
|
const fresh = ["pages:", ` enabled: ${values.enabled}`, ` port: ${values.port}`, ` dir: "${values.dir.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`];
|
|
@@ -76,6 +78,22 @@ export interface PublishOptions {
|
|
|
76
78
|
repo?: string;
|
|
77
79
|
}
|
|
78
80
|
|
|
81
|
+
/** P2 (plan 20261031_0917): a plan page is the drilldown skill's engine with only its DATA block
|
|
82
|
+
* edited — the owner approves a diagram the skill drew, not a hand-rolled page. The injected notes
|
|
83
|
+
* chrome is stripped first, so a republished page still compares clean against the template. */
|
|
84
|
+
const DRILLDOWN_TEMPLATE = join(HERE, "../../templates/skills/architecture-drilldown/template.html");
|
|
85
|
+
export function assertDrilldown(html: string): void {
|
|
86
|
+
const template = readFileSync(DRILLDOWN_TEMPLATE, "utf8");
|
|
87
|
+
const clean = stripPageNotes(html);
|
|
88
|
+
const at = clean.indexOf(DATA_MARK), end = clean.indexOf(END_DATA_MARK);
|
|
89
|
+
const part =
|
|
90
|
+
at < 0 || end < 0 ? "no DATA block"
|
|
91
|
+
: clean.slice(0, at) !== template.slice(0, template.indexOf(DATA_MARK)) ? "the part before DATA"
|
|
92
|
+
: clean.slice(end + END_DATA_MARK.length) !== template.slice(template.indexOf(END_DATA_MARK) + END_DATA_MARK.length) ? "the part after END DATA"
|
|
93
|
+
: null;
|
|
94
|
+
if (part !== null) throw new Error(`pages: a plan page must be built from ${DRILLDOWN_TEMPLATE}: copy it and edit only the DATA block (${part})`);
|
|
95
|
+
}
|
|
96
|
+
|
|
79
97
|
export function publishPage(file: string, name: string | undefined, force: boolean, dir: string, opts: PublishOptions = {}): string {
|
|
80
98
|
const keep = opts.keep ?? false, keepDays = opts.keepDays ?? 15, now = opts.now ?? new Date(), notes = opts.notes;
|
|
81
99
|
const source=basename(file), base=(name ?? source.slice(0,source.length-extname(source).length)).toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");
|
|
@@ -88,7 +106,12 @@ export function publishPage(file: string, name: string | undefined, force: boole
|
|
|
88
106
|
let diagram: { missing: string[]; thin: string[] } | null = null;
|
|
89
107
|
if (opts.plan !== undefined) {
|
|
90
108
|
if (extname(source).toLowerCase() !== ".html") throw new Error(`pages: --plan needs an HTML artifact, not ${source}`);
|
|
109
|
+
assertDrilldown(readFileSync(file, "utf8"));
|
|
91
110
|
diagram = checkDiagram(readFileSync(file, "utf8"), readFileSync(opts.plan, "utf8"));
|
|
111
|
+
// P7 (plan 20261031_0917): an incomplete diagram must not publish at all — the Approve bar only
|
|
112
|
+
// disables itself, and once a link the owner could not approve went out (I-20261031-329).
|
|
113
|
+
const unproven = [...diagram.missing, ...diagram.thin];
|
|
114
|
+
if (unproven.length > 0) throw new Error(`pages: ${targetName} diagram is not complete (${unproven.length}): ${unproven.join("; ")}`);
|
|
92
115
|
}
|
|
93
116
|
const approve = opts.plan === undefined || diagram === null ? undefined : { page: targetName, open, problems: [...diagram.missing, ...diagram.thin] };
|
|
94
117
|
if(open.length>0) throw new Error(`pages: ${targetName} has ${open.length} open note(s) (${open.join(", ")}); answer each one before publishing (see \`neurastream notes check ${targetName}\`)`);
|
package/src/core/pages.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { existsSync, lstatSync, readdirSync, readFileSync } from "node:fs";
|
|
1
|
+
import { appendFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync } from "node:fs";
|
|
2
2
|
import { basename, extname, resolve } from "node:path";
|
|
3
3
|
import type { Config } from "./config.ts";
|
|
4
|
-
import { isLoopback, isTailnet, type UiHttpServer } from "./owner-ui.ts";
|
|
4
|
+
import { isLoopback, isTailnet, inboxPath, type UiHttpServer } from "./owner-ui.ts";
|
|
5
|
+
import { nowSec } from "./clock.ts";
|
|
5
6
|
import { appendPageNotes, openNoteIds } from "./page-notes.ts";
|
|
6
7
|
import { approvePlanFile, readPagePlan } from "./plan-approval.ts";
|
|
8
|
+
import { stateDirPath } from "./queue/lib.ts";
|
|
7
9
|
import type { RunSource } from "./adapter.ts";
|
|
8
10
|
import type { Tailscale } from "./tailscale.ts";
|
|
9
11
|
|
|
@@ -42,7 +44,12 @@ export function startPagesServer(opts: PagesOptions): PagesServer {
|
|
|
42
44
|
const plan = record.plan;
|
|
43
45
|
if (!existsSync(plan)) return plain("not found: the plan file is gone", 404);
|
|
44
46
|
try {
|
|
45
|
-
|
|
47
|
+
const approved = approvePlanFile(plan, page);
|
|
48
|
+
// P5 (plan 20261031_0917): the tap must reach Main at once — one owner-inbox row, the same
|
|
49
|
+
// direct append the message POST uses; never a page note, which would 409 the next tap.
|
|
50
|
+
mkdirSync(stateDirPath(), { recursive: true });
|
|
51
|
+
appendFileSync(inboxPath(), `${JSON.stringify({ ts: nowSec(), kind: "approval", page, plan, login })}\n`);
|
|
52
|
+
return Response.json({ approved });
|
|
46
53
|
} catch (e) {
|
|
47
54
|
return plain(`not approved: ${e instanceof Error ? e.message : String(e)}`, 500);
|
|
48
55
|
}
|
package/templates/AGENTS.md
CHANGED
|
@@ -12,7 +12,7 @@ You are Main, the orchestrator. Main plans, delegates, reviews and lands; implem
|
|
|
12
12
|
- Main writes every plan in `<repo>/docs/plans/`, shaped like `{{AGENT_DIR}}/queue/TEMPLATE.md`. Do the research yourself; never base a plan on another agent's findings.
|
|
13
13
|
- Phase 0 of every plan: blocker scripts that stop the implementer from going against the plan. They must exist before any spawn.
|
|
14
14
|
- Every plan has `## Reuse`; no spawn without a current reviewer PASS (`templates/plan-review-brief.md`, recorded only from the reviewer's own Progress edit); a brief names every open MR of its plan with an `MR !N:` line.
|
|
15
|
-
- Plan order: plan → page (`neurastream pages publish <page.html> --plan <plan.md>`) → owner approves (Approve on the page, or types `approve <YYYYMMDD_HHMM>`) → reviewer PASS → implementer. Once `approval.since` is set, a plan stamped at or after it gets no spawn without a page and an approval record for its current text; a body edit voids the approval, a Progress-only edit keeps it.
|
|
15
|
+
- Plan order: plan → page built from the architecture-drilldown template (`neurastream pages publish <page.html> --plan <plan.md>` refuses anything else) → owner approves (Approve on the page, or types `approve <YYYYMMDD_HHMM>`) → reviewer PASS → implementer. Once `approval.since` is set, a plan stamped at or after it gets no spawn without a page and an approval record for its current text; a body edit voids the approval, a Progress-only edit keeps it.
|
|
16
16
|
- An open plan gets an implementer subagent. When it claims done, verify (another subagent or yourself). Not done → spawn another implementer for the rest. Done → set `Status: complete`; `queue-close` then archives it and cleans the indexes.
|
|
17
17
|
- Owner asks about a past plan → grep FINISHED.md first; open the archived plan only for details.
|
|
18
18
|
- An implementer's new `## Progress` entry ends with a `Findings:` line — `Findings: none`, or one item per finding with `file:line` evidence; plan-guard restores an entry without it. Findings stay notes: they never become incidents.
|
|
@@ -53,4 +53,4 @@ Open the file at two widths and check the root plus one drilled level:
|
|
|
53
53
|
|
|
54
54
|
## Host
|
|
55
55
|
|
|
56
|
-
Build the HTML in a scratch directory (`mktemp -d`), not in a repo. Publish it with `neurastream pages publish <file>`. The page is deleted after 15 days. Add `--keep` only when the owner's prompt says to keep it permanently. Never commit the HTML into a repo unless the owner asks.
|
|
56
|
+
Build the HTML in a scratch directory (`mktemp -d`), not in a repo. Publish it with `neurastream pages publish <file>`. A plan page (`--plan`) is refused unless it is this template with only DATA edited. The page is deleted after 15 days. Add `--keep` only when the owner's prompt says to keep it permanently. Never commit the HTML into a repo unless the owner asks.
|