neurastream 0.3.5 → 0.3.7
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
|
@@ -276,6 +276,7 @@ export function autoClose(cfg: Config): string[] {
|
|
|
276
276
|
const [bin, args] = closeChildArgs(p.file, p.status === "open");
|
|
277
277
|
const child = spawn(bin, args, { detached: true, stdio: ["ignore", out, out], env: process.env });
|
|
278
278
|
child.unref();
|
|
279
|
+
closeSync(out);
|
|
279
280
|
started.push(p.file);
|
|
280
281
|
} catch (err) {
|
|
281
282
|
adapterLog(cfg, `auto-close: could not start for ${p.file}: ${err}`);
|
|
@@ -343,6 +343,7 @@ export async function ompComplete(req: CompleteRequest, opts: { spawn?: GatewayS
|
|
|
343
343
|
body: {
|
|
344
344
|
model: req.model,
|
|
345
345
|
max_tokens: req.maxTokens,
|
|
346
|
+
...(req.effort ? { reasoning_effort: req.effort } : {}),
|
|
346
347
|
messages: [
|
|
347
348
|
{ role: "system", content: req.system },
|
|
348
349
|
{ role: "user", content: req.prompt },
|
|
@@ -365,7 +366,10 @@ export async function ompComplete(req: CompleteRequest, opts: { spawn?: GatewayS
|
|
|
365
366
|
if (reply === undefined) throw gatewayError("no-reply", "no reply with id 1");
|
|
366
367
|
if (reply.status !== 200) throw gatewayError(`status-${reply.status}`, `status ${reply.status}`);
|
|
367
368
|
const choice = reply.body?.choices?.[0];
|
|
368
|
-
if (choice?.finish_reason !== "stop")
|
|
369
|
+
if (choice?.finish_reason !== "stop") {
|
|
370
|
+
const code = typeof choice?.finish_reason === "string" ? choice.finish_reason.slice(0, 20) : "none";
|
|
371
|
+
throw gatewayError(`finish-reason:${code}`, "reply did not finish with stop");
|
|
372
|
+
}
|
|
369
373
|
const calls = choice.message?.tool_calls;
|
|
370
374
|
if (Array.isArray(calls) && calls.length > 0) throw gatewayError("tool-calls", "reply asked for tool calls");
|
|
371
375
|
const text = choice.message?.content;
|
package/src/core/config.ts
CHANGED
|
@@ -283,8 +283,8 @@ export interface Config {
|
|
|
283
283
|
/** A second net on the wire: wrap the harness in `secretgate wrap --` at launch. */
|
|
284
284
|
proxy: "none" | "secretgate";
|
|
285
285
|
};
|
|
286
|
-
/** Owner topics (src/core/owner-topics.ts, plan P8): `topics_model` writes the owner-log topic index through the gateway ("" = off); a run starts every `topics_every` Main entries. */
|
|
287
|
-
recall: { topics_model: string; topics_every: number };
|
|
286
|
+
/** Owner topics (src/core/owner-topics.ts, plan P8): `topics_model` writes the owner-log topic index through the gateway ("" = off); `topics_effort` is the reasoning effort sent with each call ("" = none); a run starts every `topics_every` Main entries. */
|
|
287
|
+
recall: { topics_model: string; topics_effort: string; topics_every: number };
|
|
288
288
|
/** Write-time lint checks (src/core/write-check.ts, plan 20261028_1228): an edit that adds a lint finding or a suppression comment is refused. */
|
|
289
289
|
write_check: WriteCheckConfig;
|
|
290
290
|
priority: { sleep_sec: number };
|
|
@@ -805,6 +805,7 @@ function check(cfg: Config): void {
|
|
|
805
805
|
}
|
|
806
806
|
}
|
|
807
807
|
if (typeof cfg.recall.topics_model !== "string") throw new ConfigError('recall.topics_model must be a string ("" = off)');
|
|
808
|
+
if (typeof cfg.recall.topics_effort !== "string") throw new ConfigError('recall.topics_effort must be a string ("" = none)');
|
|
808
809
|
if (!Number.isInteger(cfg.recall.topics_every) || cfg.recall.topics_every < 1) throw new ConfigError("recall.topics_every must be an integer >= 1");
|
|
809
810
|
for (const [key, value] of Object.entries(cfg.paths)) {
|
|
810
811
|
if (key === "work_roots") {
|
package/src/core/owner-topics.ts
CHANGED
|
@@ -15,6 +15,8 @@ export interface CompleteRequest {
|
|
|
15
15
|
system: string;
|
|
16
16
|
prompt: string;
|
|
17
17
|
maxTokens: number;
|
|
18
|
+
/** Reasoning effort for the model ("" or absent = none). */
|
|
19
|
+
effort?: string;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export interface CompleteResult {
|
|
@@ -84,20 +86,20 @@ type Attempt =
|
|
|
84
86
|
const TOPICS_FILE = "owner-topics.jsonl";
|
|
85
87
|
const TOPICS_LOG_FILE = "owner-topics.log";
|
|
86
88
|
const LOCK_FILE = "owner-topics.lock";
|
|
87
|
-
const WINDOW =
|
|
88
|
-
const MAX_TOKENS =
|
|
89
|
+
const WINDOW = 60;
|
|
90
|
+
const MAX_TOKENS = 16000;
|
|
89
91
|
|
|
90
92
|
const SYSTEM = [
|
|
91
93
|
"You split a chronological log of an owner's messages and the assistant's replies into topic segments.",
|
|
92
|
-
"Answer with one JSON object and nothing else:",
|
|
93
|
-
'{"segments":[{"from":"<entry
|
|
94
|
+
"Answer with one JSON object and nothing else. Entries are numbered [1], [2], ...; every id below is an entry number as a string:",
|
|
95
|
+
'{"segments":[{"from":"<entry number>","to":"<entry number>","title":"...","keywords":["..."],"decisions":[{"id":"<entry number>","text":"..."}],"questions":[{"id":"<owner entry number>","text":"..."}],"names":["..."],"continues":null}]}',
|
|
94
96
|
"Rules:",
|
|
95
97
|
"- The segments cover the log in order with no gaps and no overlaps; the last one ends at the last entry.",
|
|
96
|
-
"- from and to are entry
|
|
98
|
+
"- from and to are entry numbers from the log. A segment that is not the last has 3 to 60 entries.",
|
|
97
99
|
"- title: at most 10 words. keywords: at most 6 words each. decision text: at most 60 words, and its id is an entry in the segment.",
|
|
98
100
|
"- questions: the owner's open questions, each with the id of an owner entry in the segment.",
|
|
99
101
|
"- Write in your own words. Never copy 8 or more words in a row from the log.",
|
|
100
|
-
"- continues:
|
|
102
|
+
"- continues: always null.",
|
|
101
103
|
].join("\n");
|
|
102
104
|
|
|
103
105
|
export function topicsFile(): string {
|
|
@@ -313,10 +315,50 @@ function parseAnswer(text: string, window: readonly LogEntry[], earlier: readonl
|
|
|
313
315
|
} catch {
|
|
314
316
|
return { reason: "bad-json" };
|
|
315
317
|
}
|
|
316
|
-
const
|
|
317
|
-
if (
|
|
318
|
-
|
|
319
|
-
|
|
318
|
+
const shaped = shape(value);
|
|
319
|
+
if (shaped === undefined) return { reason: "check:shape" };
|
|
320
|
+
// The model sees entry numbers; a number the window has becomes its stored id, anything else is checked as is.
|
|
321
|
+
const idOf = (label: string): string => (/^[1-9]\d*$/.test(label) ? (window[Number(label) - 1]?.id ?? label) : label);
|
|
322
|
+
const segments = shaped.map(s => ({
|
|
323
|
+
...s,
|
|
324
|
+
from: idOf(s.from),
|
|
325
|
+
to: idOf(s.to),
|
|
326
|
+
decisions: s.decisions.map(d => ({ ...d, id: idOf(d.id) })),
|
|
327
|
+
questions: s.questions.map(q => ({ ...q, id: idOf(q.id) })),
|
|
328
|
+
}));
|
|
329
|
+
// The model cuts short greeting stretches that the 3-entry rule forbids: a short non-last segment folds into the next.
|
|
330
|
+
const pos = new Map(window.map((e, i) => [e.id, i]));
|
|
331
|
+
const folded: AnswerSegment[] = [];
|
|
332
|
+
let carry: AnswerSegment | undefined;
|
|
333
|
+
for (const [i, s] of segments.entries()) {
|
|
334
|
+
const cur = carry
|
|
335
|
+
? {
|
|
336
|
+
...s,
|
|
337
|
+
from: carry.from,
|
|
338
|
+
keywords: [...carry.keywords, ...s.keywords],
|
|
339
|
+
decisions: [...carry.decisions, ...s.decisions],
|
|
340
|
+
questions: [...carry.questions, ...s.questions],
|
|
341
|
+
names: [...carry.names, ...s.names],
|
|
342
|
+
}
|
|
343
|
+
: s;
|
|
344
|
+
const a = pos.get(cur.from);
|
|
345
|
+
const b = pos.get(cur.to);
|
|
346
|
+
carry = i < segments.length - 1 && a !== undefined && b !== undefined && b >= a && b - a + 1 < 3 ? cur : undefined;
|
|
347
|
+
if (carry === undefined) folded.push(cur);
|
|
348
|
+
}
|
|
349
|
+
// A note whose id points outside its segment (or a question not on an owner entry) is dropped, not the window.
|
|
350
|
+
const clean = folded.map(s => {
|
|
351
|
+
const a = pos.get(s.from) ?? -1;
|
|
352
|
+
const b = pos.get(s.to) ?? -1;
|
|
353
|
+
const inside = (id: string): boolean => (pos.get(id) ?? -1) >= a && (pos.get(id) ?? -1) <= b && pos.has(id);
|
|
354
|
+
return {
|
|
355
|
+
...s,
|
|
356
|
+
decisions: s.decisions.filter(d => inside(d.id)),
|
|
357
|
+
questions: s.questions.filter(q => inside(q.id) && window[pos.get(q.id)!]!.role === "owner"),
|
|
358
|
+
};
|
|
359
|
+
});
|
|
360
|
+
const err = checkSegments(clean, window, earlier);
|
|
361
|
+
return err === null ? { segments: clean } : { reason: `check:${err.slice(0, err.indexOf(":"))}` };
|
|
320
362
|
}
|
|
321
363
|
|
|
322
364
|
// A model error keeps its reason code; a timeout is named TimeoutError by the caller's spawn.
|
|
@@ -327,7 +369,7 @@ function failureReason(err: unknown): string {
|
|
|
327
369
|
}
|
|
328
370
|
|
|
329
371
|
function windowPrompt(window: readonly LogEntry[]): string {
|
|
330
|
-
return ["Log entries, oldest first:", ...window.map(e => `[${
|
|
372
|
+
return ["Log entries, oldest first:", ...window.map((e, i) => `[${i + 1}] (${e.role}) ${e.text}`)].join("\n");
|
|
331
373
|
}
|
|
332
374
|
|
|
333
375
|
// Redacts the model's text before it is written: the configured known secrets and extra patterns.
|
|
@@ -362,7 +404,13 @@ async function attemptOnce(
|
|
|
362
404
|
tally.calls++;
|
|
363
405
|
let answer: CompleteResult;
|
|
364
406
|
try {
|
|
365
|
-
answer = await complete({
|
|
407
|
+
answer = await complete({
|
|
408
|
+
model: cfg.recall.topics_model,
|
|
409
|
+
system: SYSTEM,
|
|
410
|
+
prompt: request,
|
|
411
|
+
maxTokens: MAX_TOKENS,
|
|
412
|
+
effort: cfg.recall.topics_effort,
|
|
413
|
+
});
|
|
366
414
|
} catch (err) {
|
|
367
415
|
return { kind: "error", reason: failureReason(err), in: Buffer.byteLength(request) };
|
|
368
416
|
}
|
|
@@ -503,6 +551,7 @@ export async function runTopics(cfg: Config, complete: Complete, opts: { close:
|
|
|
503
551
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
504
552
|
chmodSync(dir, 0o700);
|
|
505
553
|
const lock = tryLock(join(dir, LOCK_FILE));
|
|
554
|
+
chmodSync(join(dir, LOCK_FILE), 0o600);
|
|
506
555
|
if (lock === null) return { lines: ["topics: another run holds the lock"], failures: 0 };
|
|
507
556
|
try {
|
|
508
557
|
const tally: Tally = { calls: 0, tokensIn: 0, tokensOut: 0 };
|
|
@@ -513,6 +562,8 @@ export async function runTopics(cfg: Config, complete: Complete, opts: { close:
|
|
|
513
562
|
const rows = effectiveRows();
|
|
514
563
|
const window = newEntries(afterClosed(rows)).slice(0, WINDOW);
|
|
515
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 };
|
|
516
567
|
const failed = await segmentWindow(cfg, complete, window, rows, tally);
|
|
517
568
|
const lines = failed
|
|
518
569
|
? [`topics: fail ${window[0]!.id}..${window.at(-1)!.id} ${failed.reason} in=${failed.in} out=${failed.out}`]
|
package/templates/config.yml
CHANGED
|
@@ -270,6 +270,7 @@ secrets: # content redaction (src/core/secret-redact.ts); a
|
|
|
270
270
|
|
|
271
271
|
recall: # owner topics (src/core/owner-topics.ts, plan P8): a topic index over the owner log
|
|
272
272
|
topics_model: "" # gateway model that writes the topics; "" = off, e.g. "anthropic/claude-haiku-5-5"
|
|
273
|
+
topics_effort: "xhigh" # reasoning effort sent with each topics call (reasoning_effort); "" = none; the gateway ignores it for a model without thinking
|
|
273
274
|
topics_every: 30 # Main owner-log entries between background topic runs; provisional until measured on the backfill
|
|
274
275
|
|
|
275
276
|
write_check: # write-time lint checks (src/core/write-check.ts): an edit that adds a lint finding or suppression comment is undone and the agent is told why
|