neurastream 0.2.10 → 0.2.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neurastream",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
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": [
6
6
  "ai-agents",
@@ -20,7 +20,7 @@ import { appendFileSync, mkdirSync, openSync, readFileSync, renameSync, rmSync,
20
20
  import { basename, dirname, join } from "node:path";
21
21
  import type { Decision } from "../../core/adapter.ts";
22
22
  import { loadConfig, type Config } from "../../core/config.ts";
23
- import { nowSec } from "../../core/clock.ts";
23
+ import { nowSec, strftime } from "../../core/clock.ts";
24
24
  import { runDetectorsGated } from "../../core/incident-detectors.ts";
25
25
  import { checkInject, checkPlanEdit, checkStop, checkTool, MAIN_PLAN_FILE, recordMainResult, revertMainEdit, rekeySpawnFile } from "../../core/guards.ts";
26
26
  import { postReply } from "../../core/notify.ts";
@@ -291,13 +291,37 @@ function writeOwnerInboxCursor(n: number): void {
291
291
  } catch {}
292
292
  }
293
293
 
294
- /** The user message one inbox record becomes, or null when it is not a page answer. */
294
+ /** The user message one inbox record becomes, or null when the record is not one Main can act on.
295
+ * Records without `kind` are page answers (the original shape). */
295
296
  export function ownerInboxMessage(rec: Record<string, unknown>): string | null {
296
- const plan = asString(rec.plan);
297
- const question = asString(rec.question);
298
- const answer = asString(rec.answer);
299
- if (!plan || !question || !answer) return null;
300
- return `Owner answered on the phone page — ${basename(plan)}: ${question} → ${answer}`;
297
+ const kind = rec.kind === undefined ? "answer" : asString(rec.kind);
298
+ const num = (v: unknown): number | null => (typeof v === "number" && Number.isFinite(v) ? v : null);
299
+ switch (kind) {
300
+ case "answer": {
301
+ const plan = asString(rec.plan);
302
+ const question = asString(rec.question);
303
+ const answer = asString(rec.answer);
304
+ if (!plan || !question || !answer) return null;
305
+ return `Owner answered on the phone page — ${basename(plan)}: ${question} → ${answer}`;
306
+ }
307
+ case "unlock": {
308
+ const minutes = num(rec.minutes);
309
+ const until = num(rec.until);
310
+ if (minutes === null || until === null) return null;
311
+ return `Owner unlocked the guards from the phone page for ${minutes} min (until ${strftime(until, "%H:%M")}). Do the step that waited on the unlock now.`;
312
+ }
313
+ case "lock":
314
+ return "Owner locked the guards from the phone page.";
315
+ case "reorder": {
316
+ const plan = asString(rec.plan);
317
+ const from = num(rec.from);
318
+ const to = num(rec.to);
319
+ if (!plan || from === null || to === null) return null;
320
+ return `Owner moved ${basename(plan)} from #${from} to #${to} on the phone page; INDEX.md has the new order — work by it.`;
321
+ }
322
+ default:
323
+ return null;
324
+ }
301
325
  }
302
326
 
303
327
  /** The JSONL rows after `cursor` (a row count), as records, plus the new cursor. A torn last row
@@ -259,12 +259,19 @@ function handleUnlock(cfg: Config, fields: Record<string, string>, login: string
259
259
  if (minutes !== "" && !/^\d+$/.test(minutes)) return textRes("minutes must be a number", 400);
260
260
  const result = chatUnlock(minutes === "" ? "unlock" : `unlock ${minutes}`, cfg, `ui:${login}`, "ui");
261
261
  if (!result.applied) return textRes("unlock refused: guards.chat_unlock is off", 409);
262
+ mkdirSync(stateDirPath(), { recursive: true });
263
+ appendFileSync(
264
+ inboxPath(),
265
+ `${JSON.stringify({ ts: nowSec(), kind: "unlock", minutes: result.minutes, until: result.until, login })}\n`,
266
+ );
262
267
  return redirect();
263
268
  }
264
269
 
265
270
  function handleLock(cfg: Config, login: string): Response {
266
271
  const result = chatUnlock("lock", cfg, `ui:${login}`, "ui");
267
272
  if (!result.applied) return textRes("lock refused: guards.chat_unlock is off", 409);
273
+ mkdirSync(stateDirPath(), { recursive: true });
274
+ appendFileSync(inboxPath(), `${JSON.stringify({ ts: nowSec(), kind: "lock", login })}\n`);
268
275
  return redirect();
269
276
  }
270
277
 
@@ -621,6 +621,8 @@ export interface ChatUnlockResult {
621
621
  command?: "unlock" | "lock";
622
622
  /** For an unlock: the minutes the existing mtime window stays open (for the owner notice). */
623
623
  minutes?: number;
624
+ /** For an unlock: epoch seconds when the guard window closes (mtime + unlock_minutes). */
625
+ until?: number;
624
626
  }
625
627
 
626
628
  const CHAT_CMD = /^(unlock|lock)(?:\s+(\d+))?$/i;
@@ -657,7 +659,7 @@ export function chatUnlock(text: string, cfg: Config, source: string, word: "cha
657
659
  try {
658
660
  appendFileSync(cfg.paths.plan_guard_log, `${new Date().toISOString()} UNLOCK ${word} source=${source} minutes=${n}\n`);
659
661
  } catch {}
660
- return { applied: true, command: "unlock", minutes: n };
662
+ return { applied: true, command: "unlock", minutes: n, until: Math.floor(past + minutes * 60) };
661
663
  }
662
664
 
663
665
  export function protectedHit(paths: string[]): string | null {