neurastream 0.2.73 → 0.2.75
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 +1 -1
- package/src/core/main-start.ts +12 -0
- package/src/core/wip-backup.ts +9 -4
- package/src/core/wip-roots.ts +19 -2
- package/src/core/wip-snapshot.ts +15 -6
- package/templates/AGENTS.md +11 -0
package/package.json
CHANGED
package/src/core/main-start.ts
CHANGED
|
@@ -152,6 +152,7 @@ export async function mainStartText(args: string[], cfg: Config, opts: { inherit
|
|
|
152
152
|
const mgLines = mg.stdout.trim().split("\n");
|
|
153
153
|
say(mgLines.at(-1) ?? "");
|
|
154
154
|
say(loadavgLine());
|
|
155
|
+
say(terminalLine(process.env));
|
|
155
156
|
say("");
|
|
156
157
|
say(`=== agents (last ${h}h; DIED = check its worktree, relaunch FRESH with its progress file)`);
|
|
157
158
|
const ledger = await run(bin("agent-ledger", cfg), ["--hours", h], { stderr: "ignore" });
|
|
@@ -209,6 +210,17 @@ export async function mainStart(args: string[], cfg: Config, deps: MainStartDeps
|
|
|
209
210
|
return 0;
|
|
210
211
|
}
|
|
211
212
|
|
|
213
|
+
// The terminal the session runs in, from the environment alone (TERM is "dumb" under a harness, so it is not used).
|
|
214
|
+
// What the terminal can do (images, links) is not claimed: only its name is.
|
|
215
|
+
export function terminalLine(env: NodeJS.ProcessEnv): string {
|
|
216
|
+
const prog = env.TERM_PROGRAM
|
|
217
|
+
? `${env.TERM_PROGRAM}${env.TERM_PROGRAM_VERSION ? ` ${env.TERM_PROGRAM_VERSION}` : ""}`
|
|
218
|
+
: env.KITTY_WINDOW_ID ? "kitty"
|
|
219
|
+
: env.ALACRITTY_WINDOW_ID || env.ALACRITTY_SOCKET ? "alacritty"
|
|
220
|
+
: env.WT_SESSION ? "windows-terminal" : "unknown";
|
|
221
|
+
return `terminal: ${prog}${env.XDG_SESSION_TYPE ? `, ${env.XDG_SESSION_TYPE}` : ""}`;
|
|
222
|
+
}
|
|
223
|
+
|
|
212
224
|
// Due line for the weekly self-metrics report; null when notes/metrics.md is fresh.
|
|
213
225
|
export function metricsDueLine(cfg: Config, nowMs: number): string | null {
|
|
214
226
|
const reportFile = join(cfg.paths.notes, "metrics.md");
|
package/src/core/wip-backup.ts
CHANGED
|
@@ -92,12 +92,17 @@ export function wipBackup(
|
|
|
92
92
|
const mainWt = top.stdout ? top.stdout.split("\n")[0]!.slice(9) : repo;
|
|
93
93
|
const rkey = keyOf(mainWt, cfg.paths.home);
|
|
94
94
|
const specs: { src: string; dst: string }[] = [];
|
|
95
|
-
const heads = gitOrFail(failed, repo, ["for-each-ref", "--format=%(refname
|
|
95
|
+
const heads = gitOrFail(failed, repo, ["for-each-ref", "--format=%(refname)", "refs/heads"]);
|
|
96
96
|
if (!heads) continue;
|
|
97
|
-
for (const
|
|
98
|
-
|
|
97
|
+
for (const ref of heads.stdout.split("\n").filter(Boolean)) {
|
|
98
|
+
// Full refname and a trailing `--`: a branch named like an existing file (ops/x) is not
|
|
99
|
+
// "ambiguous argument" — that failure must not drop the branch from the backup.
|
|
100
|
+
const n = gitOrFail(failed, repo, ["rev-list", "--count", ref, "--not", "--remotes", "--"]);
|
|
99
101
|
if (!n) continue;
|
|
100
|
-
if (/^\d+$/.test(n.stdout) && Number(n.stdout) > 0)
|
|
102
|
+
if (/^\d+$/.test(n.stdout) && Number(n.stdout) > 0) {
|
|
103
|
+
const branch = ref.slice("refs/heads/".length);
|
|
104
|
+
specs.push({ src: ref, dst: `refs/heads/${rkey}/${branch}` });
|
|
105
|
+
}
|
|
101
106
|
}
|
|
102
107
|
const wips = gitOrFail(failed, repo, ["for-each-ref", "--sort=-refname", "--format=%(refname)", "refs/wip"]);
|
|
103
108
|
if (!wips) continue;
|
package/src/core/wip-roots.ts
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import { existsSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
2
|
-
import { join, relative } from "node:path";
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { join, relative, resolve } from "node:path";
|
|
3
3
|
import type { Config } from "./config.ts";
|
|
4
4
|
|
|
5
|
+
/** True when `dir/.git` is a file naming a gitdir that no longer exists: no repo is left to save. */
|
|
6
|
+
export function deadGitfile(dir: string): boolean {
|
|
7
|
+
const gitPath = join(dir, ".git");
|
|
8
|
+
let first: string | undefined;
|
|
9
|
+
try {
|
|
10
|
+
if (!statSync(gitPath).isFile()) return false;
|
|
11
|
+
first = readFileSync(gitPath, "utf8").split("\n")[0];
|
|
12
|
+
} catch {
|
|
13
|
+
return false; // an unreadable .git file is not our call: the repo stays and its failure is real
|
|
14
|
+
}
|
|
15
|
+
if (!first?.startsWith("gitdir: ")) return false;
|
|
16
|
+
return !existsSync(resolve(dir, first.slice("gitdir: ".length).trim()));
|
|
17
|
+
}
|
|
18
|
+
|
|
5
19
|
export function keyOf(path: string, home: string): string {
|
|
6
20
|
const realHome = existsSync(home) ? realpathSync(home) : home;
|
|
7
21
|
const realPath = existsSync(path) ? realpathSync(path) : path;
|
|
@@ -27,6 +41,8 @@ function walkFolder(dir: string, currentDepth: number, maxDepth: number, out: st
|
|
|
27
41
|
}
|
|
28
42
|
if (!st.isDirectory()) continue;
|
|
29
43
|
|
|
44
|
+
// A dead worktree dir has no repo left to save: not pushed as a repo, not recursed into.
|
|
45
|
+
if (deadGitfile(fullPath)) continue;
|
|
30
46
|
if (existsSync(join(fullPath, ".git"))) {
|
|
31
47
|
out.push(fullPath);
|
|
32
48
|
} else {
|
|
@@ -48,6 +64,7 @@ export function wipRepos(cfg: Config): string[] {
|
|
|
48
64
|
}
|
|
49
65
|
if (!st.isDirectory()) continue;
|
|
50
66
|
|
|
67
|
+
if (deadGitfile(root)) continue;
|
|
51
68
|
if (existsSync(join(root, ".git"))) {
|
|
52
69
|
out.push(root);
|
|
53
70
|
} else {
|
package/src/core/wip-snapshot.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Config } from "./config.ts";
|
|
|
5
5
|
import { nowSec, strftime } from "./clock.ts";
|
|
6
6
|
import { printText } from "./help.ts";
|
|
7
7
|
import { pyFloatStr } from "./pyfmt.ts";
|
|
8
|
-
import { cmd } from "./proc.ts";
|
|
8
|
+
import { cmd, gitRaw } from "./proc.ts";
|
|
9
9
|
import { failureLine, gitOrFail, realpathOrFail, recordWipRun } from "./wip-fail.ts";
|
|
10
10
|
import { keyOf, wipRepos } from "./wip-roots.ts";
|
|
11
11
|
|
|
@@ -102,9 +102,14 @@ export function wipSnapshot(args: string[], cfg: Config): number {
|
|
|
102
102
|
seen.set(common, repo);
|
|
103
103
|
const list = gitOrFail(failed, repo, ["worktree", "list", "--porcelain"]);
|
|
104
104
|
if (!list) continue;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
// Blocks (blank-line separated) match `worktree list --porcelain`; the bare entry of a
|
|
106
|
+
// bare main repo carries a `bare` line and is no worktree to snapshot.
|
|
107
|
+
for (const block of list.stdout.split("\n\n")) {
|
|
108
|
+
if (block.split("\n").some(line => line === "bare")) continue;
|
|
109
|
+
for (const line of block.split("\n")) {
|
|
110
|
+
if (line.startsWith("worktree ") && existsSync(line.slice(9)) && statSync(line.slice(9)).isDirectory()) {
|
|
111
|
+
worktrees.push(line.slice(9));
|
|
112
|
+
}
|
|
108
113
|
}
|
|
109
114
|
}
|
|
110
115
|
}
|
|
@@ -112,8 +117,12 @@ export function wipSnapshot(args: string[], cfg: Config): number {
|
|
|
112
117
|
const saved: { wt: string; br: string; n: number; sk: number; ref: string }[] = [];
|
|
113
118
|
let same = 0;
|
|
114
119
|
for (const wt of worktrees) {
|
|
115
|
-
|
|
116
|
-
|
|
120
|
+
// Unborn HEAD (no commit yet): nothing to save, skipped quietly. Any other git failure is real.
|
|
121
|
+
const head = gitRaw(wt, ["rev-parse", "--verify", "-q", "HEAD"]);
|
|
122
|
+
if (head.code !== 0) {
|
|
123
|
+
if (!(head.code === 1 && head.stderr === "")) failed.push(failureLine(wt, "git rev-parse --verify HEAD", head.stderr));
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
117
126
|
const st = gitOrFail(failed, wt, ["status", "--porcelain"]);
|
|
118
127
|
if (!st || !st.stdout) continue;
|
|
119
128
|
const gitdir = gitOrFail(failed, wt, ["rev-parse", "--absolute-git-dir"]);
|
package/templates/AGENTS.md
CHANGED
|
@@ -35,6 +35,17 @@ You are Main, the orchestrator. Main plans, delegates, reviews and lands; implem
|
|
|
35
35
|
|`neurastream incident list --open`|session start, before status reports, when a spawn or stop is blocked|
|
|
36
36
|
|`machine-guard`, `heavy-run`|machine-guard at session start and before launches; every test run goes through heavy-run|
|
|
37
37
|
|
|
38
|
+
## Call formats (the guards refuse anything else)
|
|
39
|
+
|Call|Exact form|
|
|
40
|
+
|---|---|
|
|
41
|
+
|Planner spawn|the task's first line is `Planner role for <absolute plan path>.md` and nothing else on that line|
|
|
42
|
+
|Spawn while an incident is open|refused: first `neurastream incident dismiss <id> --why "<text>"` (or `incident plan <id> <plan.md>`)|
|
|
43
|
+
|Owner message flagged as a cancel|`queue-cancel --not-a-cancel "<why>"`; a real cancel is `queue-cancel <plan> "<owner words>"` or `queue-cancel --never "<what>" "<owner words>" --repo <repo>`|
|
|
44
|
+
|A done claim in `## Progress`|quote the phase's verify command verbatim plus a result mark: `exit 0`, `N pass`, `fail` or `result` (`EXIT=0` does not count)|
|
|
45
|
+
|Implementer spawn|needs a Main Progress entry newer than the agent's last run, a reviewer PASS, an `MR: none open` or `MR !N:` line, and `Branch X: … — this task: …` for an unmerged branch|
|
|
46
|
+
|Plan edits in `planner delegated` mode|an implementer cannot write its own Progress bullet; Main enters it, marked as entered on its behalf|
|
|
47
|
+
|`edit` on a plan or code file|absolute path, tag from a read that showed the lines you anchor to|
|
|
48
|
+
|
|
38
49
|
Guard files are locked for every agent; the owner unlocks with `touch {{AGENT_DIR}}/.guard-unlock` (30 min), or — when `guards.chat_unlock` is on in the config — by typing `unlock 30` in chat (`lock` closes it again).
|
|
39
50
|
|
|
40
51
|
Autonomy tiers: the owner sets how much Main does unattended with one word — `tier strict` (edit cap `autonomy.strict_edit_limit`, at most `guards.main_max_calls` tool calls per turn; every `git push`, `glab mr merge` or `gh pr merge` also waits until the owner types the approve phrase from `autonomy.go_phrase` (default `go push`; a bare `go` is an ordinary message), which approves exactly one landing for `autonomy.go_minutes` minutes), `tier opinionated` (the limits above), or `tier full` (no edit cap or call cap, and a `Priority skip: <plan> — Main: "<reason>"` line with a reason of at least four words may skip an idle higher plan). Pushes stay owner-ruled in strict and opinionated as above; whatever the tier, guard files, the phone page, notify secrets and the unlock stay owner-only.
|