@nodii/dev 0.6.173 → 0.6.175
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 +242 -8
- package/dist/cli.js +178 -14
- package/dist/coordinator-items.js +235 -0
- package/dist/core.js +13 -2
- package/dist/flags.js +10 -1
- package/dist/harness.js +2 -0
- package/dist/lane-asks.js +115 -0
- package/dist/lane-supervisor.js +83 -5
- package/dist/lanes.js +43 -3
- package/dist/leeway.js +218 -0
- package/dist/managed-hooks.js +37 -4
- package/dist/nudges.js +1 -1
- package/dist/repo-policy.js +13 -1
- package/dist/safety.js +11 -1
- package/dist/session-kind.js +18 -5
- package/dist/setup.js +5 -4
- package/dist/starting.js +111 -20
- package/dist/surface.js +17 -0
- package/dist/tooling-docs.js +127 -0
- package/package.json +1 -1
package/dist/flags.js
CHANGED
|
@@ -15,6 +15,11 @@ const WAIT = ["wait", "wait-minutes"];
|
|
|
15
15
|
export const COMMAND_FLAGS = {
|
|
16
16
|
"figma transfer": ["to", "reason"],
|
|
17
17
|
"coordinator start": ["machine", "account", "heartbeat-seconds"],
|
|
18
|
+
"coordinator items": ["machine"],
|
|
19
|
+
"lane ask": ["question", "options"],
|
|
20
|
+
"lane asks": ["machine", "state", "lane", "cursor", "limit"],
|
|
21
|
+
"lane answer": ["text"],
|
|
22
|
+
"lane defer": ["reason", "minutes", "leeway"],
|
|
18
23
|
"coordinator heartbeat": ["machine", "run", "pid", "pid-started-at", "interval"],
|
|
19
24
|
"issues create": ["service", ...ISSUE_FIELDS],
|
|
20
25
|
"issues update": ISSUE_FIELDS,
|
|
@@ -29,7 +34,7 @@ export const COMMAND_FLAGS = {
|
|
|
29
34
|
],
|
|
30
35
|
"lane amend": ["objective", "scope", "rules", "reason"],
|
|
31
36
|
"lane fold": ["versions", "summary", "reason"],
|
|
32
|
-
"lane amendments": ["all", "state", "note"],
|
|
37
|
+
"lane amendments": ["all", "state", "note", "all-pending"],
|
|
33
38
|
"lane authority": ["kind", "quote", "at", "to-agent"],
|
|
34
39
|
"lane start": ["key", "issue", "title", "kind", "side", "repo", "branch", "worktree", "step-limit"],
|
|
35
40
|
"lane step": ["side", "start", "done", "block", "not-applicable", "reason", "reason-code", "note", "review", "delta"],
|
|
@@ -38,6 +43,7 @@ export const COMMAND_FLAGS = {
|
|
|
38
43
|
"receipt verify": ["commit"],
|
|
39
44
|
"sync pending": ["discard", "reason"],
|
|
40
45
|
"lane done-check": ["evidence"],
|
|
46
|
+
"lane finish": ["reason", "evidence"],
|
|
41
47
|
"lane ready": ["withdraw", "reason"],
|
|
42
48
|
"lane cap": ["confirm-raise", "reason"],
|
|
43
49
|
"lane heartbeat": ["note", "waiting-on"],
|
|
@@ -48,6 +54,8 @@ export const COMMAND_FLAGS = {
|
|
|
48
54
|
"lane stop": ["reason", "sweeper", "no-closeout", "no-closeout-push", "launched-in-error", "replaced-by"],
|
|
49
55
|
"lane closeout": ["reason"],
|
|
50
56
|
"lane repo": ["repo", "branch", "worktree", "read-only", "reason"],
|
|
57
|
+
// MW1-12.6: ask (--blocker, --repo, --reason), grant (--note, --source, --worktree), refuse (--note), list (--machine, --state, --lane, --cursor, --limit).
|
|
58
|
+
"lane leeway": ["blocker", "repo", "reason", "note", "source", "worktree", "machine", "state", "lane", "cursor", "limit"],
|
|
51
59
|
// hub-232: the honest close-out and the governor.
|
|
52
60
|
"lane close": ["delivered-by", "reason", "sweeper", "no-closeout"],
|
|
53
61
|
"governor show": ["machine-id"],
|
|
@@ -58,6 +66,7 @@ export const COMMAND_FLAGS = {
|
|
|
58
66
|
"repo policy": ["root"],
|
|
59
67
|
"test affected": ["base", "max-light", "run"],
|
|
60
68
|
"repo lint": ["root"],
|
|
69
|
+
"repo docs-check": ["root", "base"],
|
|
61
70
|
"lane review": ["file", "not-required", "decision", "question", "quote", "at", "treat", "ruling"],
|
|
62
71
|
"lane non-issue": ["reason", "reroute", "evidence", "commits", "branch"],
|
|
63
72
|
"drift file": ["service", "severity", "summary", ...BODY, "related-artifact-type", "related-artifact-id"],
|
package/dist/harness.js
CHANGED
|
@@ -13,6 +13,7 @@ import { CliError, devRequest, query } from "./core.js";
|
|
|
13
13
|
import { classifyClaudeManaged, claudeManagedSettingsPath, managedClaudeHookBundle, managedHookBundle, nodiiCommandArgs, refreshManagedDispatchers, writeManagedClaudeHookBundle, writeManagedHookBundle } from "./managed-hooks.js";
|
|
14
14
|
import { heartbeatSettingsSnippet } from "./hooks.js";
|
|
15
15
|
import { nudgeSettingsSnippet } from "./nudges.js";
|
|
16
|
+
import { toolingDocsSettingsSnippet } from "./tooling-docs.js";
|
|
16
17
|
import { codexSafetyHooksSnippet, regroundingHooksSnippet, safetySettingsSnippet } from "./safety.js";
|
|
17
18
|
|
|
18
19
|
/** What this CLI wrote, per path: { mode, sha256 }, or for merge-json the hook entries it `added`. */
|
|
@@ -202,6 +203,7 @@ export function withSafetyHooks(harness) {
|
|
|
202
203
|
hooks = addHookEntries(hooks, regroundingHooksSnippet().hooks);
|
|
203
204
|
hooks = addHookEntries(hooks, heartbeatSettingsSnippet().hooks);
|
|
204
205
|
hooks = addHookEntries(hooks, nudgeSettingsSnippet().hooks);
|
|
206
|
+
hooks = addHookEntries(hooks, toolingDocsSettingsSnippet().hooks);
|
|
205
207
|
assertNodiiHooks(hooks, ".claude/settings.json");
|
|
206
208
|
settings.content = JSON.stringify({ ...parsed, hooks });
|
|
207
209
|
settings.sha256 = sha(settings.content);
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { CliError, devRequest, encode, query, requireFlag } from "./core.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* hub-525 (MW1-12.9, MW1-37.2): a lane's questions to its machine
|
|
5
|
+
* coordinator. The answer is delivered as an amendment the lane acknowledges
|
|
6
|
+
* with a Delta gather; an issue comment alone is not delivery.
|
|
7
|
+
*
|
|
8
|
+
* lane ask <key> --question TEXT [--options a,b]
|
|
9
|
+
* lane ask withdraw <ask id>
|
|
10
|
+
* lane answer <ask id> --text TEXT
|
|
11
|
+
* lane defer <ask or leeway id> --reason TEXT [--minutes N] [--leeway]
|
|
12
|
+
* lane asks [--machine M] [--state S] [--lane KEY] [--cursor C] [--limit N]
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* MW1-37.2 (DEC-0503): lane asks ship off by default; NODII_DEV_LANE_ASKS=1
|
|
17
|
+
* turns them on. Dev's rulebook holds no clause yet for a lane's question and
|
|
18
|
+
* its answer. Off, no command here calls Dev's lane-ask routes (Dev's answer
|
|
19
|
+
* route, which delivers the amendment, is then unreachable from the CLI), and
|
|
20
|
+
* the coordinator's count, list and gate leave questions out: a question
|
|
21
|
+
* cannot be cleared without the answer route.
|
|
22
|
+
*/
|
|
23
|
+
export const laneAsksOn = (env = process.env) => env?.NODII_DEV_LANE_ASKS === "1";
|
|
24
|
+
const assertAsksOn = (name, env) => {
|
|
25
|
+
if (!laneAsksOn(env))
|
|
26
|
+
throw new CliError("LANE_ASKS_OFF", `${name} is off: lane asks ship off by default (MW1-37.2). A lane writes its question as an issue comment or a heartbeat note, as before; NODII_DEV_LANE_ASKS=1 turns the commands on.`, 1);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const via = { via: "nodii-dev" };
|
|
30
|
+
const ASK_USAGE = "lane ask <key> --question TEXT [--options a,b] | lane ask withdraw <ask id>";
|
|
31
|
+
const DEFER_MAX_MINUTES = 240;
|
|
32
|
+
|
|
33
|
+
function onlyFlags(name, flags, allowed) {
|
|
34
|
+
const extra = Object.keys(flags).filter((flag) => !["json", "help", ...allowed].includes(flag));
|
|
35
|
+
if (extra.length)
|
|
36
|
+
throw new CliError("USAGE", `${name} does not take ${extra.map((flag) => `--${flag}`).join(", ")}; its flags: ${allowed.length ? allowed.map((flag) => `--${flag}`).join(", ") : "none"} (and --json).`, 2);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function laneAskCommand(args, flags, { request = devRequest, env = process.env } = {}) {
|
|
40
|
+
assertAsksOn("lane ask", env);
|
|
41
|
+
const [first, second, ...more] = args;
|
|
42
|
+
if (first === "withdraw") {
|
|
43
|
+
if (!second || more.length) throw new CliError("USAGE", "lane ask withdraw needs the ask id.", 2);
|
|
44
|
+
onlyFlags("lane ask withdraw", flags, []);
|
|
45
|
+
const payload = await request("POST", `/api/v1/lane-asks/${encode(second)}/withdraw`, { ...via });
|
|
46
|
+
return { payload, human: `Withdrawn (${payload.data?.id ?? second}): ${payload.data?.laneKey ?? "the lane"} no longer asks.` };
|
|
47
|
+
}
|
|
48
|
+
if (!first || args.length > 1) throw new CliError("USAGE", ASK_USAGE, 2);
|
|
49
|
+
onlyFlags("lane ask", flags, ["question", "options"]);
|
|
50
|
+
const question = String(requireFlag(flags, "question"));
|
|
51
|
+
const options = flags.options === undefined ? undefined : String(requireFlag(flags, "options")).split(",").map((option) => option.trim()).filter(Boolean);
|
|
52
|
+
const payload = await request("POST", `/api/v1/lanes/${encode(first)}/asks`, { question, ...(options?.length ? { options } : {}), ...via });
|
|
53
|
+
const key = payload.data?.laneKey ?? first;
|
|
54
|
+
return { payload, human: `Asked (${payload.data?.id}): the coordinator's answer reaches ${key} as an amendment; acknowledge it with nodii-dev lane gather ${key} --delta. Keep working what is not blocked.` };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function laneAnswerCommand(args, flags, { request = devRequest, env = process.env } = {}) {
|
|
58
|
+
assertAsksOn("lane answer", env);
|
|
59
|
+
if (!args[0] || args.length > 1) throw new CliError("USAGE", "lane answer <ask id> --text TEXT", 2);
|
|
60
|
+
onlyFlags("lane answer", flags, ["text"]);
|
|
61
|
+
const text = String(requireFlag(flags, "text"));
|
|
62
|
+
const payload = await request("POST", `/api/v1/lane-asks/${encode(args[0])}/answer`, { text, ...via });
|
|
63
|
+
const { ask, amendment } = payload.data ?? {};
|
|
64
|
+
const key = ask?.laneKey ?? "the lane";
|
|
65
|
+
return { payload, human: `Answered (${ask?.id ?? args[0]}): ${key} gets it as amendment ${amendment?.version ?? "?"} and acknowledges it with nodii-dev lane gather ${key} --delta.` };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Dev has no such ask: the id may be a leeway's.
|
|
69
|
+
const notFound = (error) => error instanceof CliError && (/NOT_FOUND$/.test(error.code ?? "") || error.code === "HTTP_404");
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* `lane defer <id>`: the id is tried as an ask; when Dev has no such ask it
|
|
73
|
+
* is tried as a leeway. `--leeway` goes straight to the leeway.
|
|
74
|
+
*/
|
|
75
|
+
export async function laneDeferCommand(args, flags, { request = devRequest, env = process.env } = {}) {
|
|
76
|
+
if (!args[0] || args.length > 1) throw new CliError("USAGE", "lane defer <ask or leeway id> --reason TEXT [--minutes N] [--leeway]", 2);
|
|
77
|
+
onlyFlags("lane defer", flags, ["reason", "minutes", "leeway"]);
|
|
78
|
+
const reason = String(requireFlag(flags, "reason"));
|
|
79
|
+
let minutes;
|
|
80
|
+
if (flags.minutes !== undefined) {
|
|
81
|
+
minutes = Number(requireFlag(flags, "minutes"));
|
|
82
|
+
if (!Number.isInteger(minutes) || minutes < 1 || minutes > DEFER_MAX_MINUTES)
|
|
83
|
+
throw new CliError("USAGE", `--minutes is a whole number from 1 to ${DEFER_MAX_MINUTES} (default 60).`, 2);
|
|
84
|
+
}
|
|
85
|
+
const body = { reason, ...(minutes === undefined ? {} : { minutes }), ...via };
|
|
86
|
+
const id = encode(args[0]);
|
|
87
|
+
let payload;
|
|
88
|
+
// With questions off the id can only be a leeway's.
|
|
89
|
+
let kind = flags.leeway || !laneAsksOn(env) ? "leeway" : "ask";
|
|
90
|
+
if (kind === "ask") {
|
|
91
|
+
try {
|
|
92
|
+
payload = await request("POST", `/api/v1/lane-asks/${id}/defer`, body);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (!notFound(error)) throw error;
|
|
95
|
+
kind = "leeway";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (kind === "leeway") payload = await request("POST", `/api/v1/lane-leeway/${id}/defer`, body);
|
|
99
|
+
const item = payload.data ?? {};
|
|
100
|
+
const what = kind === "ask" ? `${item.laneKey ?? "the lane"}'s question` : `${item.laneKey ?? "the lane"}'s leeway for ${item.blockerIssueKey ?? "its blocker"}`;
|
|
101
|
+
return { payload, human: `Deferred (${item.id ?? args[0]}) until ${item.deferUntil ?? "?"}: ${reason}. ${what} counts again after that.` };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const askLine = (ask) => [ask.id, ask.laneKey, ask.state === "deferred" && ask.deferUntil ? `deferred until ${ask.deferUntil}` : ask.state, ask.createdAt, String(ask.question ?? "").replace(/\s+/g, " ").trim().slice(0, 100)].join("\t");
|
|
105
|
+
|
|
106
|
+
export async function laneAsksCommand(args, flags, { request = devRequest, env = process.env } = {}) {
|
|
107
|
+
assertAsksOn("lane asks", env);
|
|
108
|
+
const filters = ["machine", "state", "lane", "cursor", "limit"];
|
|
109
|
+
if (args.length) throw new CliError("USAGE", `lane asks ${filters.map((flag) => `[--${flag} X]`).join(" ")}`, 2);
|
|
110
|
+
onlyFlags("lane asks", flags, filters);
|
|
111
|
+
const payload = await request("GET", `/api/v1/lane-asks${query(Object.fromEntries(filters.filter((flag) => flags[flag] !== undefined).map((flag) => [flag, String(requireFlag(flags, flag))])))}`);
|
|
112
|
+
const rows = payload.data ?? [];
|
|
113
|
+
const more = payload.nextCursor ? `\nMore: nodii-dev lane asks --cursor ${payload.nextCursor}` : "";
|
|
114
|
+
return { payload, human: rows.length ? `${rows.map(askLine).join("\n")}${more}` : "No lane asks." };
|
|
115
|
+
}
|
package/dist/lane-supervisor.js
CHANGED
|
@@ -19,6 +19,11 @@ import { processStartedAt, saveWatchedRun, watchdogRunDir } from "./watchdog.js"
|
|
|
19
19
|
* watchdog could only see a vanished PID and counted every exit as
|
|
20
20
|
* process_dead.
|
|
21
21
|
*
|
|
22
|
+
* hub-525: ending the run does not finish the lane. A clean exit
|
|
23
|
+
* after `lane done-check` also records the lane finished (POST
|
|
24
|
+
* /lanes/:id/finish, as `lane finish` does) with the done check's evidence,
|
|
25
|
+
* so its coordinator's `lane close` is not refused LANE_NOT_FINISHED.
|
|
26
|
+
*
|
|
22
27
|
* NODII-DEV-CLI-9: an exit before the done check, with the lane not
|
|
23
28
|
* BLOCKED, first continues the SAME session (`claude --resume`, `codex exec
|
|
24
29
|
* resume`) with "Lane <key>: done check not recorded. Continue the Task:
|
|
@@ -93,11 +98,38 @@ export const doneCheckRecorded = (lane) =>
|
|
|
93
98
|
|| (lane?.steps ?? []).some((step) => step.stepKey === "dev_check" && step.state === "done")
|
|
94
99
|
|| FINISHED_LANE.has(lane?.status);
|
|
95
100
|
|
|
96
|
-
|
|
101
|
+
const LIVE_LEEWAY = ["granted", "requested"];
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* hub-525 (MW1-12.6): the leeway step a lane is on, or null. A
|
|
105
|
+
* granted leeway is the fix to make, a requested one waits on the coordinator
|
|
106
|
+
* while the lane works what is not blocked, and `leewayNext` is Dev naming an
|
|
107
|
+
* open issue no live lane holds, with the `lane leeway` command that asks for
|
|
108
|
+
* it. The lane's `next` (its step array) is never read for this.
|
|
109
|
+
*/
|
|
110
|
+
export function laneLeewayStep(lane) {
|
|
111
|
+
for (const state of LIVE_LEEWAY) {
|
|
112
|
+
const leeway = (Array.isArray(lane?.leeways) ? lane.leeways : []).find((candidate) => candidate?.state === state);
|
|
113
|
+
if (leeway) return { kind: state, id: leeway.id, blockerIssueKey: leeway.blockerIssueKey };
|
|
114
|
+
}
|
|
115
|
+
const next = fixableBlocker(lane?.leewayNext);
|
|
116
|
+
return next ? { kind: "ask", ...next } : null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Dev's unasked fixable blocker: an object with a command, or null. */
|
|
120
|
+
export function fixableBlocker(next) {
|
|
121
|
+
if (!next || typeof next !== "object" || Array.isArray(next) || typeof next.command !== "string" || !next.command.trim()) return null;
|
|
122
|
+
return { command: next.command.trim(), blockerIssueKey: next.blockerIssueKey, reason: next.reason };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** A lane is BLOCKED by a blocked step (`lane step --block`) or a latest heartbeat note that starts "blocked" or "WAITING:" (AGENT-HARNESS-46), unless leeway covers it (MW1-12.6). */
|
|
97
126
|
export const laneBlocked = (lane) => Boolean(laneBlockedReason(lane));
|
|
98
127
|
|
|
99
128
|
/** Why a lane is BLOCKED, or null (the same rule Dev applies to a run's exit). */
|
|
100
129
|
export function laneBlockedReason(lane) {
|
|
130
|
+
// MW1-12.6: a lane with leeway asked or granted, or with a blocker it can
|
|
131
|
+
// ask leeway for, is not BLOCKED: its session is continued, not released.
|
|
132
|
+
if (laneLeewayStep(lane)) return null;
|
|
101
133
|
const step = (lane?.steps ?? []).find((candidate) => candidate.state === "blocked");
|
|
102
134
|
if (step) return `Lane step ${step.side}/${step.stepKey} is blocked.`;
|
|
103
135
|
// hub-283: the open waits first, then the latest heartbeat that says something.
|
|
@@ -116,6 +148,14 @@ export function continueTaskMessage(laneKey, lane) {
|
|
|
116
148
|
const next = (lane?.next ?? []).map((step) => `${step.side}/${step.step}`);
|
|
117
149
|
const current = [lane?.currentBackendStep && `backend/${lane.currentBackendStep}`, lane?.currentFrontendStep && `frontend/${lane.currentFrontendStep}`].filter(Boolean);
|
|
118
150
|
const step = (next.length ? next : current).join(" and ") || "the lane's objective";
|
|
151
|
+
const leeway = laneLeewayStep(lane);
|
|
152
|
+
const issue = leeway?.blockerIssueKey ?? "its blocker";
|
|
153
|
+
if (leeway?.kind === "ask")
|
|
154
|
+
return `Lane ${laneKey}: blocked on ${issue}, which no live lane holds. Do not stop BLOCKED: ask the coordinator for leeway with \`${leeway.command}\`, then keep working what is not blocked.`;
|
|
155
|
+
if (leeway?.kind === "granted")
|
|
156
|
+
return `Lane ${laneKey}: leeway ${leeway.id} for ${issue} is granted. Run \`nodii-dev lane gather ${laneKey} --delta\` if its amendment is not acknowledged yet, then fix ${issue} as its own PR. Done check not recorded: continue the Task: ${step}.`;
|
|
157
|
+
if (leeway?.kind === "requested")
|
|
158
|
+
return `Lane ${laneKey}: leeway ${leeway.id} for ${issue} waits on the coordinator; do not start that fix yet. Done check not recorded: keep working what is not blocked: ${step}.`;
|
|
119
159
|
return `Lane ${laneKey}: done check not recorded. Continue the Task: ${step}.`;
|
|
120
160
|
}
|
|
121
161
|
|
|
@@ -126,9 +166,35 @@ export function continueTaskMessage(laneKey, lane) {
|
|
|
126
166
|
async function laneProgress(request, laneKey) {
|
|
127
167
|
try {
|
|
128
168
|
const lane = (await request("GET", `/api/v1/lanes/${encode(laneKey)}`)).data;
|
|
129
|
-
return { status: lane?.status ?? null, finished: doneCheckRecorded(lane), blocked: laneBlockedReason(lane) };
|
|
169
|
+
return { status: lane?.status ?? null, finished: doneCheckRecorded(lane), blocked: laneBlockedReason(lane), finishEvidence: laneFinishEvidence(lane) };
|
|
130
170
|
} catch {
|
|
131
|
-
return { status: null, finished: false, blocked: null };
|
|
171
|
+
return { status: null, finished: false, blocked: null, finishEvidence: null };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The evidence the supervisor finishes a lane with: its recorded done check's
|
|
177
|
+
* (`lane done-check`). Null when there is none, when the lane has ended (Dev
|
|
178
|
+
* refuses LANE_TERMINAL), or when the lane already marked itself finished.
|
|
179
|
+
*/
|
|
180
|
+
function laneFinishEvidence(lane) {
|
|
181
|
+
const evidence = lane?.doneCheckRecorded?.evidence;
|
|
182
|
+
if (typeof evidence !== "string" || !evidence.trim()) return null;
|
|
183
|
+
if (FINISHED_LANE.has(lane?.status) || lane?.finishedRecord) return null;
|
|
184
|
+
return evidence.trim().slice(0, 8000);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Record the lane finished after its run ended. Never throws: a failed call
|
|
189
|
+
* leaves the exit as it was reported, and the lane can still run `lane finish`.
|
|
190
|
+
*/
|
|
191
|
+
async function finishLane(request, laneKey, reason, evidence) {
|
|
192
|
+
try {
|
|
193
|
+
await send(request, `/api/v1/lanes/${encode(laneKey)}/finish`, { reason, evidence, via: "nodii-dev" });
|
|
194
|
+
return "recorded";
|
|
195
|
+
} catch (error) {
|
|
196
|
+
if (error?.code === "LANE_ALREADY_FINISHED") return "already_finished";
|
|
197
|
+
return `failed: ${error?.code ?? error?.message ?? error}`;
|
|
132
198
|
}
|
|
133
199
|
}
|
|
134
200
|
|
|
@@ -146,7 +212,7 @@ export async function reportLaneExit({ runId, laneKey, exitCode, signal, worktre
|
|
|
146
212
|
markTerminal = markWatchedTerminal,
|
|
147
213
|
} = {}) {
|
|
148
214
|
const worktree = await inspect(worktrees);
|
|
149
|
-
const { status, finished, blocked } = await laneProgress(request, laneKey);
|
|
215
|
+
const { status, finished, blocked, finishEvidence } = await laneProgress(request, laneKey);
|
|
150
216
|
const clean = exitCode === 0 && !signal;
|
|
151
217
|
const exitRef = signal ? `signal ${signal}` : String(exitCode ?? -1);
|
|
152
218
|
const exited = signal ? `was ended by ${signal}` : `exited with code ${exitCode ?? -1}`;
|
|
@@ -197,8 +263,16 @@ export async function reportLaneExit({ runId, laneKey, exitCode, signal, worktre
|
|
|
197
263
|
});
|
|
198
264
|
} else throw error;
|
|
199
265
|
}
|
|
266
|
+
// hub-525: only a clean exit after a recorded done check, with
|
|
267
|
+
// nothing left uncommitted, finishes the lane; a failed, blocked, unfinished
|
|
268
|
+
// or handed-off exit never does. READY is a recorded done check too, so a
|
|
269
|
+
// lane that still waits (on its steward, say) or has a blocked step is not
|
|
270
|
+
// finished by its exit.
|
|
271
|
+
const laneFinish = finished && clean && !blocked && worktree.state === "clean" && finishEvidence
|
|
272
|
+
? await finishLane(request, laneKey, `The lane's done check was recorded and its process exited 0 with its worktree ${worktree.state}; recorded by the lane supervisor on exit.`, finishEvidence)
|
|
273
|
+
: null;
|
|
200
274
|
await markTerminal(runId).catch(() => {});
|
|
201
|
-
return { outcome, exitCode: exitCode ?? null, signal: signal ?? null, worktree: worktree.state, laneStatus: status };
|
|
275
|
+
return { outcome, exitCode: exitCode ?? null, signal: signal ?? null, worktree: worktree.state, laneStatus: status, ...(laneFinish ? { laneFinish } : {}) };
|
|
202
276
|
}
|
|
203
277
|
|
|
204
278
|
/** The sweep skips a run whose exit was reported (it would otherwise report process_dead). */
|
|
@@ -382,6 +456,10 @@ export async function superviseLane({
|
|
|
382
456
|
try {
|
|
383
457
|
const result = await report({ runId, laneKey, exitCode, signal, worktrees, logPath, continuations: continued });
|
|
384
458
|
process.stderr.write(`nodii-dev: lane process exit reported to Dev (${result.outcome}, exit ${signal ?? exitCode}, lane ${result.laneStatus ?? "status unknown"}, worktree ${result.worktree}).\n`);
|
|
459
|
+
if (result.laneFinish?.startsWith("failed"))
|
|
460
|
+
process.stderr.write(`nodii-dev: could not record lane ${laneKey} finished (${result.laneFinish.slice("failed: ".length)}); run \`nodii-dev lane finish ${laneKey} --reason TEXT --evidence TEXT|URL\` so its coordinator can close it.\n`);
|
|
461
|
+
else if (result.laneFinish)
|
|
462
|
+
process.stderr.write(`nodii-dev: lane ${laneKey} ${result.laneFinish === "recorded" ? "recorded finished" : "was already recorded finished"}; its coordinator can close it.\n`);
|
|
385
463
|
return exit(0);
|
|
386
464
|
} catch (error) {
|
|
387
465
|
process.stderr.write(`nodii-dev: could not report the lane process exit to Dev (${error?.code ?? error?.message ?? error}); the watchdog reports it as process_dead.\n`);
|
package/dist/lanes.js
CHANGED
|
@@ -10,7 +10,7 @@ import { assertGovernorOpen, readGovernor } from "./governor.js";
|
|
|
10
10
|
import { recordReviewReceipt, reviewCommitContext } from "./safety.js";
|
|
11
11
|
import { GATHER_TIMEOUT_MS, PICKER_FIRST_PICK_TIMEOUT_MS, agentFallbackReason, gatherDeadline, gatherText, pickDocuments, pickerModelName, pickTimingLine, pickTimingStats, readPickTimings, recordPickTiming, warmPicker, withPickLock } from "./gather.js";
|
|
12
12
|
import { storeGatherFreeze } from "./freeze.js";
|
|
13
|
-
import { doneCheckRecorded } from "./lane-supervisor.js";
|
|
13
|
+
import { doneCheckRecorded, fixableBlocker } from "./lane-supervisor.js";
|
|
14
14
|
import { STEWARD_DONE_CHECK, stewardObjective } from "./session-kind.js";
|
|
15
15
|
import { availableMemoryBytes } from "./host.js";
|
|
16
16
|
import { assertNothingPending, devDown, queuePending, receiptEvidenceBody, signedBuiltAck } from "./receipt.js";
|
|
@@ -70,21 +70,42 @@ const laneWaitsText = (x) => (x.waits?.length ? `\twaits on ${x.waits.map(waitTe
|
|
|
70
70
|
const waitText = (w) => `${w.blockerLaneKey && w.blockerLaneKey !== w.targetRef ? `${w.blockerLaneKey} (${w.targetRef})` : w.targetRef}${w.chain ? ` [chain: ${w.chain.why} ${w.chain.headLaneKey}]` : ""}`;
|
|
71
71
|
const laneLine = (x) => `${x.key}\t${x.status}\t${x.kind}/${x.side}\t${x.title}${x.stuck ? "\tSTUCK" : ""}${laneLiveness(x)}${lanePriority(x)}${laneWaitsText(x)}`;
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* hub-525 (MW1-12.6): the lane's leeways, and the command Dev
|
|
75
|
+
* gives when a BLOCKED or WAITING note names an open issue no live lane holds:
|
|
76
|
+
* `leewayNext` on the lane detail the heartbeat returns (`next` there is the
|
|
77
|
+
* step list and is never read for this).
|
|
78
|
+
*/
|
|
79
|
+
function leewayLines(payload) {
|
|
80
|
+
const data = payload?.data ?? {};
|
|
81
|
+
const lines = [];
|
|
82
|
+
const leeways = (Array.isArray(data.leeways) ? data.leeways : []).filter((leeway) => leeway?.blockerIssueKey && leeway.state);
|
|
83
|
+
if (leeways.length)
|
|
84
|
+
lines.push(` leeway: ${leeways.map((leeway) => `${leeway.blockerIssueKey} ${leeway.state}${leeway.state === "requested" ? " (waits on the coordinator)" : ""}`).join(", ")}`);
|
|
85
|
+
const next = fixableBlocker(data.leewayNext);
|
|
86
|
+
if (next)
|
|
87
|
+
lines.push(
|
|
88
|
+
` ${next.blockerIssueKey ?? "The blocker"} is open and no live lane holds it${next.reason ? ` (${next.reason})` : ""}. Do not stop BLOCKED: ask the coordinator for leeway. Run:`,
|
|
89
|
+
` ${next.command}`,
|
|
90
|
+
);
|
|
91
|
+
return lines;
|
|
92
|
+
}
|
|
93
|
+
|
|
73
94
|
/** What a heartbeat changed in the lane's waits. */
|
|
74
95
|
export function heartbeatText(ref, payload, sentWaits = false) {
|
|
75
96
|
const waits = payload?.waits;
|
|
76
97
|
// A Dev without hub-246 answers with no `waits` key at all and ignores the flag.
|
|
77
98
|
if (sentWaits && waits === undefined)
|
|
78
99
|
return `${ref}: heartbeat recorded, but this Dev does not record --waiting-on yet (needs the hub-246 deploy); the wait was not stored.`;
|
|
79
|
-
if (!waits) return `${ref}: heartbeat recorded.`;
|
|
80
100
|
const lines = [`${ref}: heartbeat recorded.`];
|
|
101
|
+
if (!waits) return [...lines, ...leewayLines(payload)].join("\n");
|
|
81
102
|
for (const change of waits.changes ?? [])
|
|
82
103
|
lines.push(change.change === "new" ? ` now waits on ${change.targetRef}` : ` no longer waits on ${change.targetRef} (${change.clearReason})`);
|
|
83
104
|
for (const drop of waits.dropped ?? []) lines.push(` not a wait: ${drop.ref}: ${drop.why}`);
|
|
84
105
|
if (waits.notices) lines.push(` coordinator notified (${waits.notices} notice${waits.notices === 1 ? "" : "s"})`);
|
|
85
106
|
const current = payload.data?.waits ?? [];
|
|
86
107
|
if (current.length) lines.push(` waiting on: ${current.map(waitText).join(", ")}`);
|
|
87
|
-
return lines.join("\n");
|
|
108
|
+
return [...lines, ...leewayLines(payload)].join("\n");
|
|
88
109
|
}
|
|
89
110
|
|
|
90
111
|
/** The wait board (GET /lanes/waits) as text: blockers first, then what holds lanes outside the graph. */
|
|
@@ -988,6 +1009,25 @@ export async function laneCommand(action, args, flags, deps = {}) {
|
|
|
988
1009
|
throw new CliError("DONE_CHECK_NOT_RECORDED", `Dev took the evidence but does not show ${ref}'s done check as recorded; it predates NODII-DEV-CLI-4. The run would still end orphaned.`, 1);
|
|
989
1010
|
return { payload, human: `${ref}: done check recorded. The lane's run ends finished when its process exits.` };
|
|
990
1011
|
}
|
|
1012
|
+
// hub-525 (MW1-28.2): the lane's own agent marks the lane finished,
|
|
1013
|
+
// which is what its coordinator's `lane close` needs (LANE_NOT_FINISHED).
|
|
1014
|
+
if (action === "finish") {
|
|
1015
|
+
const text = (name, limit, what) => {
|
|
1016
|
+
const value = flags[name];
|
|
1017
|
+
if (Array.isArray(value)) throw new CliError("USAGE", `Give --${name} once.`, 2);
|
|
1018
|
+
const trimmed = typeof value === "string" ? value.trim() : "";
|
|
1019
|
+
if (!trimmed) throw new CliError("USAGE", `lane finish needs --${name} ${what}`, 2);
|
|
1020
|
+
if (trimmed.length > limit) throw new CliError("USAGE", `--${name} is ${trimmed.length} characters; Dev keeps at most ${limit.toLocaleString("en-US")}.`, 2);
|
|
1021
|
+
return trimmed;
|
|
1022
|
+
};
|
|
1023
|
+
const body = {
|
|
1024
|
+
reason: text("reason", 4_000, "TEXT: why the lane is finished."),
|
|
1025
|
+
evidence: text("evidence", 8_000, "TEXT|URL: what the lane delivered and where its branch and commits went."),
|
|
1026
|
+
...via,
|
|
1027
|
+
};
|
|
1028
|
+
const payload = await request("POST", `/api/v1/lanes/${encode(id)}/finish`, body);
|
|
1029
|
+
return { payload, human: `${ref}: recorded finished. Its coordinator can close it with nodii-dev lane close ${ref} --reason TEXT.` };
|
|
1030
|
+
}
|
|
991
1031
|
if (action === "heartbeat") {
|
|
992
1032
|
// hub-246: --waiting-on is repeatable; it replaces the lane's waits.
|
|
993
1033
|
const waitingOn = flags["waiting-on"] === undefined ? [] : [flags["waiting-on"]].flat();
|
package/dist/leeway.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { execFile as execFileCallback } from "node:child_process";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { CliError, devRequest, encode, query, requireFlag } from "./core.js";
|
|
6
|
+
import { createWorktrees, writeLaneMarkers } from "./starting.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* hub-525 (MW1-12.6 to MW1-12.8): leeway. A lane blocked on an open
|
|
10
|
+
* issue that no live lane holds asks its machine coordinator for leeway to fix
|
|
11
|
+
* it, instead of ending BLOCKED. Dev claims the issue for the lane (a second
|
|
12
|
+
* asker is refused with the holder's key and waits on it), the coordinator
|
|
13
|
+
* grants or refuses, and a grant reaches the lane as an amendment it
|
|
14
|
+
* acknowledges with a Delta gather before it starts the fix.
|
|
15
|
+
*
|
|
16
|
+
* lane leeway <key> --blocker ISSUE [--repo NAME] --reason TEXT
|
|
17
|
+
* lane leeway grant <id> [--note TEXT] [--source PATH] [--worktree PATH]
|
|
18
|
+
* lane leeway refuse <id> [--note TEXT]
|
|
19
|
+
* lane leeway withdraw <id>
|
|
20
|
+
* lane leeway list [--machine M] [--state S] [--lane KEY] [--cursor C] [--limit N]
|
|
21
|
+
* lane leeway show <id>
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const execFile = promisify(execFileCallback);
|
|
25
|
+
const via = { via: "nodii-dev" };
|
|
26
|
+
const USAGE = "lane leeway <key> --blocker ISSUE [--repo NAME] --reason TEXT | lane leeway grant <id> [--note TEXT] [--source PATH] [--worktree PATH] | lane leeway refuse <id> [--note TEXT] | lane leeway withdraw <id> | lane leeway list [--machine M] [--state S] [--lane KEY] [--cursor C] [--limit N] | lane leeway show <id>";
|
|
27
|
+
const SUBCOMMANDS = ["grant", "refuse", "withdraw", "list", "show"];
|
|
28
|
+
const FLAGS = {
|
|
29
|
+
ask: ["blocker", "repo", "reason"],
|
|
30
|
+
grant: ["note", "source", "worktree"],
|
|
31
|
+
refuse: ["note"],
|
|
32
|
+
withdraw: [],
|
|
33
|
+
list: ["machine", "state", "lane", "cursor", "limit"],
|
|
34
|
+
show: [],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function onlyFlags(sub, flags) {
|
|
38
|
+
const extra = Object.keys(flags).filter((flag) => !["json", "help", ...FLAGS[sub]].includes(flag));
|
|
39
|
+
if (!extra.length) return;
|
|
40
|
+
const name = sub === "ask" ? "lane leeway <key>" : `lane leeway ${sub}`;
|
|
41
|
+
throw new CliError("USAGE", `${name} does not take ${extra.map((flag) => `--${flag}`).join(", ")}; its flags: ${FLAGS[sub].length ? FLAGS[sub].map((flag) => `--${flag}`).join(", ") : "none"} (and --json).`, 2);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const issueOf = (leeway) => leeway?.blockerIssueKey ?? leeway?.blockerIssueId ?? "the blocker";
|
|
45
|
+
const titled = (leeway) => `${issueOf(leeway)}${leeway?.blockerIssueTitle ? ` "${leeway.blockerIssueTitle}"` : ""}${leeway?.repo ? ` in ${leeway.repo}` : ""}`;
|
|
46
|
+
const oneLine = (value) => String(value ?? "").replace(/\s+/g, " ").trim();
|
|
47
|
+
const leewayLine = (leeway) => [leeway.id, leeway.laneKey, leeway.state, issueOf(leeway), leeway.repo ?? "-", leeway.createdAt, oneLine(leeway.reason).slice(0, 100)].join("\t");
|
|
48
|
+
|
|
49
|
+
/** The source checkout a worktree belongs to (the parent of its common git dir). */
|
|
50
|
+
async function worktreeSource(worktree) {
|
|
51
|
+
const { stdout } = await execFile("git", ["-C", worktree, "rev-parse", "--path-format=absolute", "--git-common-dir"], { encoding: "utf8" });
|
|
52
|
+
return dirname(stdout.trim());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async function isGitRepository(path) {
|
|
56
|
+
try {
|
|
57
|
+
await execFile("git", ["-C", path, "rev-parse", "--git-dir"], { encoding: "utf8" });
|
|
58
|
+
return true;
|
|
59
|
+
} catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The lane marker launch wrote in a worktree's git dir, or null. */
|
|
65
|
+
async function readLaneMarker(worktree) {
|
|
66
|
+
try {
|
|
67
|
+
const { stdout } = await execFile("git", ["-C", worktree, "rev-parse", "--path-format=absolute", "--git-dir"], { encoding: "utf8" });
|
|
68
|
+
return JSON.parse(await readFile(join(stdout.trim(), "nodii-lane.json"), "utf8"));
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function ask(key, flags, { request }) {
|
|
75
|
+
if (!key) throw new CliError("USAGE", USAGE, 2);
|
|
76
|
+
onlyFlags("ask", flags);
|
|
77
|
+
const blocker = String(requireFlag(flags, "blocker"));
|
|
78
|
+
const reason = String(requireFlag(flags, "reason"));
|
|
79
|
+
const repo = flags.repo === undefined ? undefined : String(requireFlag(flags, "repo"));
|
|
80
|
+
let payload;
|
|
81
|
+
try {
|
|
82
|
+
payload = await request("POST", `/api/v1/lanes/${encode(key)}/leeway`, { blocker, ...(repo ? { repo } : {}), reason, ...via });
|
|
83
|
+
} catch (error) {
|
|
84
|
+
// Every other refusal is Dev's own text. This one also says who holds the issue and what the lane does next.
|
|
85
|
+
if (error?.code !== "LEEWAY_BLOCKER_HELD") throw error;
|
|
86
|
+
const holder = error.details?.holderLaneKey ?? "another lane";
|
|
87
|
+
const held = `${blocker} is held by lane ${holder}${error.details?.leewayId ? ` (leeway ${error.details.leewayId})` : ""}.`;
|
|
88
|
+
const wait = error.details?.waitRecorded
|
|
89
|
+
? `A wait on ${holder} was recorded for ${key}: Dev resumes ${key} when ${holder} lands the fix.`
|
|
90
|
+
: `Dev recorded no wait: record it with nodii-dev lane heartbeat ${key} --waiting-on ${holder}.`;
|
|
91
|
+
throw new CliError(error.code, `${error.message}\n${held} ${wait} Keep working what is not blocked; do not start the fix.`, error.exitCode ?? 1, error.details);
|
|
92
|
+
}
|
|
93
|
+
const leeway = payload.data;
|
|
94
|
+
const coordinator = leeway?.coordinatorName ? `coordinator ${leeway.coordinatorName}` : "the machine coordinator";
|
|
95
|
+
return { payload, human: `Leeway asked (${leeway?.id}): ${leeway?.blockerIssueKey ?? blocker} claimed for ${leeway?.laneKey ?? key}. Waiting for ${coordinator}. Keep working what is not blocked.` };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Where the fix's worktree goes, for a repository the lane does not have:
|
|
100
|
+
* `<source>/.claude/worktrees/<lane key>`, as `lane launch` places it. The
|
|
101
|
+
* source is --source, else the checkout of that name beside the lane's first
|
|
102
|
+
* repository's.
|
|
103
|
+
*/
|
|
104
|
+
async function grantWorktree(leeway, lane, flags, { sourceOf, isRepository }) {
|
|
105
|
+
for (const flag of ["source", "worktree"])
|
|
106
|
+
if (flags[flag] !== undefined && !isAbsolute(String(requireFlag(flags, flag))))
|
|
107
|
+
throw new CliError("USAGE", `--${flag} needs an absolute path.`, 2);
|
|
108
|
+
let source = flags.source ? resolve(String(flags.source)) : null;
|
|
109
|
+
if (!source) {
|
|
110
|
+
const first = (lane.repositories ?? []).find((repository) => repository.worktree)?.worktree ?? lane.worktree;
|
|
111
|
+
let beside = null;
|
|
112
|
+
try { beside = first ? join(dirname(await sourceOf(first)), leeway.repo) : null; } catch {}
|
|
113
|
+
if (!beside || !(await isRepository(beside)))
|
|
114
|
+
throw new CliError("LEEWAY_SOURCE_REQUIRED", `Leeway ${leeway.id} is for ${leeway.repo}, which ${leeway.laneKey} does not work in, and ${beside ? `${beside} is not a git checkout` : "its checkout could not be found beside the lane's worktree"}. Pass --source /absolute/path/to/${leeway.repo} (and --worktree PATH to place the worktree elsewhere). Nothing was granted.`, 2);
|
|
115
|
+
source = beside;
|
|
116
|
+
} else if (!(await isRepository(source)))
|
|
117
|
+
throw new CliError("LEEWAY_SOURCE_REQUIRED", `--source ${source} is not a git checkout of ${leeway.repo}. Nothing was granted.`, 2);
|
|
118
|
+
const worktree = resolve(flags.worktree ? String(flags.worktree) : join(source, ".claude", "worktrees", leeway.laneKey));
|
|
119
|
+
return { source, worktree };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function grant(id, flags, { request, sourceOf, isRepository, worktrees, laneMarker, markers }) {
|
|
123
|
+
onlyFlags("grant", flags);
|
|
124
|
+
const path = `/api/v1/lane-leeway/${encode(id)}`;
|
|
125
|
+
const asked = (await request("GET", path)).data;
|
|
126
|
+
// A repository the lane already works in needs no worktree: the lane's
|
|
127
|
+
// safety hook keeps it on its lane branch, so the fix is its own commit
|
|
128
|
+
// range and PR from the worktree it has.
|
|
129
|
+
let lane = null;
|
|
130
|
+
let placed = null;
|
|
131
|
+
if (asked?.repo) {
|
|
132
|
+
lane = (await request("GET", `/api/v1/lanes/${encode(asked.laneKey ?? asked.laneId)}`)).data ?? {};
|
|
133
|
+
if (!(lane.repositories ?? []).some((repository) => repository.repo === asked.repo))
|
|
134
|
+
placed = await grantWorktree(asked, lane, flags, { sourceOf, isRepository });
|
|
135
|
+
}
|
|
136
|
+
const payload = await request("POST", `${path}/grant`, { ...(flags.note ? { note: String(flags.note) } : {}), ...(placed ? { worktree: placed.worktree } : {}), ...via });
|
|
137
|
+
const { leeway = asked, amendment, repository, warnings = [] } = payload.data ?? {};
|
|
138
|
+
const laneKey = leeway?.laneKey ?? asked?.laneKey;
|
|
139
|
+
const lines = [
|
|
140
|
+
`Leeway granted (${leeway?.id ?? id}): ${laneKey} may fix ${titled({ ...asked, ...leeway })}. Amendment ${amendment?.version ?? "?"} carries it: ${laneKey} acknowledges it with nodii-dev lane gather ${laneKey} --delta and does not start the fix before that.`,
|
|
141
|
+
];
|
|
142
|
+
if (placed) {
|
|
143
|
+
const created = { repo: repository?.repo ?? asked.repo, source: placed.source, branch: repository?.branch ?? `fix/${laneKey}`, worktree: repository?.worktree ?? placed.worktree, baseRef: "origin/main" };
|
|
144
|
+
try {
|
|
145
|
+
await worktrees([created]);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
throw new CliError("LEEWAY_WORKTREE_FAILED", `Leeway ${leeway?.id ?? id} is granted, but its worktree could not be created (${error?.message ?? error}). Create it, then tell ${laneKey}: git -C ${created.source} worktree add ${created.worktree} -b ${created.branch} ${created.baseRef}`, 1, { leeway, repository: created });
|
|
148
|
+
}
|
|
149
|
+
// The lane's marker, so a command run in the new worktree is the lane's.
|
|
150
|
+
const first = (lane?.repositories ?? []).find((known) => known.worktree)?.worktree ?? lane?.worktree;
|
|
151
|
+
const marker = first ? await laneMarker(first).catch(() => null) : null;
|
|
152
|
+
const marked = marker ? await markers([created], marker).then(() => true, () => false) : false;
|
|
153
|
+
// Without its marker a command run there is not the lane's, so it would
|
|
154
|
+
// skip the lane's amendment check: say so instead of reporting a clean grant.
|
|
155
|
+
if (!marked) lines.push(`Warning: ${created.worktree} has no lane marker (nodii-lane.json in its git directory), so commands run there are not checked as ${laneKey}'s. Before the lane works there, copy it from the git directory of ${first ?? "the lane's first worktree"} (git -C PATH rev-parse --git-dir).`);
|
|
156
|
+
lines.push(`Worktree: ${created.worktree} on ${created.branch} (from ${created.baseRef}).`);
|
|
157
|
+
} else {
|
|
158
|
+
const own = asked?.repo ? (lane?.repositories ?? []).find((known) => known.repo === asked.repo) : null;
|
|
159
|
+
lines.push(`The fix goes in ${laneKey}'s existing worktree${asked?.repo ? ` for ${asked.repo}` : ""}${own?.worktree ? ` (${own.worktree})` : ""} as its own commit range and its own PR; the lane stays on its lane branch.`);
|
|
160
|
+
}
|
|
161
|
+
lines.push(
|
|
162
|
+
`The fix is its own PR, linked to ${issueOf({ ...asked, ...leeway })} and merged by the repository's steward where it has one: leeway covers the fix, not the merge.`,
|
|
163
|
+
`After the fix merges, ${laneKey} rebases its own PR on origin/main.`,
|
|
164
|
+
...warnings.map((warning) => `Warning ${warning.code}: ${warning.message}`),
|
|
165
|
+
);
|
|
166
|
+
return { payload, human: lines.join("\n") };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export async function laneLeewayCommand(args, flags, {
|
|
170
|
+
request = devRequest,
|
|
171
|
+
sourceOf = worktreeSource,
|
|
172
|
+
isRepository = isGitRepository,
|
|
173
|
+
worktrees = createWorktrees,
|
|
174
|
+
laneMarker = readLaneMarker,
|
|
175
|
+
markers = writeLaneMarkers,
|
|
176
|
+
} = {}) {
|
|
177
|
+
const [first, second, ...more] = args;
|
|
178
|
+
if (!SUBCOMMANDS.includes(first)) {
|
|
179
|
+
if (args.length > 1) throw new CliError("USAGE", USAGE, 2);
|
|
180
|
+
return ask(first, flags, { request });
|
|
181
|
+
}
|
|
182
|
+
if (first === "list") {
|
|
183
|
+
if (second !== undefined) throw new CliError("USAGE", USAGE, 2);
|
|
184
|
+
onlyFlags("list", flags);
|
|
185
|
+
const filters = Object.fromEntries(FLAGS.list.filter((flag) => flags[flag] !== undefined).map((flag) => [flag, String(requireFlag(flags, flag))]));
|
|
186
|
+
const payload = await request("GET", `/api/v1/lane-leeway${query(filters)}`);
|
|
187
|
+
const rows = payload.data ?? [];
|
|
188
|
+
// Dev pages this as it pages the lane list.
|
|
189
|
+
const more = payload.nextCursor ? `\nMore: nodii-dev lane leeway list --cursor ${payload.nextCursor}` : "";
|
|
190
|
+
return { payload, human: rows.length ? `${rows.map(leewayLine).join("\n")}${more}` : "No leeway requests." };
|
|
191
|
+
}
|
|
192
|
+
if (!second || more.length) throw new CliError("USAGE", `lane leeway ${first} needs the leeway id (lane leeway list shows them).`, 2);
|
|
193
|
+
if (first === "grant") return grant(second, flags, { request, sourceOf, isRepository, worktrees, laneMarker, markers });
|
|
194
|
+
onlyFlags(first, flags);
|
|
195
|
+
const path = `/api/v1/lane-leeway/${encode(second)}`;
|
|
196
|
+
if (first === "show") {
|
|
197
|
+
const payload = await request("GET", path);
|
|
198
|
+
const leeway = payload.data;
|
|
199
|
+
return {
|
|
200
|
+
payload,
|
|
201
|
+
human: [
|
|
202
|
+
`Leeway ${leeway.id}: ${leeway.state}. ${leeway.laneKey} asked to fix ${titled(leeway)}.`,
|
|
203
|
+
`Reason: ${leeway.reason}`,
|
|
204
|
+
`Asked ${leeway.createdAt}${leeway.decidedAt ? `; decided ${leeway.decidedAt}` : ""}${leeway.closedAt ? `; closed ${leeway.closedAt}` : ""}.${leeway.decisionNote ? ` Note: ${leeway.decisionNote}` : ""}`,
|
|
205
|
+
...(leeway.depth > 1 || leeway.parentLeewayId ? [`Depth ${leeway.depth ?? "?"}${leeway.parentLeewayId ? `, under leeway ${leeway.parentLeewayId}` : ""}.`] : []),
|
|
206
|
+
...(leeway.state === "requested" ? [`Waiting for ${leeway.coordinatorName ? `coordinator ${leeway.coordinatorName}` : "the machine coordinator"}: nodii-dev lane leeway grant ${leeway.id} | nodii-dev lane leeway refuse ${leeway.id} --note TEXT`] : []),
|
|
207
|
+
].join("\n"),
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const payload = await request("POST", `${path}/${first}`, { ...(first === "refuse" && flags.note ? { note: String(flags.note) } : {}), ...via });
|
|
211
|
+
const leeway = payload.data;
|
|
212
|
+
return {
|
|
213
|
+
payload,
|
|
214
|
+
human: first === "refuse"
|
|
215
|
+
? `Leeway refused (${leeway.id}): ${leeway.laneKey} was not given ${issueOf(leeway)}.${leeway.decisionNote ?? flags.note ? ` Note: ${leeway.decisionNote ?? flags.note}` : ""}`
|
|
216
|
+
: `Leeway withdrawn (${leeway.id}): ${leeway.laneKey} no longer asks for ${issueOf(leeway)}.`,
|
|
217
|
+
};
|
|
218
|
+
}
|