neurastream 0.3.6 → 0.3.8

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.3.6",
3
+ "version": "0.3.8",
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",
@@ -41,6 +41,12 @@ export function newEntryId(atMs: number, rand: (n: number) => Uint8Array = rando
41
41
  return atMs.toString(36).padStart(9, "0") + Buffer.from(rand(4)).toString("hex");
42
42
  }
43
43
 
44
+ // The second an entry id was minted at; undefined for an id that is not in newEntryId's form.
45
+ export function entryIdSec(id: string): number | undefined {
46
+ if (!/^[0-9a-z]{9}[0-9a-f]{8}$/.test(id)) return undefined;
47
+ return Math.floor(Number.parseInt(id.slice(0, 9), 36) / 1000);
48
+ }
49
+
44
50
  // The one writer: the recall dir is 0700 and the file 0600, also when they pre-exist looser.
45
51
  export function appendJsonLines(file: string, rows: readonly object[]): void {
46
52
  const dir = dirname(file);
@@ -7,7 +7,7 @@ import { join } from "node:path";
7
7
  import { nowSec } from "./clock.ts";
8
8
  import type { Config } from "./config.ts";
9
9
  import { tryLock } from "./file-lock.ts";
10
- import { appendJsonLines, type LogEntry, ownerLogDir, ownerLogFile, readEntries, readLines } from "./owner-log.ts";
10
+ import { appendJsonLines, entryIdSec, type LogEntry, ownerLogDir, ownerLogFile, readEntries, readLines } from "./owner-log.ts";
11
11
  import { loadKnownSecrets, redactSecrets } from "./secret-redact.ts";
12
12
 
13
13
  export interface CompleteRequest {
@@ -143,7 +143,7 @@ function parseRow(line: string): TopicRow | undefined {
143
143
  if (v === null || typeof v !== "object" || typeof v.from !== "string" || typeof v.to !== "string") return undefined;
144
144
  if (typeof v.at !== "number") return undefined;
145
145
  if (v.skipped === true) {
146
- return { from: v.from, to: v.to, at: v.at, skipped: true, why: typeof v.why === "string" ? v.why : "" };
146
+ return { from: v.from, to: v.to, at: entryIdSec(v.from) ?? v.at, skipped: true, why: typeof v.why === "string" ? v.why : "" };
147
147
  }
148
148
  if (
149
149
  typeof v.title !== "string" ||
@@ -159,7 +159,7 @@ function parseRow(line: string): TopicRow | undefined {
159
159
  return {
160
160
  from: v.from,
161
161
  to: v.to,
162
- at: v.at,
162
+ at: entryIdSec(v.from) ?? v.at,
163
163
  open: v.open,
164
164
  title: v.title,
165
165
  keywords: v.keywords,
@@ -562,6 +562,8 @@ export async function runTopics(cfg: Config, complete: Complete, opts: { close:
562
562
  const rows = effectiveRows();
563
563
  const window = newEntries(afterClosed(rows)).slice(0, WINDOW);
564
564
  if (window.length === 0) return { lines: [statsLine(tally)], failures: 0 };
565
+ const last = rows.at(-1);
566
+ if (last !== undefined && isSegment(last) && last.open && window.at(-1)!.id === last.to) return { lines: [statsLine(tally)], failures: 0 };
565
567
  const failed = await segmentWindow(cfg, complete, window, rows, tally);
566
568
  const lines = failed
567
569
  ? [`topics: fail ${window[0]!.id}..${window.at(-1)!.id} ${failed.reason} in=${failed.in} out=${failed.out}`]