neurastream 0.3.17 → 0.3.20
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 +88 -490
- package/package.json +1 -1
- package/src/adapters/omp/index.ts +66 -54
- package/src/adapters/omp/launch.ts +4 -6
- package/src/cli/claim.ts +1 -3
- package/src/cli/dispatch.ts +25 -21
- package/src/cli/guard.ts +0 -3
- package/src/cli/incident.ts +2 -2
- package/src/cli/metrics.ts +1 -1
- package/src/cli/recall.ts +3 -6
- package/src/cli/results-build.ts +1 -3
- package/src/cli/workspace.ts +0 -3
- package/src/core/autonomy.ts +24 -21
- package/src/core/guards.ts +192 -195
- package/src/core/incidents.ts +13 -12
- package/src/core/main-start.ts +1 -1
- package/src/core/mr-sweep.ts +4 -2
- package/src/core/notify.ts +15 -15
- package/src/core/owner-log.ts +19 -17
- package/src/core/owner-topics.ts +36 -35
- package/src/core/owner-ui.ts +54 -51
- package/src/core/pages.ts +3 -4
- package/src/core/plan-approval.ts +18 -18
- package/src/core/queue/lib.ts +89 -105
- package/src/core/queue-cancel.ts +20 -10
- package/src/core/queue-check.ts +5 -7
- package/src/core/queue-close.ts +8 -8
- package/src/core/queue-finished.ts +9 -10
- package/src/core/queue-migrate.ts +1 -3
- package/src/core/queue-trim.ts +2 -4
- package/src/core/results.ts +0 -2
- package/src/core/rollover.ts +2 -3
- package/src/core/team-client.ts +5 -4
- package/src/core/watch.ts +3 -2
- package/src/core/queue/env.ts +0 -14
package/src/core/queue/lib.ts
CHANGED
|
@@ -77,28 +77,28 @@ export function autoCloseCandidate(p: Plan): boolean {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
const HOME = os.homedir();
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
|
|
81
|
+
/** Explicit filesystem paths for queue operations (structurally satisfied by `Config["paths"]`). */
|
|
82
|
+
export interface QueuePaths {
|
|
83
|
+
agent_dir: string;
|
|
84
|
+
queue_index: string;
|
|
85
|
+
blockers: string;
|
|
86
|
+
queue_state: string;
|
|
87
|
+
subagents: string;
|
|
88
|
+
cancelled: string;
|
|
89
|
+
unlock: string;
|
|
86
90
|
}
|
|
91
|
+
|
|
87
92
|
/** FINISHED.md sits beside the main index: one short entry per closed plan. */
|
|
88
|
-
export function finishedPath(): string {
|
|
89
|
-
return path.join(path.dirname(
|
|
93
|
+
export function finishedPath(paths: Pick<QueuePaths, "queue_index">): string {
|
|
94
|
+
return path.join(path.dirname(paths.queue_index), "FINISHED.md");
|
|
90
95
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return process.env.QUEUE_STATE ?? `${HOME}/.local/state/queue`;
|
|
96
|
+
|
|
97
|
+
/** Pending-cancel flag file inside the queue state directory. */
|
|
98
|
+
export function cancelPendingPath(paths: Pick<QueuePaths, "queue_state">): string {
|
|
99
|
+
return path.join(paths.queue_state, "cancel-pending.json");
|
|
96
100
|
}
|
|
97
|
-
|
|
98
|
-
// refreshQueuePaths() reassigns them after applyQueueEnv, so a static import still sees config.
|
|
99
|
-
export let INDEX = indexPath();
|
|
100
|
-
export let BLOCKERS_DIR = blockersDirPath();
|
|
101
|
-
export let STATE_DIR = stateDirPath();
|
|
101
|
+
|
|
102
102
|
export const BACKGROUND_MAX_LINES = 40;
|
|
103
103
|
export const SUB_WARN_CALLS = 90;
|
|
104
104
|
export const SUB_MAX_CALLS = 100;
|
|
@@ -168,7 +168,7 @@ function indexLines(file: string): string[] | null {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
// Relative lines resolve against `base` (default: the cwd); a repo INDEX.md passes its repo dir.
|
|
171
|
-
export function readIndex(file
|
|
171
|
+
export function readIndex(file: string, base = process.cwd()): string[] {
|
|
172
172
|
return [...new Set((indexLines(file) ?? []).map(l => path.resolve(base, expandHome(l))))];
|
|
173
173
|
}
|
|
174
174
|
|
|
@@ -176,9 +176,8 @@ export function readIndex(file = indexPath(), base = process.cwd()): string[] {
|
|
|
176
176
|
// disappear without an explicit close/cancel/migrate reason throws before anything is written, and
|
|
177
177
|
// every write lands temp+rename then chmods the file to 0444. No 0o644 before the rename: rename(2)
|
|
178
178
|
// replaces a read-only target with directory-write permission only, so the file is never writable —
|
|
179
|
-
// not even between the rename and the chmod.
|
|
180
|
-
|
|
181
|
-
export function writeIndex(lines: string[], why?: { removed?: "close" | "cancel" | "migrate" }, file = indexPath()): void {
|
|
179
|
+
// not even between the rename and the chmod.
|
|
180
|
+
export function writeIndex(lines: string[], why: { removed?: "close" | "cancel" | "migrate" } | undefined, file: string): void {
|
|
182
181
|
const index = file;
|
|
183
182
|
const newSet = new Set(
|
|
184
183
|
lines.filter(l => l.trim()).map(l => path.resolve(expandHome(l.trim().replace(/^[-*]\s+/, "").replace(/`/g, "").trim()))),
|
|
@@ -196,7 +195,7 @@ export function writeIndex(lines: string[], why?: { removed?: "close" | "cancel"
|
|
|
196
195
|
|
|
197
196
|
// Doctor's enforcement half of the same plan: the live index must sit at 0444 between writes, so
|
|
198
197
|
// no program — not just an agent tool call — can rewrite it. Returns the mode it had to fix.
|
|
199
|
-
export function enforceReadOnlyIndex(index
|
|
198
|
+
export function enforceReadOnlyIndex(index: string): string | null {
|
|
200
199
|
try {
|
|
201
200
|
const mode = statSync(index).mode & 0o777;
|
|
202
201
|
if (mode === 0o444) return null;
|
|
@@ -376,14 +375,15 @@ function reuseProblems(repo: string, file: string, secs: Map<string, string>, re
|
|
|
376
375
|
* author's machine, so nothing here may stat this machine's disk — no blocker executable()
|
|
377
376
|
* check and no reuse existsSync. Its blockers are `[]`; every other field is parsed as usual.
|
|
378
377
|
*/
|
|
379
|
-
export function parsePlan(repo: string, file: string, text: string | null, blockersDir =
|
|
378
|
+
export function parsePlan(repo: string, file: string, text: string | null, blockersDir = "", reviewAgents: string[] = [], localPaths = true, agentDir?: string): Plan {
|
|
380
379
|
const empty = { repo, file, text: "", status: null, blockers: [], doneCheck: null, worktree: null, branch: null, appliesTo: [], waiting: false, waitingLine: null, waitingAsk: null, waitingBlocked: null, waitingWhy: null, waitingCheck: null, waitsOn: [], priorityId: null, title: path.basename(file), goal: [], summary: null, phases: { done: 0, total: 0 }, started: false };
|
|
381
380
|
if (text === null) return { ...empty, errors: ["plan file listed in the index does not exist"] };
|
|
382
381
|
const errors: string[] = [];
|
|
383
382
|
const secs = sections(text);
|
|
383
|
+
const templateHint = agentDir ? `${agentDir}/queue/TEMPLATE.md` : "queue/TEMPLATE.md";
|
|
384
384
|
for (const s of REQUIRED) {
|
|
385
385
|
if (s === "progress" ? !secs.has(s) : !items(secs.get(s) ?? "").length)
|
|
386
|
-
errors.push(`missing or empty "## ${s.replace(/^\w/, c => c.toUpperCase())}" section (template: ${
|
|
386
|
+
errors.push(`missing or empty "## ${s.replace(/^\w/, c => c.toUpperCase())}" section (template: ${templateHint})`);
|
|
387
387
|
}
|
|
388
388
|
const stamp = /^(\d{8}_\d{4})/.exec(path.basename(file))?.[1] ?? "";
|
|
389
389
|
if (stamp >= READ_CUTOVER && !items(secs.get("code read by main") ?? "").length)
|
|
@@ -454,23 +454,23 @@ export function planRepo(file: string): string {
|
|
|
454
454
|
return m?.[1] ? m[1].replace(/\/$/, "") : dir;
|
|
455
455
|
}
|
|
456
456
|
|
|
457
|
-
export function readPlans(files: string[], blockersDir =
|
|
457
|
+
export function readPlans(files: string[], blockersDir = "", reviewAgents: string[] = [], agentDir?: string): Plan[] {
|
|
458
458
|
return files.map(file => {
|
|
459
459
|
let text: string | null = null;
|
|
460
460
|
try {
|
|
461
461
|
text = readFileSync(file, "utf8");
|
|
462
462
|
} catch {}
|
|
463
|
-
return parsePlan(planRepo(file), file, text, blockersDir, reviewAgents);
|
|
463
|
+
return parsePlan(planRepo(file), file, text, blockersDir, reviewAgents, true, agentDir);
|
|
464
464
|
});
|
|
465
465
|
}
|
|
466
466
|
|
|
467
|
-
export function activePlans(
|
|
468
|
-
return readPlans(readIndex(
|
|
467
|
+
export function activePlans(paths: Pick<QueuePaths, "queue_index" | "blockers" | "agent_dir">, reviewAgents: string[] = []): Plan[] {
|
|
468
|
+
return readPlans(readIndex(paths.queue_index), paths.blockers, reviewAgents, paths.agent_dir);
|
|
469
469
|
}
|
|
470
470
|
|
|
471
471
|
/** Owner holds: one line per plan with a WAITING on owner line. The only real holds; the summary, the rollover context and the handoff all read them here. */
|
|
472
|
-
export function ownerHolds(
|
|
473
|
-
return activePlans(
|
|
472
|
+
export function ownerHolds(paths: Pick<QueuePaths, "queue_index" | "blockers" | "agent_dir">): string[] {
|
|
473
|
+
return activePlans(paths)
|
|
474
474
|
.filter(p => p.waiting)
|
|
475
475
|
.map(p => `${p.file}: WAITING on owner: ${p.waitingLine ?? ""}`);
|
|
476
476
|
}
|
|
@@ -526,8 +526,8 @@ export function planAt(p: string, plans: Plan[]): Plan | null {
|
|
|
526
526
|
return plans.find(pl => pl.repo === g.repo && path.relative(pl.repo, pl.file) === rel) ?? null;
|
|
527
527
|
}
|
|
528
528
|
|
|
529
|
-
export function isOrchestrationPath(p: string, plans: Plan[]
|
|
530
|
-
if (p ===
|
|
529
|
+
export function isOrchestrationPath(p: string, plans: Plan[], indexFile: string): boolean {
|
|
530
|
+
if (p === indexFile) return true;
|
|
531
531
|
if (planAt(p, plans)) return true;
|
|
532
532
|
return plans.some(pl => pl.blockers.some(b => b.script === p));
|
|
533
533
|
}
|
|
@@ -615,7 +615,7 @@ export function registerPackageOpTarget(fn: PackageOpMatcher): void {
|
|
|
615
615
|
packageOpMatcher = fn;
|
|
616
616
|
}
|
|
617
617
|
|
|
618
|
-
function packageOpTarget(code: string): string | null {
|
|
618
|
+
function packageOpTarget(code: string, paths?: Pick<QueuePaths, "agent_dir">): string | null {
|
|
619
619
|
for (const seg of code.split(/&&|\|\||;|\n|\|/)) {
|
|
620
620
|
const toks = seg.trim().split(/\s+/).filter(Boolean);
|
|
621
621
|
let i = 0;
|
|
@@ -641,7 +641,7 @@ function packageOpTarget(code: string): string | null {
|
|
|
641
641
|
})) {
|
|
642
642
|
const envHome = toks.slice(0, i).find(t => t.startsWith("HOME="));
|
|
643
643
|
if (envHome && envHome.slice("HOME=".length).replace(/^["']|["']$/g, "").startsWith("/tmp/")) continue;
|
|
644
|
-
return `${
|
|
644
|
+
return `${paths?.agent_dir ?? `${HOME}/.config/neurastream`}/extensions/`;
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
647
|
return packageOpMatcher?.(code) ?? null;
|
|
@@ -687,7 +687,7 @@ function subagentsOpWrites(code: string): boolean {
|
|
|
687
687
|
return false;
|
|
688
688
|
}
|
|
689
689
|
|
|
690
|
-
export function writeTargets(toolName: string, input: Record<string, unknown>, cwd: string, relative?: string[]): string[] {
|
|
690
|
+
export function writeTargets(toolName: string, input: Record<string, unknown>, cwd: string, paths?: Pick<QueuePaths, "agent_dir" | "subagents">, relative?: string[]): string[] {
|
|
691
691
|
const out = new Set<string>();
|
|
692
692
|
const add = (raw: string, from: string) => {
|
|
693
693
|
const typed = String(raw).trim().replace(/^["']|["']$/g, "");
|
|
@@ -721,7 +721,7 @@ export function writeTargets(toolName: string, input: Record<string, unknown>, c
|
|
|
721
721
|
const code = String(input?.command ?? input?.code ?? "");
|
|
722
722
|
// A package/plugin/cutover command is a write even though none of the
|
|
723
723
|
// generic mutating heuristics fire on its text.
|
|
724
|
-
const pkgOp = packageOpTarget(code);
|
|
724
|
+
const pkgOp = packageOpTarget(code, paths);
|
|
725
725
|
const subOp = subagentsOpWrites(code);
|
|
726
726
|
if (!MUTATING.test(withoutQuotedRedirects(code)) && !pkgOp && !subOp) return [];
|
|
727
727
|
let dir = typeof input?.cwd === "string" ? path.resolve(cwd, expandHome(input.cwd)) : cwd;
|
|
@@ -759,14 +759,10 @@ export function writeTargets(toolName: string, input: Record<string, unknown>, c
|
|
|
759
759
|
])
|
|
760
760
|
for (const m of code.matchAll(re)) add((m[1] ?? "").replace(/`/g, ""), dir);
|
|
761
761
|
if (pkgOp) out.add(pkgOp);
|
|
762
|
-
if (subOp) out.add(
|
|
762
|
+
if (subOp) out.add(paths?.subagents ?? `${HOME}/.config/neurastream/notes/subagents.md`);
|
|
763
763
|
return [...out];
|
|
764
764
|
}
|
|
765
765
|
|
|
766
|
-
export function unlockPath(): string {
|
|
767
|
-
return process.env.QUEUE_UNLOCK ?? `${agentDir()}/.guard-unlock`;
|
|
768
|
-
}
|
|
769
|
-
export let UNLOCK = unlockPath();
|
|
770
766
|
export const UNLOCK_MINUTES = 30;
|
|
771
767
|
// P8 (2026-10-21): after the npm cutover the running guards load from the
|
|
772
768
|
// installed package, so the package itself is guard surface. The package root
|
|
@@ -788,19 +784,21 @@ function bunGlobalRoot(): string {
|
|
|
788
784
|
return process.env.BUN_INSTALL ? path.resolve(expandHome(process.env.BUN_INSTALL)) : `${HOME}/.bun`;
|
|
789
785
|
}
|
|
790
786
|
|
|
791
|
-
function protectedPaths(): string[] {
|
|
792
|
-
const agent =
|
|
793
|
-
const
|
|
787
|
+
export function protectedPaths(paths: QueuePaths): string[] {
|
|
788
|
+
const agent = paths.agent_dir;
|
|
789
|
+
const out = [
|
|
794
790
|
`${agent}/extensions/`,
|
|
795
791
|
`${agent}/queue/`,
|
|
796
792
|
`${agent}/blockers/`,
|
|
793
|
+
`${paths.blockers.replace(/\/$/, "")}/`,
|
|
797
794
|
`${agent}/agents/`,
|
|
798
795
|
`${agent}/AGENTS.md`,
|
|
799
796
|
`${agent}/CANCELLED.md`,
|
|
797
|
+
paths.cancelled,
|
|
800
798
|
// The plan index (plan 20261031_0911 P2): append-only and 0444 on disk. Agents add or
|
|
801
799
|
// reorder through `neurastream queue add` / `queue move`; only the owner writes directly.
|
|
802
|
-
|
|
803
|
-
`${
|
|
800
|
+
paths.queue_index,
|
|
801
|
+
`${paths.queue_state.replace(/\/$/, "")}/`,
|
|
804
802
|
`${agent}/config.yml`,
|
|
805
803
|
// The user's neurastream config file, even when agent_dir points elsewhere: an agent that
|
|
806
804
|
// could rewrite it could point notify at its own webhook.
|
|
@@ -810,7 +808,9 @@ function protectedPaths(): string[] {
|
|
|
810
808
|
// writer's own dirt the truth, so no tool may touch it.
|
|
811
809
|
`${HOME}/.config/neurastream/guard-baseline`,
|
|
812
810
|
`${agent}/notes/subagents.md`,
|
|
811
|
+
paths.subagents,
|
|
813
812
|
`${agent}/.guard-unlock`,
|
|
813
|
+
paths.unlock,
|
|
814
814
|
`${path.dirname(agent)}/git-no-verify-guard.mjs`,
|
|
815
815
|
`${HOME}/.local/bin/queue-check`,
|
|
816
816
|
`${HOME}/.local/bin/queue-close`,
|
|
@@ -829,16 +829,15 @@ function protectedPaths(): string[] {
|
|
|
829
829
|
];
|
|
830
830
|
const pkg = packageManifest();
|
|
831
831
|
if (pkg) {
|
|
832
|
-
|
|
833
|
-
for (const name of pkg.bins)
|
|
832
|
+
out.push(`${pkg.root}/`);
|
|
833
|
+
for (const name of pkg.bins) out.push(`${HOME}/.bun/bin/${name}`);
|
|
834
834
|
}
|
|
835
|
-
return
|
|
835
|
+
return out;
|
|
836
836
|
}
|
|
837
|
-
export let PROTECTED = protectedPaths();
|
|
838
837
|
|
|
839
|
-
export function unlocked(): boolean {
|
|
838
|
+
export function unlocked(paths: Pick<QueuePaths, "unlock">, unlockMinutes = UNLOCK_MINUTES): boolean {
|
|
840
839
|
try {
|
|
841
|
-
return Date.now() - statSync(
|
|
840
|
+
return Date.now() - statSync(paths.unlock).mtimeMs < unlockMinutes * 60_000;
|
|
842
841
|
} catch {
|
|
843
842
|
return false;
|
|
844
843
|
}
|
|
@@ -871,7 +870,7 @@ export function chatUnlock(text: string, cfg: Config, source: string, word: "cha
|
|
|
871
870
|
if (!m) return { applied: false };
|
|
872
871
|
const minutes = cfg.guards.unlock_minutes;
|
|
873
872
|
if ((m[1] ?? "").toLowerCase() === "lock") {
|
|
874
|
-
rmSync(
|
|
873
|
+
rmSync(cfg.paths.unlock, { force: true });
|
|
875
874
|
try {
|
|
876
875
|
appendFileSync(cfg.paths.plan_guard_log, `${new Date().toISOString()} LOCK ${word} source=${source}\n`);
|
|
877
876
|
} catch {}
|
|
@@ -880,7 +879,7 @@ export function chatUnlock(text: string, cfg: Config, source: string, word: "cha
|
|
|
880
879
|
const want = m[2] === undefined ? minutes : Number(m[2]);
|
|
881
880
|
if (want < 1) return { applied: false }; // "unlock 0" is no unlock
|
|
882
881
|
const n = Math.min(want, minutes);
|
|
883
|
-
const file =
|
|
882
|
+
const file = cfg.paths.unlock;
|
|
884
883
|
writeFileSync(file, "");
|
|
885
884
|
// Backdate the mtime so the existing window (mtime + unlock_minutes) closes after exactly n minutes.
|
|
886
885
|
const past = (Date.now() - (minutes - n) * 60_000) / 1000; // utimesSync takes seconds
|
|
@@ -891,16 +890,13 @@ export function chatUnlock(text: string, cfg: Config, source: string, word: "cha
|
|
|
891
890
|
return { applied: true, command: "unlock", minutes: n, until: Math.floor(past + minutes * 60) };
|
|
892
891
|
}
|
|
893
892
|
|
|
894
|
-
export function protectedHit(
|
|
895
|
-
|
|
893
|
+
export function protectedHit(targetPaths: string[], paths: QueuePaths): string | null {
|
|
894
|
+
const guarded = protectedPaths(paths);
|
|
895
|
+
for (const p of targetPaths) for (const g of guarded) if (g.endsWith("/") ? p.startsWith(g) || `${p}/` === g : p === g) return p;
|
|
896
896
|
return null;
|
|
897
897
|
}
|
|
898
898
|
|
|
899
|
-
export function
|
|
900
|
-
return process.env.QUEUE_SUBAGENTS ?? `${agentDir()}/notes/subagents.md`;
|
|
901
|
-
}
|
|
902
|
-
export let SUBAGENTS_MD = subagentsPath();
|
|
903
|
-
export function allowedAgents(file = subagentsPath()): Set<string> {
|
|
899
|
+
export function allowedAgents(file: string): Set<string> {
|
|
904
900
|
let text = "";
|
|
905
901
|
try {
|
|
906
902
|
text = readFileSync(file, "utf8");
|
|
@@ -927,10 +923,6 @@ export function reviewAgentsProblem(cfg: Config, allowed: Set<string>): { proble
|
|
|
927
923
|
}
|
|
928
924
|
|
|
929
925
|
export const CANCELLED_REL = "docs/plans/CANCELLED.md";
|
|
930
|
-
export function globalCancelledPath(): string {
|
|
931
|
-
return process.env.QUEUE_CANCELLED ?? `${agentDir()}/CANCELLED.md`;
|
|
932
|
-
}
|
|
933
|
-
export let GLOBAL_CANCELLED = globalCancelledPath();
|
|
934
926
|
export function cancelledFile(repo: string): string {
|
|
935
927
|
return path.join(repo, CANCELLED_REL);
|
|
936
928
|
}
|
|
@@ -971,8 +963,8 @@ function readList(file: string): CancelledEntry[] {
|
|
|
971
963
|
export function readCancelled(repo: string): CancelledEntry[] {
|
|
972
964
|
return readList(cancelledFile(repo));
|
|
973
965
|
}
|
|
974
|
-
export function readGlobalCancelled(): CancelledEntry[] {
|
|
975
|
-
return readList(
|
|
966
|
+
export function readGlobalCancelled(paths: Pick<QueuePaths, "cancelled">): CancelledEntry[] {
|
|
967
|
+
return readList(paths.cancelled);
|
|
976
968
|
}
|
|
977
969
|
export function banLine(what: string, owner: string, date: string): string {
|
|
978
970
|
const words = keyWords(what);
|
|
@@ -1004,7 +996,7 @@ export function finishedKey(entry: string): string {
|
|
|
1004
996
|
}
|
|
1005
997
|
|
|
1006
998
|
/** Inserts the entry above older ones. Returns false when the same plan (title + file name) is already listed. */
|
|
1007
|
-
export function prependFinished(entry: string, file
|
|
999
|
+
export function prependFinished(entry: string, file: string): boolean {
|
|
1008
1000
|
let current = "";
|
|
1009
1001
|
try {
|
|
1010
1002
|
current = readFileSync(file, "utf8");
|
|
@@ -1023,11 +1015,11 @@ export function prependFinished(entry: string, file = finishedPath()): boolean {
|
|
|
1023
1015
|
return true;
|
|
1024
1016
|
}
|
|
1025
1017
|
const slug = (name: string) => name.replace(/\.md$/, "").replace(/^\d{8}_\d{4}_/, "");
|
|
1026
|
-
export function cancelledMatches(plan: Plan): CancelledEntry[] {
|
|
1018
|
+
export function cancelledMatches(plan: Plan, paths: Pick<QueuePaths, "cancelled">): CancelledEntry[] {
|
|
1027
1019
|
if (plan.status !== "open") return [];
|
|
1028
1020
|
const mine = new Set(planWords(plan.text));
|
|
1029
1021
|
const name = path.basename(plan.file);
|
|
1030
|
-
return [...readCancelled(plan.repo), ...readGlobalCancelled()].filter(c => {
|
|
1022
|
+
return [...readCancelled(plan.repo), ...readGlobalCancelled(paths)].filter(c => {
|
|
1031
1023
|
const cleared = plan.text.split("\n").some(l => {
|
|
1032
1024
|
const m = l.match(/^\s*(?:[-*]\s+)?False positive:\s*`?([^\s`]+)`?\s+[—:–-]+\s*(.+)$/);
|
|
1033
1025
|
return m && m[1] === c.name && (m[2] ?? "").trim().length >= 15;
|
|
@@ -1039,54 +1031,44 @@ export function cancelledMatches(plan: Plan): CancelledEntry[] {
|
|
|
1039
1031
|
return need >= 2 && shared >= need && shared / Math.max(1, Math.min(c.words.length, mine.size)) >= 0.5;
|
|
1040
1032
|
});
|
|
1041
1033
|
}
|
|
1042
|
-
export function cancelledProblem(plan: Plan, c: CancelledEntry): string {
|
|
1034
|
+
export function cancelledProblem(plan: Plan, c: CancelledEntry, paths: Pick<QueuePaths, "queue_index">): string {
|
|
1043
1035
|
const what = c.name.startsWith("ban-")
|
|
1044
1036
|
? `work the owner said NEVER to do: ${c.name} (${c.date}, owner: ${c.owner}; list ${c.list})`
|
|
1045
1037
|
: `a plan the owner CANCELLED: ${c.name} (${c.date}, owner: ${c.owner}; archived under ${path.dirname(plan.file)}/archive/)`;
|
|
1046
|
-
return `resembles ${what}. Check it before going on. Same work: drop this plan (remove it from ${
|
|
1038
|
+
return `resembles ${what}. Check it before going on. Same work: drop this plan (remove it from ${paths.queue_index}) and don't do it. Different work: add the line "False positive: ${c.name} — <why it differs>" to this plan.`;
|
|
1047
1039
|
}
|
|
1048
1040
|
|
|
1049
1041
|
export const CANCEL_WORDS =
|
|
1050
1042
|
/\b(?:cancel(?:led|ed)?|abort|scrap|call (?:it|that|this) off|forget (?:it|about)|no longer (?:do|need|want)|skip (?:it|that|this|the)|(?:don'?t|do not|never|stop|quit|not to|not) (?:do|doing|start|starting|work(?:ing)? on|implement|implementing|build|building|touch|run|running|continue|continuing|bother|pursue|go ahead|proceed)|stop (?:it|that|this|the|working|now)|drop (?:it|that|this|the))\b/i;
|
|
1051
|
-
|
|
1052
|
-
export function
|
|
1053
|
-
INDEX = indexPath();
|
|
1054
|
-
BLOCKERS_DIR = blockersDirPath();
|
|
1055
|
-
STATE_DIR = stateDirPath();
|
|
1056
|
-
UNLOCK = unlockPath();
|
|
1057
|
-
PROTECTED = protectedPaths();
|
|
1058
|
-
SUBAGENTS_MD = subagentsPath();
|
|
1059
|
-
GLOBAL_CANCELLED = globalCancelledPath();
|
|
1060
|
-
CANCEL_PENDING = path.join(STATE_DIR, "cancel-pending.json");
|
|
1061
|
-
}
|
|
1062
|
-
export function cancelPending(): { at: string; words: string } | null {
|
|
1043
|
+
|
|
1044
|
+
export function cancelPending(paths: Pick<QueuePaths, "queue_state">): { at: string; words: string } | null {
|
|
1063
1045
|
try {
|
|
1064
|
-
return JSON.parse(readFileSync(
|
|
1046
|
+
return JSON.parse(readFileSync(cancelPendingPath(paths), "utf8"));
|
|
1065
1047
|
} catch {
|
|
1066
1048
|
return null;
|
|
1067
1049
|
}
|
|
1068
1050
|
}
|
|
1069
1051
|
|
|
1070
|
-
export function closeLog(file: string): string {
|
|
1071
|
-
return path.join(
|
|
1052
|
+
export function closeLog(file: string, paths: Pick<QueuePaths, "queue_state">): string {
|
|
1053
|
+
return path.join(paths.queue_state, `close-${path.basename(file, ".md")}-${sha(file).slice(0, 6)}.log`);
|
|
1072
1054
|
}
|
|
1073
1055
|
|
|
1074
|
-
export function lastCloseResult(file: string): string | null {
|
|
1056
|
+
export function lastCloseResult(file: string, paths: Pick<QueuePaths, "queue_state">): string | null {
|
|
1075
1057
|
try {
|
|
1076
|
-
const lines = readFileSync(closeLog(file), "utf8").split("\n").filter(l => /^queue-close: (REFUSED|CLOSED|AWAITING|already)/.test(l));
|
|
1058
|
+
const lines = readFileSync(closeLog(file, paths), "utf8").split("\n").filter(l => /^queue-close: (REFUSED|CLOSED|AWAITING|already)/.test(l));
|
|
1077
1059
|
return lines.at(-1) ?? null;
|
|
1078
1060
|
} catch {
|
|
1079
1061
|
return null;
|
|
1080
1062
|
}
|
|
1081
1063
|
}
|
|
1082
1064
|
|
|
1083
|
-
export function awaitingMerge(p: Plan): boolean {
|
|
1084
|
-
return p.status === "complete" && (lastCloseResult(p.file) ?? "").startsWith("queue-close: AWAITING merge");
|
|
1065
|
+
export function awaitingMerge(p: Plan, paths: Pick<QueuePaths, "queue_state">): boolean {
|
|
1066
|
+
return p.status === "complete" && (lastCloseResult(p.file, paths) ?? "").startsWith("queue-close: AWAITING merge");
|
|
1085
1067
|
}
|
|
1086
1068
|
|
|
1087
1069
|
/** P5 (plan 20261031_0911): the plan's last queue-close attempt did not close it — a refusal or still awaiting merge ("already running" is another close in flight, not a failure). */
|
|
1088
|
-
export function lastCloseFailed(file: string): boolean {
|
|
1089
|
-
const last = lastCloseResult(file);
|
|
1070
|
+
export function lastCloseFailed(file: string, paths: Pick<QueuePaths, "queue_state">): boolean {
|
|
1071
|
+
const last = lastCloseResult(file, paths);
|
|
1090
1072
|
return !!last && !last.startsWith("queue-close: CLOSED") && !last.startsWith("queue-close: already");
|
|
1091
1073
|
}
|
|
1092
1074
|
|
|
@@ -1117,26 +1099,27 @@ export interface QueueProblem {
|
|
|
1117
1099
|
problem: string;
|
|
1118
1100
|
}
|
|
1119
1101
|
|
|
1120
|
-
export function queueProblems(
|
|
1102
|
+
export function queueProblems(paths: QueuePaths, reviewAgents: string[] = []): QueueProblem[] {
|
|
1103
|
+
const index = paths.queue_index;
|
|
1121
1104
|
const probs: QueueProblem[] = [];
|
|
1122
1105
|
if (!existsSync(index)) probs.push({ where: index, problem: "main index missing: create it (empty = no open work)" });
|
|
1123
|
-
const plans =
|
|
1106
|
+
const plans = activePlans(paths, reviewAgents);
|
|
1124
1107
|
const byWorktree = new Map<string, Plan[]>();
|
|
1125
1108
|
for (const p of plans) {
|
|
1126
1109
|
for (const e of p.errors) probs.push({ where: p.file, problem: e });
|
|
1127
|
-
if ((p.status === "complete" || p.status === "cancelled") && !awaitingMerge(p)) {
|
|
1128
|
-
const last = lastCloseResult(p.file);
|
|
1110
|
+
if ((p.status === "complete" || p.status === "cancelled") && !awaitingMerge(p, paths)) {
|
|
1111
|
+
const last = lastCloseResult(p.file, paths);
|
|
1129
1112
|
probs.push({ where: p.file, problem: `says ${p.status} but is still indexed; auto-close runs at every prompt, every 15 min and after a push${last ? ` (last: ${last.replace(/^queue-close: /, "")})` : ""}` });
|
|
1130
1113
|
}
|
|
1131
1114
|
// P5 (plan 20261031_0911): a landed open plan whose auto-close failed locks the queue — the
|
|
1132
1115
|
// spawn gate and the stop gate refuse everything that does not name it until it closes.
|
|
1133
|
-
if (p.status === "open" && autoCloseCandidate(p) && lastCloseFailed(p.file))
|
|
1134
|
-
probs.push({ where: p.file, problem: `landed but not closed: ${path.basename(p.file)} — ${(lastCloseResult(p.file) ?? "").replace(/^queue-close: /, "")}` });
|
|
1116
|
+
if (p.status === "open" && autoCloseCandidate(p) && lastCloseFailed(p.file, paths))
|
|
1117
|
+
probs.push({ where: p.file, problem: `landed but not closed: ${path.basename(p.file)} — ${(lastCloseResult(p.file, paths) ?? "").replace(/^queue-close: /, "")}` });
|
|
1135
1118
|
// P5: a done check that rides `merge-base --is-ancestor` re-does the landing check the
|
|
1136
1119
|
// closer already owns, squash-aware — and misses squashes.
|
|
1137
1120
|
if (p.doneCheck?.includes("merge-base --is-ancestor"))
|
|
1138
1121
|
probs.push({ where: p.file, problem: "done check runs git merge-base --is-ancestor — queue-close checks landing itself, squash-aware; drop it" });
|
|
1139
|
-
for (const c of cancelledMatches(p)) probs.push({ where: p.file, problem: cancelledProblem(p, c) });
|
|
1122
|
+
for (const c of cancelledMatches(p, paths)) probs.push({ where: p.file, problem: cancelledProblem(p, c, paths) });
|
|
1140
1123
|
probs.push(...doneClaimProblems(p));
|
|
1141
1124
|
// A plan file must live in a main checkout, never in a linked worktree.
|
|
1142
1125
|
const g = gitTop(p.file);
|
|
@@ -1232,10 +1215,11 @@ export function holdWarnings(plans: Plan[]): string[] {
|
|
|
1232
1215
|
// and passes `cap = Infinity`.
|
|
1233
1216
|
export const SUMMARY_CAP = 10;
|
|
1234
1217
|
|
|
1235
|
-
export function queueSummary(
|
|
1218
|
+
export function queueSummary(paths: QueuePaths, reviewAgents: string[] = [], staleOrClaims: ReadonlySet<string> | Pick<ClaimStore, "holder"> | null = null, cap: number = SUMMARY_CAP): string {
|
|
1236
1219
|
// Index order IS priority (20261025_0215_index_priority): the list is flat and ranked,
|
|
1237
1220
|
// rank 1 = the index's top line; repos only surface through each plan's own path.
|
|
1238
|
-
const
|
|
1221
|
+
const index = paths.queue_index;
|
|
1222
|
+
const plans = activePlans(paths);
|
|
1239
1223
|
const rank = new Map(plans.map((p, i) => [p.file, i + 1] as const));
|
|
1240
1224
|
const repos = [...new Set(plans.map(p => p.repo))];
|
|
1241
1225
|
const lines = [`Queue (${index}): ${plans.length ? `${plans.length} plan(s) in ${repos.length} repo(s)` : "empty, no open work"}`];
|
|
@@ -1247,7 +1231,7 @@ export function queueSummary(index = INDEX, reviewAgents: string[] = [], staleOr
|
|
|
1247
1231
|
stale = staleOrClaims as ReadonlySet<string> ?? new Set<string>();
|
|
1248
1232
|
}
|
|
1249
1233
|
plans.slice(0, cap).forEach((p, i) => {
|
|
1250
|
-
const status = awaitingMerge(p) ? "complete, awaiting merge" : (p.status ?? "INVALID");
|
|
1234
|
+
const status = awaitingMerge(p, paths) ? "complete, awaiting merge" : (p.status ?? "INVALID");
|
|
1251
1235
|
const ask = (p.waitingLine ?? "").slice(0, 80);
|
|
1252
1236
|
const hold = p.waiting ? (stale?.has(p.file) ? `[STALE?] ${ask}` : `WAITING on owner: ${ask}`) : "";
|
|
1253
1237
|
// I-20261025-208: an open plan waiting on an open plan of the queue shows the target's rank.
|
|
@@ -1277,7 +1261,7 @@ export function queueSummary(index = INDEX, reviewAgents: string[] = [], staleOr
|
|
|
1277
1261
|
if (nCancelled) lines.push(`Cancelled rules: ${nCancelled}`);
|
|
1278
1262
|
const more = plans.length - Math.min(plans.length, cap);
|
|
1279
1263
|
if (more > 0) lines.push(`… ${more} more plans (queue-check lists all)`);
|
|
1280
|
-
const probs = queueProblems(
|
|
1264
|
+
const probs = queueProblems(paths, reviewAgents);
|
|
1281
1265
|
const shown = new Set(plans.slice(0, cap).map(p => p.file));
|
|
1282
1266
|
const planProbs = probs.filter(x => shown.has(x.where));
|
|
1283
1267
|
const hidden = probs.length - planProbs.length;
|
package/src/core/queue-cancel.ts
CHANGED
|
@@ -3,28 +3,27 @@ import { appendFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileS
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import type { Config } from "./config.ts";
|
|
6
|
-
import { applyQueueEnv } from "./queue/env.ts";
|
|
7
6
|
import {
|
|
8
7
|
activePlans,
|
|
9
8
|
banLine,
|
|
10
|
-
CANCEL_PENDING,
|
|
11
9
|
cancelledFile,
|
|
12
10
|
cancelledMatches,
|
|
13
11
|
cancelPending,
|
|
14
|
-
|
|
12
|
+
cancelPendingPath,
|
|
15
13
|
repoRoot,
|
|
16
|
-
STATE_DIR,
|
|
17
14
|
} from "./queue/lib.ts";
|
|
18
15
|
|
|
19
16
|
export function queueCancel(args: string[], cfg: Config): number {
|
|
20
|
-
|
|
17
|
+
const STATE_DIR = cfg.paths.queue_state;
|
|
18
|
+
const CANCEL_PENDING = cancelPendingPath(cfg.paths);
|
|
19
|
+
const GLOBAL_CANCELLED = cfg.paths.cancelled;
|
|
21
20
|
const today = new Date().toISOString().slice(0, 10);
|
|
22
21
|
function die(msg: string): never {
|
|
23
22
|
console.error(`queue-cancel: REFUSED: ${msg}`);
|
|
24
23
|
process.exit(1);
|
|
25
24
|
}
|
|
26
25
|
function clearPending(how: string) {
|
|
27
|
-
const p = cancelPending();
|
|
26
|
+
const p = cancelPending(cfg.paths);
|
|
28
27
|
mkdirSync(STATE_DIR, { recursive: true });
|
|
29
28
|
appendFileSync(path.join(STATE_DIR, "cancel.log"), `${new Date().toISOString()} ${how}${p ? ` (flagged message: ${p.words})` : ""}\n`);
|
|
30
29
|
rmSync(CANCEL_PENDING, { force: true });
|
|
@@ -34,7 +33,7 @@ export function queueCancel(args: string[], cfg: Config): number {
|
|
|
34
33
|
if (args[0] === "--not-a-cancel") {
|
|
35
34
|
const why = (args[1] ?? "").trim();
|
|
36
35
|
// Only a message main-guard flagged needs an answer; a bare call is a wasted round.
|
|
37
|
-
if (!cancelPending()) die("nothing is flagged: main-guard did not see cancel words, so there is nothing to record");
|
|
36
|
+
if (!cancelPending(cfg.paths)) die("nothing is flagged: main-guard did not see cancel words, so there is nothing to record");
|
|
38
37
|
if (why.length < 10) die(`say why the message was no cancel (at least 10 characters). ${usage}`);
|
|
39
38
|
clearPending(`not a cancel: ${why}`);
|
|
40
39
|
console.log("queue-cancel: noted, not a cancel");
|
|
@@ -70,7 +69,7 @@ export function queueCancel(args: string[], cfg: Config): number {
|
|
|
70
69
|
console.log(c.status === 0 ? `queue-cancel: committed in ${repo}; push it with the usual rules` : `queue-cancel: WARNING commit failed (hooks above); the line is in the file and already enforced, commit it later`);
|
|
71
70
|
}
|
|
72
71
|
clearPending(`never: ${line}`);
|
|
73
|
-
for (const p of activePlans()) if (cancelledMatches(p).some(c => line.startsWith(`- ${c.name} `)))
|
|
72
|
+
for (const p of activePlans(cfg.paths)) if (cancelledMatches(p, cfg.paths).some(c => line.startsWith(`- ${c.name} `)))
|
|
74
73
|
console.log(`queue-cancel: open plan ${p.file} matches it and is now refused; cancel it too: queue-cancel ${p.file} "${owner}"`);
|
|
75
74
|
return 0;
|
|
76
75
|
}
|
|
@@ -78,7 +77,7 @@ export function queueCancel(args: string[], cfg: Config): number {
|
|
|
78
77
|
const [planArg, owner = ""] = args;
|
|
79
78
|
if (!planArg || planArg.startsWith("-")) die(usage);
|
|
80
79
|
const file = path.resolve(planArg);
|
|
81
|
-
const plan = activePlans().find(p => p.file === file);
|
|
80
|
+
const plan = activePlans(cfg.paths).find(p => p.file === file);
|
|
82
81
|
if (!plan) die(`${file} is not an indexed plan; for work without a plan use --never`);
|
|
83
82
|
if (owner.trim().length < 3) die(`quote the owner's words. ${usage}`);
|
|
84
83
|
let text = readFileSync(file, "utf8");
|
|
@@ -87,6 +86,17 @@ export function queueCancel(args: string[], cfg: Config): number {
|
|
|
87
86
|
writeFileSync(file, text);
|
|
88
87
|
clearPending(`plan: ${file}`);
|
|
89
88
|
const closeBin = path.join(path.dirname(fileURLToPath(import.meta.url)), "../cli/main.ts");
|
|
90
|
-
const
|
|
89
|
+
const childEnv: NodeJS.ProcessEnv = {
|
|
90
|
+
...process.env,
|
|
91
|
+
HOME: cfg.paths.home,
|
|
92
|
+
QUEUE_AGENT: cfg.paths.agent_dir,
|
|
93
|
+
QUEUE_INDEX: cfg.paths.queue_index,
|
|
94
|
+
QUEUE_BLOCKERS: cfg.paths.blockers,
|
|
95
|
+
QUEUE_STATE: cfg.paths.queue_state,
|
|
96
|
+
QUEUE_SUBAGENTS: cfg.paths.subagents,
|
|
97
|
+
QUEUE_CANCELLED: cfg.paths.cancelled,
|
|
98
|
+
QUEUE_UNLOCK: cfg.paths.unlock,
|
|
99
|
+
};
|
|
100
|
+
const r = spawnSync("bun", [closeBin, "queue-close", file], { stdio: "inherit", env: childEnv });
|
|
91
101
|
return r.status ?? 1;
|
|
92
102
|
}
|
package/src/core/queue-check.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Config } from "./config.ts";
|
|
2
|
-
import { applyQueueEnv } from "./queue/env.ts";
|
|
3
2
|
import { activePlans, allowedAgents, holdWarnings, queueProblems, queueSummary, reviewAgentsProblem } from "./queue/lib.ts";
|
|
4
3
|
import { mrSweep } from "./mr-sweep.ts";
|
|
5
4
|
import { summaryHolder, teamSummaryLines, teamViews } from "./team-client.ts";
|
|
@@ -9,21 +8,20 @@ import { recheckHolds, staleHoldLines } from "./waiting-check.ts";
|
|
|
9
8
|
// repo INDEX.md files to git-check and no work_roots scan; the queue problems carry the
|
|
10
9
|
// worktree-placement and one-plan-one-worktree rules instead.
|
|
11
10
|
export function queueCheck(args: string[], cfg: Config): number {
|
|
12
|
-
applyQueueEnv(cfg);
|
|
13
11
|
if (args.includes("--priority-ids")) {
|
|
14
|
-
for (const p of activePlans()) if (p.priorityId && !p.waiting && p.status === "open") console.log(p.priorityId);
|
|
12
|
+
for (const p of activePlans(cfg.paths)) if (p.priorityId && !p.waiting && p.status === "open") console.log(p.priorityId);
|
|
15
13
|
return 0;
|
|
16
14
|
}
|
|
17
15
|
// P4 (20261027_1305): one GET /view per team, read once for the holder and the team lines.
|
|
18
16
|
const views = teamViews(cfg);
|
|
19
17
|
const claims = summaryHolder(cfg, {}, views);
|
|
20
|
-
const plans = activePlans();
|
|
18
|
+
const plans = activePlans(cfg.paths);
|
|
21
19
|
const holds = recheckHolds(cfg, plans);
|
|
22
|
-
console.log(queueSummary(
|
|
20
|
+
console.log(queueSummary(cfg.paths, cfg.review.agents, claims, Infinity));
|
|
23
21
|
for (const line of teamSummaryLines(cfg, views, Infinity)) console.log(line);
|
|
24
22
|
for (const line of staleHoldLines(holds, plans)) console.log(line);
|
|
25
23
|
// main-start prints the sweep itself and passes this so the child bin does not print it twice.
|
|
26
|
-
let fail = queueProblems(
|
|
24
|
+
let fail = queueProblems(cfg.paths, cfg.review.agents).length > 0;
|
|
27
25
|
// P4d (plan 20261028_1600): a review spawn needs a review.agents entry that Main may spawn.
|
|
28
26
|
const review = reviewAgentsProblem(cfg, allowedAgents(cfg.paths.subagents));
|
|
29
27
|
if (review.problem) {
|
|
@@ -35,7 +33,7 @@ export function queueCheck(args: string[], cfg: Config): number {
|
|
|
35
33
|
for (const w of holdWarnings(plans)) console.log(`warning: ${w}`);
|
|
36
34
|
if (!args.includes("--no-mr-sweep")) {
|
|
37
35
|
try {
|
|
38
|
-
const sweep = mrSweep();
|
|
36
|
+
const sweep = mrSweep({ paths: cfg.paths });
|
|
39
37
|
for (const line of sweep.lines) console.log(line);
|
|
40
38
|
if (sweep.fail) fail = true;
|
|
41
39
|
} catch {
|
package/src/core/queue-close.ts
CHANGED
|
@@ -6,8 +6,7 @@ import { claimStoreFor } from "./team-client.ts";
|
|
|
6
6
|
|
|
7
7
|
import type { Config } from "./config.ts";
|
|
8
8
|
import { mainId } from "./guards.ts";
|
|
9
|
-
import {
|
|
10
|
-
import { activePlans, cancelledFile, cancelledLine, closeLog, finishedEntry, finishedPath, gitOut as git, INDEX, landed, prependFinished, sha, STATE_DIR, writeIndex } from "./queue/lib.ts";
|
|
9
|
+
import { activePlans, cancelledFile, cancelledLine, closeLog, finishedEntry, finishedPath, gitOut as git, landed, prependFinished, sha, writeIndex } from "./queue/lib.ts";
|
|
11
10
|
import { fixedIncident } from "./incidents.ts";
|
|
12
11
|
|
|
13
12
|
// P4 (plan 20261031_0911): the landing check lives in queue/lib.ts (queueProblems' landed lock
|
|
@@ -15,7 +14,8 @@ import { fixedIncident } from "./incidents.ts";
|
|
|
15
14
|
export { landed };
|
|
16
15
|
|
|
17
16
|
export function queueClose(args: string[], cfg: Config): number {
|
|
18
|
-
|
|
17
|
+
const INDEX = cfg.paths.queue_index;
|
|
18
|
+
const STATE_DIR = cfg.paths.queue_state;
|
|
19
19
|
const ARCHIVE_DAYS = cfg.queue.archive_days;
|
|
20
20
|
|
|
21
21
|
let resultLog: string | null = null;
|
|
@@ -75,7 +75,7 @@ export function queueClose(args: string[], cfg: Config): number {
|
|
|
75
75
|
}
|
|
76
76
|
if (!arg) die("usage: queue-close [--auto] <plan file>");
|
|
77
77
|
const file = path.resolve(arg);
|
|
78
|
-
resultLog = closeLog(file);
|
|
78
|
+
resultLog = closeLog(file, cfg.paths);
|
|
79
79
|
|
|
80
80
|
mkdirSync(STATE_DIR, { recursive: true });
|
|
81
81
|
const lock = path.join(STATE_DIR, `close-${sha(file)}.lock`);
|
|
@@ -90,7 +90,7 @@ export function queueClose(args: string[], cfg: Config): number {
|
|
|
90
90
|
writeFileSync(lock, String(process.pid));
|
|
91
91
|
process.on("exit", () => rmSync(lock, { force: true }));
|
|
92
92
|
|
|
93
|
-
const plan = activePlans().find(p => p.file === file);
|
|
93
|
+
const plan = activePlans(cfg.paths).find(p => p.file === file);
|
|
94
94
|
if (!plan) die(`${file} is not listed in the main index ${INDEX}`);
|
|
95
95
|
if (plan.errors.length) die(`plan does not match the template: ${plan.errors.join("; ")}`);
|
|
96
96
|
if (plan.status !== "complete" && plan.status !== "cancelled" && !(auto && plan.status === "open"))
|
|
@@ -276,15 +276,15 @@ export function queueClose(args: string[], cfg: Config): number {
|
|
|
276
276
|
console.log(`queue-close: plan moved to ${dest}`);
|
|
277
277
|
}
|
|
278
278
|
if (!cancelling) {
|
|
279
|
-
const listed = finishedPath();
|
|
280
|
-
const added = prependFinished(finishedEntry(plan, dest, today));
|
|
279
|
+
const listed = finishedPath(cfg.paths);
|
|
280
|
+
const added = prependFinished(finishedEntry(plan, dest, today), listed);
|
|
281
281
|
console.log(added ? `queue-close: recorded in ${listed}` : `queue-close: already in ${listed}`);
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
// One index: the closed plan's line leaves the main index; there is no repo INDEX.md.
|
|
285
285
|
const lines = readFileSync(INDEX, "utf8").split("\n").filter(l => l.trim());
|
|
286
286
|
const keep = lines.filter(l => path.resolve(l.trim().replace(/^[-*]\s+/, "").replace(/`/g, "").replace(/^~(?=\/)/, os.homedir())) !== file);
|
|
287
|
-
writeIndex(keep, { removed: cancelling ? "cancel" : "close" });
|
|
287
|
+
writeIndex(keep, { removed: cancelling ? "cancel" : "close" }, INDEX);
|
|
288
288
|
console.log(`queue-close: removed from ${INDEX} (${keep.length} plan(s) left)`);
|
|
289
289
|
try {
|
|
290
290
|
const sp = path.join(STATE_DIR, "spawns.json");
|