neurastream 0.1.21 → 0.1.22
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 +1 -1
- package/bin/queue-trim +6 -0
- package/package.json +2 -1
- package/src/adapters/omp/index.ts +18 -3
- package/src/cli/commands.ts +4 -0
- package/src/cli/dispatch.ts +1 -0
- package/src/core/config.ts +1 -0
- package/src/core/guards.ts +26 -3
- package/src/core/metrics.ts +4 -1
- package/src/core/queue/lib.ts +52 -1
- package/src/core/queue-trim.ts +41 -0
- package/src/core/rollover.ts +23 -4
- package/templates/config.yml +1 -0
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ Check the merged result:
|
|
|
58
58
|
neurastream config --json
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
-
Every tool is one program, selected by the name it was called with: `agent-score`, `agent-ledger`, `brief-lint`, `oc-run`, `wip-check`, `wip-backup`, `wip-snapshot`, `pm-fail-facts`, `main-health`, `queue-check`, `queue-close`, `queue-cancel`, `main-start`, `machine-guard`, `glm-reset`, `priority-watch`, `resource-alerts`, `tmp-snapshot`, `heavy-run`.
|
|
61
|
+
Every tool is one program, selected by the name it was called with: `agent-score`, `agent-ledger`, `brief-lint`, `oc-run`, `wip-check`, `wip-backup`, `wip-snapshot`, `pm-fail-facts`, `main-health`, `queue-check`, `queue-close`, `queue-cancel`, `queue-trim`, `main-start`, `machine-guard`, `glm-reset`, `priority-watch`, `resource-alerts`, `tmp-snapshot`, `heavy-run`.
|
|
62
62
|
|
|
63
63
|
## Develop
|
|
64
64
|
|
package/bin/queue-trim
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "neurastream",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.22",
|
|
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",
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"pm-fail-facts": "bin/pm-fail-facts",
|
|
38
38
|
"main-health": "bin/main-health",
|
|
39
39
|
"queue-check": "bin/queue-check",
|
|
40
|
+
"queue-trim": "bin/queue-trim",
|
|
40
41
|
"queue-close": "bin/queue-close",
|
|
41
42
|
"queue-cancel": "bin/queue-cancel",
|
|
42
43
|
"main-start": "bin/main-start",
|
|
@@ -23,11 +23,11 @@ import type { Decision } from "../../core/adapter.ts";
|
|
|
23
23
|
import { loadConfig, type Config } from "../../core/config.ts";
|
|
24
24
|
import { nowSec } from "../../core/clock.ts";
|
|
25
25
|
import { runDetectorsGated } from "../../core/incident-detectors.ts";
|
|
26
|
-
import { checkInject, checkPlanEdit, checkStop, checkTool, MAIN_PLAN_FILE, recordMainResult } from "../../core/guards.ts";
|
|
26
|
+
import { checkInject, checkPlanEdit, checkStop, checkTool, MAIN_PLAN_FILE, recordMainResult, rekeySpawnFile } from "../../core/guards.ts";
|
|
27
27
|
import { applyQueueEnv } from "../../core/queue/env.ts";
|
|
28
28
|
import { mainStartText, runDailyCheck } from "../../core/main-start.ts";
|
|
29
29
|
import { readBlocks } from "../../core/metrics.ts";
|
|
30
|
-
import { buildHandoff, holdsBlock, notePath, noteRequest, relaunchPath, rolloverState, spawnRefusal, type RolloverState } from "../../core/rollover.ts";
|
|
30
|
+
import { buildHandoff, holdsBlock, notePath, noteRequest, ownerText, relaunchPath, rolloverState, spawnRefusal, type RolloverState } from "../../core/rollover.ts";
|
|
31
31
|
import { defaultCompletedResults, defaultRunSource } from "./sessions.ts";
|
|
32
32
|
import * as q from "../../core/queue/lib.ts";
|
|
33
33
|
// Registers the plugin-command matcher into core's writeTargets (side effect).
|
|
@@ -306,7 +306,8 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
306
306
|
// A turn the harness starts from the guard's own stop continuation is not an owner
|
|
307
307
|
// message: D4 (owner-correction) only sees real prompts; D1/D3 run either way.
|
|
308
308
|
const prompt = asString(asRecord(event).prompt);
|
|
309
|
-
|
|
309
|
+
// Machine prompts (guard continuation, rollover note request, handoff note) are not owner messages.
|
|
310
|
+
mainDetectors(cfg, { prompt: ownerText(prompt) });
|
|
310
311
|
return {
|
|
311
312
|
message: {
|
|
312
313
|
customType: "main-guard.queue",
|
|
@@ -368,12 +369,21 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
368
369
|
return Object.keys(out).length > 0 ? out : undefined;
|
|
369
370
|
});
|
|
370
371
|
|
|
372
|
+
// Main ticked a phase: keep the newest Progress entries in the plan and move older ones to its archive.
|
|
373
|
+
const trimProgress = (file: string): string | undefined => {
|
|
374
|
+
const t = q.trimPlanProgress(file, cfg.queue.progress_keep);
|
|
375
|
+
if (!t) return undefined;
|
|
376
|
+
rekeySpawnFile(file, t.before, t.after);
|
|
377
|
+
return `plan-guard: moved ${t.count} older Progress entries to ${t.archive}; re-read the plan before editing it again.`;
|
|
378
|
+
};
|
|
379
|
+
|
|
371
380
|
pi.on("tool_result", (event, ctx) => {
|
|
372
381
|
onSizeCheck(event, ctx);
|
|
373
382
|
const e = asRecord(event);
|
|
374
383
|
const c = asCtx(ctx);
|
|
375
384
|
const id = asString(e.toolCallId);
|
|
376
385
|
const snap = pending.get(id);
|
|
386
|
+
const notes: string[] = [];
|
|
377
387
|
if (snap) {
|
|
378
388
|
pending.delete(id);
|
|
379
389
|
for (const [file, before] of snap) {
|
|
@@ -389,6 +399,10 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
389
399
|
} catch {}
|
|
390
400
|
return { isError: true, content: [{ type: "text", text: d.reason }] };
|
|
391
401
|
}
|
|
402
|
+
if (d.allow && (!c.hasAgent || c.kind === "main") && q.doneCount(after) > q.doneCount(before) && q.planAt(file, q.activePlans())) {
|
|
403
|
+
const note = trimProgress(file);
|
|
404
|
+
if (note) notes.push(note);
|
|
405
|
+
}
|
|
392
406
|
}
|
|
393
407
|
}
|
|
394
408
|
if ((!c.hasAgent || c.kind === "main") && asString(e.toolName) === "bash" && !e.isError) {
|
|
@@ -406,6 +420,7 @@ export function createOmpAdapter(pi: ExtensionHost, cfg: Config): void {
|
|
|
406
420
|
bash: { command: asString(asRecord(e.input).command), output: content.map(p => asString(asRecord(p).text)).join("\n") },
|
|
407
421
|
});
|
|
408
422
|
}
|
|
423
|
+
if (notes.length) return { content: [...(Array.isArray(e.content) ? e.content : []), ...notes.map(text => ({ type: "text", text }))] };
|
|
409
424
|
return undefined;
|
|
410
425
|
});
|
|
411
426
|
|
package/src/cli/commands.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { pmFailFacts } from "../core/pm-fail-facts.ts";
|
|
|
11
11
|
import { priorityWatch } from "../core/priority-watch.ts";
|
|
12
12
|
import { queueCancel } from "../core/queue-cancel.ts";
|
|
13
13
|
import { queueCheck } from "../core/queue-check.ts";
|
|
14
|
+
import { queueTrim } from "../core/queue-trim.ts";
|
|
14
15
|
import { queueClose } from "../core/queue-close.ts";
|
|
15
16
|
import { resourceAlerts } from "../core/resource-alerts.ts";
|
|
16
17
|
import { tmpSnapshot } from "../core/tmp-snapshot.ts";
|
|
@@ -32,6 +33,7 @@ export const PORTED = [
|
|
|
32
33
|
"pm-fail-facts",
|
|
33
34
|
"main-health",
|
|
34
35
|
"queue-check",
|
|
36
|
+
"queue-trim",
|
|
35
37
|
"queue-close",
|
|
36
38
|
"queue-cancel",
|
|
37
39
|
"main-start",
|
|
@@ -70,6 +72,8 @@ export async function runPorted(cmd: string, args: string[]): Promise<number> {
|
|
|
70
72
|
return mainHealth(args, rt.cfg, rt.source);
|
|
71
73
|
case "queue-check":
|
|
72
74
|
return queueCheck(args, rt.cfg);
|
|
75
|
+
case "queue-trim":
|
|
76
|
+
return queueTrim(args, rt.cfg);
|
|
73
77
|
case "queue-close":
|
|
74
78
|
return queueClose(args, rt.cfg);
|
|
75
79
|
case "queue-cancel":
|
package/src/cli/dispatch.ts
CHANGED
package/src/core/config.ts
CHANGED
package/src/core/guards.ts
CHANGED
|
@@ -106,6 +106,24 @@ export function recordSpawns(files: string[]): void {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/** Re-key a plan's spawn hash after its Progress body was trimmed. Only a hash that matched the old body moves. Pure. */
|
|
110
|
+
export function rekeySpawns(spawns: Record<string, string>, file: string, before: string, after: string): boolean {
|
|
111
|
+
if (spawns[file] !== q.sha(before)) return false;
|
|
112
|
+
spawns[file] = q.sha(after);
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Apply rekeySpawns to the stored spawn hashes. */
|
|
117
|
+
export function rekeySpawnFile(file: string, before: string, after: string): void {
|
|
118
|
+
const s = readSpawns();
|
|
119
|
+
if (!rekeySpawns(s, file, before, after)) return;
|
|
120
|
+
try {
|
|
121
|
+
writeFileSync(spawnsFile(), JSON.stringify(s, null, 1));
|
|
122
|
+
} catch (err) {
|
|
123
|
+
log(`${q.STATE_DIR}/../main-guard.log`, `cannot write ${spawnsFile()}: ${err}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
109
127
|
// --- shared pieces ---
|
|
110
128
|
|
|
111
129
|
function unlocked(cfg: Config): boolean {
|
|
@@ -592,7 +610,10 @@ export function checkPlanEdit(e: PlanEditEvent, cfg: Config): Decision {
|
|
|
592
610
|
// An empty `before` means the plan file did not exist yet; a refusal then deletes it.
|
|
593
611
|
function checkMainPlan(e: PlanEditEvent, cfg: Config): Decision {
|
|
594
612
|
if (q.outsideProgress(e.after) === q.outsideProgress(e.before)) return ALLOW;
|
|
595
|
-
|
|
613
|
+
// Refuse only what this edit adds: a problem the plan already had is not Main's doing now.
|
|
614
|
+
// The missing-section problem is always refused: a plan with no read list has no evidence behind its text.
|
|
615
|
+
const known = new Set(e.before ? planReadProblems(e.before, e.path, cfg) : []);
|
|
616
|
+
const problems = planReadProblems(e.after, e.path, cfg).filter(p => p === NO_SECTION || !known.has(p));
|
|
596
617
|
if (!problems.length) return ALLOW;
|
|
597
618
|
log(cfg.paths.plan_guard_log, `REFUSE-READ ${e.path}: ${problems.join("; ")}`);
|
|
598
619
|
return {
|
|
@@ -606,11 +627,13 @@ const READ_SECTION = /^## Code read by Main[^\n]*\n([\s\S]*?)(?=^## |(?![\s\S]))
|
|
|
606
627
|
const LISTED_PATH = /`([^`\s]+)`/g;
|
|
607
628
|
const CITED_PATH = /((?:~\/|\/|\.{1,2}\/)?[\w@.-]+(?:\/[\w@.-]+)*\.[A-Za-z0-9]+):\d+/g;
|
|
608
629
|
|
|
630
|
+
const NO_SECTION = `no "## Code read by Main" section lists a file (list each file you read for this plan as a backticked path)`;
|
|
631
|
+
|
|
609
632
|
/** Read evidence behind a plan edit: section present, each listed path read within the window, no unlisted cited path. */
|
|
610
633
|
function planReadProblems(text: string, planPath: string, cfg: Config): string[] {
|
|
611
634
|
const section = READ_SECTION.exec(text)?.[1] ?? "";
|
|
612
635
|
const listed = [...section.matchAll(LISTED_PATH)].map(m => (m[1] ?? "").replace(/:[\d,+\- ]+$/, ""));
|
|
613
|
-
if (!listed.length) return [
|
|
636
|
+
if (!listed.length) return [NO_SECTION];
|
|
614
637
|
const reads = readMainReads();
|
|
615
638
|
const maxMs = cfg.guards.plan_read_max_hours * 3_600_000;
|
|
616
639
|
const problems: string[] = [];
|
|
@@ -621,7 +644,7 @@ function planReadProblems(text: string, planPath: string, cfg: Config): string[]
|
|
|
621
644
|
if (!isFile(abs)) problems.push(`${p} does not exist`);
|
|
622
645
|
else if (!(Date.parse(reads[abs] ?? "") >= Date.now() - maxMs)) problems.push(`${p} was not read by Main within ${cfg.guards.plan_read_max_hours} h`);
|
|
623
646
|
}
|
|
624
|
-
for (const [, cited = ""] of text.matchAll(CITED_PATH)) {
|
|
647
|
+
for (const [, cited = ""] of q.outsideProgress(text).matchAll(CITED_PATH)) {
|
|
625
648
|
const abs = planFile(cited, planPath, text);
|
|
626
649
|
if (abs.includes("/docs/plans/") || named.has(abs) || !isFile(abs)) continue;
|
|
627
650
|
problems.push(`${cited} is cited but not listed under "## Code read by Main"`);
|
package/src/core/metrics.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { join } from "node:path";
|
|
|
8
8
|
import type { Config } from "./config.ts";
|
|
9
9
|
import type { Run, RunSource } from "./adapter.ts";
|
|
10
10
|
import { readEvents } from "./agent-score.ts";
|
|
11
|
+
import { ownerText } from "./rollover.ts";
|
|
11
12
|
|
|
12
13
|
export type Ev = Record<string, unknown>;
|
|
13
14
|
|
|
@@ -199,7 +200,9 @@ export function m4(runs: Run[], w: Window, patterns: RegExp[]): M4 {
|
|
|
199
200
|
const text = blocks(m.text)
|
|
200
201
|
.map((b) => b.text)
|
|
201
202
|
.join("\n");
|
|
202
|
-
|
|
203
|
+
// Machine-written messages (rollover note request, handoff note text) are not owner corrections.
|
|
204
|
+
const own = ownerText(text);
|
|
205
|
+
if (own !== undefined && patterns.some((p) => p.test(own))) out.corrections++;
|
|
203
206
|
} else if (m.role === "assistant") {
|
|
204
207
|
const last = blocks(m.text)
|
|
205
208
|
.filter((b) => b.type === "text")
|
package/src/core/queue/lib.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Queue model: main index, repo INDEX.md, plan shape (templates/queue/TEMPLATE.md).
|
|
2
2
|
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
|
-
import { accessSync, constants, existsSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
4
|
+
import { accessSync, constants, existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
5
5
|
import os from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
|
|
@@ -108,6 +108,57 @@ export function progressBody(text: string): string {
|
|
|
108
108
|
return sections(text).get("progress") ?? "";
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
export type ProgressTrim = { body: string; moved: string; count: number };
|
|
112
|
+
|
|
113
|
+
// Entries start at a top-level "- " line. The pointer line that a trim leaves behind is not an entry,
|
|
114
|
+
// and Main-only lines (status, owner parking/cancel, cancelled-list clearance) never move to the archive.
|
|
115
|
+
const POINTER_PREFIX = "- Older Progress entries:";
|
|
116
|
+
const MAIN_ONLY_LINE = /^\s*(?:[-*]\s+)?(Status:|WAITING on owner:|Cancelled by owner:|False positive:)/;
|
|
117
|
+
|
|
118
|
+
/** Keep the first `keep` entries (the file lists them newest first) and move the rest. Pure. */
|
|
119
|
+
export function trimProgressBody(body: string, keep: number, pointer: string): ProgressTrim | undefined {
|
|
120
|
+
const lines = body.split("\n").filter(l => !l.startsWith(POINTER_PREFIX));
|
|
121
|
+
const starts = lines.flatMap((l, i) => (/^- /.test(l) && !MAIN_ONLY_LINE.test(l) ? [i] : []));
|
|
122
|
+
if (starts.length <= keep) return undefined;
|
|
123
|
+
const cut = starts[keep];
|
|
124
|
+
const tail = lines.slice(cut);
|
|
125
|
+
const pinned = tail.filter(l => MAIN_ONLY_LINE.test(l));
|
|
126
|
+
const moved = tail.filter(l => !MAIN_ONLY_LINE.test(l));
|
|
127
|
+
let end = moved.length;
|
|
128
|
+
while (end > 0 && moved[end - 1] === "") end--;
|
|
129
|
+
return {
|
|
130
|
+
body: [...lines.slice(0, cut), ...pinned, pointer, ...moved.slice(end)].join("\n"),
|
|
131
|
+
moved: moved.slice(0, end).join("\n"),
|
|
132
|
+
count: starts.length - keep,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Trim the `## Progress` body of a plan file in place and append the moved entries to its archive (newest batch on top). */
|
|
137
|
+
export function trimPlanProgress(planFile: string, keep: number): { count: number; archive: string; before: string; after: string } | undefined {
|
|
138
|
+
const text = readFileSync(planFile, "utf8");
|
|
139
|
+
const head = /^## Progress[^\n]*\n/m.exec(text);
|
|
140
|
+
if (!head) return undefined;
|
|
141
|
+
const start = head.index + head[0].length;
|
|
142
|
+
const next = text.slice(start).search(/^## /m);
|
|
143
|
+
const end = next === -1 ? text.length : start + next;
|
|
144
|
+
const before = text.slice(start, end);
|
|
145
|
+
const archiveName = `${path.basename(planFile, ".md")}-progress.md`;
|
|
146
|
+
const res = trimProgressBody(before, keep, `- Older Progress entries: archive/${archiveName}`);
|
|
147
|
+
if (!res) return undefined;
|
|
148
|
+
const dir = path.join(path.dirname(planFile), "archive");
|
|
149
|
+
const archive = path.join(dir, archiveName);
|
|
150
|
+
const older = (existsSync(archive) ? readFileSync(archive, "utf8") : "").replace(/^# Progress archive:[^\n]*\n?/, "").trim();
|
|
151
|
+
mkdirSync(dir, { recursive: true });
|
|
152
|
+
writeFileSync(archive, `# Progress archive: ${path.basename(planFile)}\n\n${res.moved.trim()}\n${older ? `\n${older}\n` : ""}`);
|
|
153
|
+
writeFileSync(planFile, text.slice(0, start) + res.body + text.slice(end));
|
|
154
|
+
return { count: res.count, archive, before, after: res.body };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Number of ticked phase lines ("- [x]") in a plan. */
|
|
158
|
+
export function doneCount(text: string): number {
|
|
159
|
+
return (text.match(/^\s*[-*] \[x\]/gm) ?? []).length;
|
|
160
|
+
}
|
|
161
|
+
|
|
111
162
|
export function statusOf(text: string): Plan["status"] {
|
|
112
163
|
const m = progressBody(text).match(/^Status:\s*(\S+)\s*$/m);
|
|
113
164
|
const st = m?.[1];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// queue-trim <plan> [--keep N]: keep the newest Progress entries of an indexed plan and move the
|
|
2
|
+
// older ones to its archive. The adapter runs the same trim after Main ticks a phase.
|
|
3
|
+
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { rekeySpawnFile } from "./guards.ts";
|
|
7
|
+
import type { Config } from "./config.ts";
|
|
8
|
+
import { applyQueueEnv } from "./queue/env.ts";
|
|
9
|
+
import * as q from "./queue/lib.ts";
|
|
10
|
+
|
|
11
|
+
const USAGE = "usage: queue-trim <plan file> [--keep N]";
|
|
12
|
+
|
|
13
|
+
export function queueTrim(args: string[], cfg: Config): number {
|
|
14
|
+
applyQueueEnv(cfg);
|
|
15
|
+
const hasKeep = args.includes("--keep");
|
|
16
|
+
const rest = args.filter((a, i) => a !== "--keep" && args[i - 1] !== "--keep");
|
|
17
|
+
const planArg = rest[0];
|
|
18
|
+
if (!planArg) {
|
|
19
|
+
console.error(USAGE);
|
|
20
|
+
return 2;
|
|
21
|
+
}
|
|
22
|
+
const keepArg = hasKeep ? args[args.indexOf("--keep") + 1] : undefined;
|
|
23
|
+
const keep = hasKeep ? Number(keepArg) : cfg.queue.progress_keep;
|
|
24
|
+
if (!Number.isInteger(keep) || keep < 0) {
|
|
25
|
+
console.error(`queue-trim: --keep takes a whole number, got ${keepArg ?? "nothing"}`);
|
|
26
|
+
return 2;
|
|
27
|
+
}
|
|
28
|
+
const file = path.resolve(planArg);
|
|
29
|
+
if (!existsSync(file) || !q.planAt(file, q.activePlans())) {
|
|
30
|
+
console.error(`queue-trim: ${file} is not an indexed plan`);
|
|
31
|
+
return 2;
|
|
32
|
+
}
|
|
33
|
+
const t = q.trimPlanProgress(file, keep);
|
|
34
|
+
if (!t) {
|
|
35
|
+
console.log(`queue-trim: ${file} has no more than ${keep} Progress entries; nothing moved`);
|
|
36
|
+
return 0;
|
|
37
|
+
}
|
|
38
|
+
rekeySpawnFile(file, t.before, t.after);
|
|
39
|
+
console.log(`queue-trim: moved ${t.count} older Progress entries of ${file} to ${t.archive}`);
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
package/src/core/rollover.ts
CHANGED
|
@@ -64,10 +64,15 @@ export interface HandoffInput {
|
|
|
64
64
|
ownerMessage: string;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/** Prefixes of the machine-written messages: the builders write them, ownerText reads them. */
|
|
68
|
+
const NOTE_REQUEST_PREFIX = "Session rollover:";
|
|
69
|
+
const HANDOFF_PREFIX = "Previous session file:";
|
|
70
|
+
const OWNER_MARK = "Owner's message:";
|
|
71
|
+
|
|
67
72
|
/** The first user message of the new session: header, Main's note, generated state, owner message. */
|
|
68
73
|
export function buildHandoff(p: HandoffInput): string {
|
|
69
74
|
return [
|
|
70
|
-
|
|
75
|
+
`${HANDOFF_PREFIX} ${p.previousSessionFile}. Its full history stays there; this session continues from the handoff below.`,
|
|
71
76
|
"",
|
|
72
77
|
"## Main's handoff note (verbatim)",
|
|
73
78
|
p.note.trimEnd(),
|
|
@@ -75,11 +80,25 @@ export function buildHandoff(p: HandoffInput): string {
|
|
|
75
80
|
"## Generated state (main-start)",
|
|
76
81
|
p.generated.trimEnd(),
|
|
77
82
|
"",
|
|
78
|
-
|
|
83
|
+
OWNER_MARK,
|
|
79
84
|
p.ownerMessage,
|
|
80
85
|
].join("\n");
|
|
81
86
|
}
|
|
82
87
|
|
|
88
|
+
/**
|
|
89
|
+
* The owner's own words in a user prompt, or undefined for a machine prompt: a guard continuation, the
|
|
90
|
+
* rollover note request, or a handoff without its owner marker. A handoff yields only its owner message.
|
|
91
|
+
*/
|
|
92
|
+
export function ownerText(prompt: string): string | undefined {
|
|
93
|
+
const t = prompt.trimStart();
|
|
94
|
+
if (t.startsWith("main-guard:") || t.startsWith(NOTE_REQUEST_PREFIX)) return undefined;
|
|
95
|
+
if (t.startsWith(HANDOFF_PREFIX)) {
|
|
96
|
+
const at = prompt.lastIndexOf(OWNER_MARK);
|
|
97
|
+
return at < 0 ? undefined : prompt.slice(at + OWNER_MARK.length).trim();
|
|
98
|
+
}
|
|
99
|
+
return prompt;
|
|
100
|
+
}
|
|
101
|
+
|
|
83
102
|
/** The owner-holds part of the generated state: each WAITING on owner line verbatim, or none. */
|
|
84
103
|
export function holdsBlock(holds: readonly string[]): string {
|
|
85
104
|
return ["=== owner holds (plans' WAITING on owner lines)", ...(holds.length > 0 ? holds : ["none"]), ""].join("\n");
|
|
@@ -89,8 +108,8 @@ export function holdsBlock(holds: readonly string[]): string {
|
|
|
89
108
|
export function noteRequest(path: string, auto = false, reason = ""): string {
|
|
90
109
|
return [
|
|
91
110
|
reason
|
|
92
|
-
?
|
|
93
|
-
:
|
|
111
|
+
? `${NOTE_REQUEST_PREFIX} a new neurastream version is installed (${reason}).`
|
|
112
|
+
: `${NOTE_REQUEST_PREFIX} this session has grown past rollover.max_session_mb.`,
|
|
94
113
|
`Write a handoff note to ${path} (overwrite it). Cover the work in progress and its state, the decisions made and why, the next step, and the files involved.`,
|
|
95
114
|
"Do not list holds or owner blockers in the note; they come from the plans' WAITING on owner lines.",
|
|
96
115
|
auto
|