neurastream 0.1.22 → 0.1.23

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 CHANGED
@@ -147,7 +147,16 @@ bun add -g neurastream@latest
147
147
  neurastream adapter install omp
148
148
  ```
149
149
 
150
- Live copies are never hand-edited. `neurastream doctor` names each hand-edited or foreign installed file, and a stale install (the installed version is not `npm view neurastream version`). If the registry cannot be reached, that check is a warning, not a failure.
150
+ Live copies are never hand-edited. `neurastream doctor` names each hand-edited installed file and each missing one (`missing:`), and a stale install (the installed version is not `npm view neurastream version`). If the registry cannot be reached, that check is a warning, not a failure.
151
+
152
+ ## AGENTS.md block
153
+
154
+ `adapter install omp` writes the neurastream orchestrator rules into `~/.omp/agent/AGENTS.md`, between the markers `<!-- neurastream:begin (managed by neurastream; edit the package, not this block) -->` and `<!-- neurastream:end -->`. The rules come from `templates/AGENTS.md`; the agent dir comes from your config.
155
+
156
+ - Managed: the text between the markers. Install replaces it. A second install changes nothing.
157
+ - Yours: every line outside the markers. Install keeps it byte for byte. A file with no markers gets the block appended.
158
+ - Drift: `neurastream doctor` reports `stale:` when the text between the markers differs from the package's block, and `missing:` when the markers are absent. Edits outside the markers are never reported.
159
+ - Edit limit: the project-file changes Main gets per window come from `guards.main_edit_limit` and `guards.main_window_min`, not from the block text.
151
160
 
152
161
  ## License
153
162
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neurastream",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "Guardrails for running many AI coding agents at once: plan queue, blockers, call budgets, provider caps, scoring, merge-verified close.",
5
5
  "keywords": ["ai-agents", "coding-agents", "orchestration", "guardrails", "omp", "bun", "cli"],
6
6
  "homepage": "https://github.com/umiddey/neurastream#readme",
@@ -1,5 +1,5 @@
1
- // Reports hand-edited or foreign live files the omp adapter installs, and a stale
2
- // registry version. Offline `npm view` is a warning, not a failure.
1
+ // Reports hand-edited or missing live files the omp adapter installs, the managed block in
2
+ // the owner's AGENTS.md, and a stale registry version. Offline `npm view` is a warning, not a failure.
3
3
  // Notes, INDEX, queue state and config are user state: not checked.
4
4
 
5
5
  import { spawnSync } from "node:child_process";
@@ -7,6 +7,8 @@ import { existsSync, lstatSync, readdirSync, readFileSync, realpathSync } from "
7
7
  import { homedir } from "node:os";
8
8
  import { dirname, join, relative, resolve } from "node:path";
9
9
  import { fileURLToPath } from "node:url";
10
+ import { blockState, renderBlock } from "../../core/agents-md.ts";
11
+ import { loadConfig } from "../../core/config.ts";
10
12
 
11
13
  const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
12
14
 
@@ -30,6 +32,11 @@ export function packageBins(root: string): { name: string; source: string }[] {
30
32
  return Object.entries(pkg.bin ?? {}).map(([name, rel]) => ({ name, source: join(root, rel) }));
31
33
  }
32
34
 
35
+ /** The omp agent's AGENTS.md, which carries the managed neurastream block. */
36
+ export function liveAgentsMd(home: string): string {
37
+ return join(home, ".omp/agent/AGENTS.md");
38
+ }
39
+
33
40
  /** Files adapter install places under this home. Bun's global bin dir is extra, checked only when a name is present. */
34
41
  export function adapterLiveFiles(home: string, root: string = PACKAGE_ROOT): LiveFile[] {
35
42
  const files: LiveFile[] = [];
@@ -154,7 +161,7 @@ export function doctorReport(home: string, env: NodeJS.ProcessEnv = process.env)
154
161
  if (seen.has(file.live)) continue;
155
162
  seen.add(file.live);
156
163
  if (!existsSync(file.live)) {
157
- problems.push(`foreign: ${file.live}`);
164
+ problems.push(`missing: ${file.live}`);
158
165
  continue;
159
166
  }
160
167
  if (isPackageFile(file.live, file.source)) {
@@ -163,6 +170,11 @@ export function doctorReport(home: string, env: NodeJS.ProcessEnv = process.env)
163
170
  }
164
171
  problems.push(`hand-edited: ${file.live}`);
165
172
  }
173
+ const agents = liveAgentsMd(home);
174
+ const text = existsSync(agents) ? readFileSync(agents, "utf8") : "";
175
+ const state = blockState(text, renderBlock(loadConfig({ home, env })));
176
+ if (state === "ok") ok.push(`${agents} neurastream block`);
177
+ else problems.push(`${state}: ${agents} neurastream block`);
166
178
  const warnings: string[] = [];
167
179
  const viewed = npmViewVersion(name, env);
168
180
  let registry: string | null = null;
@@ -6,9 +6,10 @@ import { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSy
6
6
  import { homedir } from "node:os";
7
7
  import { dirname, join, resolve } from "node:path";
8
8
  import { fileURLToPath } from "node:url";
9
- import { configFile } from "../../core/config.ts";
9
+ import { renderBlock, upsertBlock } from "../../core/agents-md.ts";
10
+ import { configFile, loadConfig } from "../../core/config.ts";
10
11
 
11
- import { adapterLiveFiles } from "./doctor.ts";
12
+ import { adapterLiveFiles, liveAgentsMd } from "./doctor.ts";
12
13
  // Registers the plugin-command matcher into core's writeTargets (side effect).
13
14
  import "./package-ops.ts";
14
15
  const PACKAGE_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "../../..");
@@ -31,6 +32,7 @@ export interface InstallResult {
31
32
  pinsCopied: string[];
32
33
  pinsKept: string[];
33
34
  overlay: "written" | "unchanged";
35
+ agentsMd: "written" | "unchanged";
34
36
  }
35
37
 
36
38
  function ensureLink(link: string, target: string): void {
@@ -101,6 +103,17 @@ function writeOverlay(file: string): "written" | "unchanged" {
101
103
  return "written";
102
104
  }
103
105
 
106
+ // Writes the managed block into the owner's AGENTS.md: the rest of the file is never touched.
107
+ function writeAgentsMd(home: string): "written" | "unchanged" {
108
+ const file = liveAgentsMd(home);
109
+ const current = existsSync(file) ? readFileSync(file, "utf8") : "";
110
+ const next = upsertBlock(current, renderBlock(loadConfig({ home })));
111
+ if (next === current) return "unchanged";
112
+ mkdirSync(dirname(file), { recursive: true });
113
+ writeFileSync(file, next);
114
+ return "written";
115
+ }
116
+
104
117
  function linkPlugin(home: string): string {
105
118
  const r = spawnSync("omp", ["plugin", "link", PACKAGE_ROOT], {
106
119
  env: { ...process.env, HOME: home },
@@ -141,7 +154,8 @@ export function installOmp(home: string): InstallResult {
141
154
  linkInstalled(home);
142
155
  const plugin = linkPlugin(home);
143
156
  const overlay = writeOverlay(file);
144
- return { plugin, removedStaleLink, pinsCopied: pins.copied, pinsKept: pins.kept, overlay };
157
+ const agentsMd = writeAgentsMd(home);
158
+ return { plugin, removedStaleLink, pinsCopied: pins.copied, pinsKept: pins.kept, overlay, agentsMd };
145
159
  }
146
160
 
147
161
  export function printInstall(result: InstallResult): void {
@@ -150,6 +164,7 @@ export function printInstall(result: InstallResult): void {
150
164
  console.log(
151
165
  `neurastream adapter install omp: pins copied ${result.pinsCopied.length}, kept ${result.pinsKept.length}; overlay ${result.overlay}`,
152
166
  );
167
+ console.log(`neurastream adapter install omp: AGENTS.md block ${result.agentsMd}`);
153
168
  }
154
169
 
155
170
  export function runAdapterInstall(args: string[]): number {
@@ -0,0 +1,58 @@
1
+ // The managed block in the owner's AGENTS.md. The rules come from templates/AGENTS.md with the
2
+ // config's agent dir filled in; they sit between two markers, and only what is between them is
3
+ // ever written or checked against the package's block. Everything outside the markers stays the owner's.
4
+
5
+ import { readFileSync } from "node:fs";
6
+ import { dirname, join } from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+ import type { Config } from "./config.ts";
9
+
10
+ const HERE = dirname(fileURLToPath(import.meta.url));
11
+ export const AGENTS_TEMPLATE = join(HERE, "../../templates/AGENTS.md");
12
+ export const BEGIN_MARK = "<!-- neurastream:begin (managed by neurastream; edit the package, not this block) -->";
13
+ export const END_MARK = "<!-- neurastream:end -->";
14
+
15
+ export function renderBlock(cfg: Config, template: string = readFileSync(AGENTS_TEMPLATE, "utf8")): string {
16
+ const body = template.trimEnd().split("{{AGENT_DIR}}").join(cfg.paths.agent_dir);
17
+ return `${BEGIN_MARK}\n${body}\n${END_MARK}`;
18
+ }
19
+
20
+ function occurrences(text: string, mark: string): number[] {
21
+ const at: number[] = [];
22
+ for (let i = text.indexOf(mark); i !== -1; i = text.indexOf(mark, i + mark.length)) at.push(i);
23
+ return at;
24
+ }
25
+
26
+ // The block's span in a file, or null when there are no markers. Anything other than exactly one
27
+ // begin marker followed by exactly one end marker is malformed and throws.
28
+ function span(text: string): { start: number; end: number } | null {
29
+ const begins = occurrences(text, BEGIN_MARK);
30
+ const ends = occurrences(text, END_MARK);
31
+ const begin = begins[0];
32
+ const end = ends[0];
33
+ if (begin === undefined && end === undefined) return null;
34
+ if (begins.length !== 1 || ends.length !== 1 || begin === undefined || end === undefined || end < begin) {
35
+ throw new Error("neurastream block markers malformed: expected one begin marker, then one end marker");
36
+ }
37
+ return { start: begin, end: end + END_MARK.length };
38
+ }
39
+
40
+ // Replace the marked block, or append one when the file has none. Bytes outside the markers are kept.
41
+ export function upsertBlock(fileText: string, block: string): string {
42
+ const at = span(fileText);
43
+ if (at) return fileText.slice(0, at.start) + block + fileText.slice(at.end);
44
+ if (fileText === "") return `${block}\n`;
45
+ return `${fileText}\n${block}\n`;
46
+ }
47
+
48
+ // "missing": no block in the file. "stale": the block differs, or its markers are malformed.
49
+ export function blockState(fileText: string, block: string): "ok" | "stale" | "missing" {
50
+ let at: { start: number; end: number } | null;
51
+ try {
52
+ at = span(fileText);
53
+ } catch {
54
+ return "stale";
55
+ }
56
+ if (!at) return "missing";
57
+ return fileText.slice(at.start, at.end) === block ? "ok" : "stale";
58
+ }
@@ -572,10 +572,11 @@ export function checkInject(e: InjectEvent, cfg: Config): Decision {
572
572
  const cancel = continuation ? "" : flagCancel(e.inject, cfg);
573
573
  const incidents = openIncidentList(cfg);
574
574
  const incidentText = incidents.length ? `\n${incidents.map(incidentLine).join("\n")}` : "";
575
+ const editLimit = continuation ? "" : `\nmain-guard: Main may change project files at most ${cfg.guards.main_edit_limit} times per ${cfg.guards.main_window_min}-minute window; then delegate.`;
575
576
  return {
576
577
  allow: true,
577
578
  reason: "",
578
- inject: `${summary}\n(main-guard: read ${q.INDEX} and the listed repo INDEX.md files are summarised above; work the open plans, close finished ones with queue-close.)${cancel}${incidentText}`,
579
+ inject: `${summary}\n(main-guard: read ${q.INDEX} and the listed repo INDEX.md files are summarised above; work the open plans, close finished ones with queue-close.)${editLimit}${cancel}${incidentText}`,
579
580
  ...(continuation ? {} : { state: { callsSinceStop: 0, idleStops: 0 } }),
580
581
  };
581
582
  }
@@ -0,0 +1,27 @@
1
+ # neurastream: orchestrator rules
2
+
3
+ You are Main, the orchestrator. Main plans, delegates, reviews and lands; implementers do the work.
4
+
5
+ ## Plans
6
+ - When the owner asks for work in a repo, add the repo to `{{AGENT_DIR}}/INDEX.md` and the plan to the repo's INDEX.md.
7
+ - Entering a repo: read its AGENTS.md first.
8
+ - 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.
9
+ - Phase 0 of every plan: blocker scripts that stop the implementer from going against the plan. They must exist before any spawn.
10
+ - 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.
11
+ - Main may push and publish once the repo's AGENTS.md test rules are met.
12
+
13
+ ## Scripts (run at the stated moment)
14
+ |Script|When|
15
+ |---|---|
16
+ |`main-start`|session start, after an abort, before every status report|
17
+ |`queue-check`|after changing a plan or an index, before every spawn; exit 1 = fix first|
18
+ |`agent-ledger --cap`|before every spawn|
19
+ |`agent-score`|`gate <agent>` before every spawn; `accept`/`diagnose`/`penalty` after reviewing a result; `check` after every merge; `board` after a score change|
20
+ |`brief-lint <plan.md>`|before every spawn on that plan|
21
+ |`wip-check`|session start, before new work|
22
+ |`neurastream metrics ci <repo> <mr>`|after every merge|
23
+ |`neurastream metrics report`|weekly when main-start says due; propose ONE rule change to the owner|
24
+ |`neurastream incident list --open`|session start, before status reports, when a spawn or stop is blocked|
25
+ |`machine-guard`, `heavy-run`|machine-guard at session start and before launches; every test run goes through heavy-run|
26
+
27
+ Guard files are locked for every agent; the owner unlocks with `touch {{AGENT_DIR}}/.guard-unlock` (30 min).