@nodii/dev 0.6.208 → 0.6.210
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 +161 -38
- package/dist/accounts.js +17 -1
- package/dist/cli.js +74 -39
- package/dist/coordinator-items.js +31 -36
- package/dist/coordinator-watch.js +3 -1
- package/dist/core.js +72 -9
- package/dist/drill-stub.js +213 -0
- package/dist/drill.js +1081 -0
- package/dist/figma-scope.js +31 -6
- package/dist/flags.js +6 -4
- package/dist/harness.js +105 -2
- package/dist/impact.js +304 -12
- package/dist/lane-asks.js +22 -87
- package/dist/lane-messages.js +63 -1
- package/dist/lane-supervisor.js +17 -10
- package/dist/lane-switches.js +1 -1
- package/dist/lanes.js +26 -5
- package/dist/managed-version.js +90 -11
- package/dist/nodii-dev.js +2 -0
- package/dist/process-tree.js +18 -0
- package/dist/rulings.js +77 -0
- package/dist/runtime-launcher.js +41 -6
- package/dist/safety.js +3 -1
- package/dist/session-kind.js +164 -15
- package/dist/setup.js +1 -1
- package/dist/starting.js +2 -2
- package/dist/surface.js +10 -3
- package/dist/watchdog.js +108 -5
- package/package.json +1 -1
package/dist/rulings.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// O3 item 9 (MW1-115, DEC-0569): `nodii-dev ruling file --text TEXT`.
|
|
2
|
+
//
|
|
3
|
+
// Any session files a ruling in the turn it was typed. The proof is the
|
|
4
|
+
// prompt hook's own record of the turn (session-kind.js recordTurn), kept on
|
|
5
|
+
// this machine and never sent: the text must be an exact substring of that
|
|
6
|
+
// turn's prompt, else RULING_NOT_TYPED and nothing is sent. Only the ruling's
|
|
7
|
+
// own words leave the machine; it binds nothing until sorted and uploaded.
|
|
8
|
+
import { CliError, devRequest } from "./core.js";
|
|
9
|
+
import { readTurns } from "./session-kind.js";
|
|
10
|
+
|
|
11
|
+
/** A ruling must be filed in the turn it was typed; a turn older than this is not that turn. */
|
|
12
|
+
export const TURN_WINDOW_MS = 30 * 60_000;
|
|
13
|
+
/** A ruling is a sentence, not a fragment: at least this many words and characters, and at most RULING_MAX_CHARS. */
|
|
14
|
+
export const RULING_MIN_WORDS = 3;
|
|
15
|
+
export const RULING_MIN_CHARS = 12;
|
|
16
|
+
export const RULING_MAX_CHARS = 4000;
|
|
17
|
+
const USAGE = "ruling file --text - (the person's exact words on stdin, as typed this turn: --text - <<'EOF' ... EOF), or --text 'WORDS' in single quotes";
|
|
18
|
+
|
|
19
|
+
/** The words as the turn holds them: byte for byte, else with the surrounding whitespace trimmed; null when not typed. */
|
|
20
|
+
export function typedForm(prompt, text) {
|
|
21
|
+
if (prompt.includes(text)) return text;
|
|
22
|
+
const trimmed = text.trim();
|
|
23
|
+
return trimmed && trimmed !== text && prompt.includes(trimmed) ? trimmed : null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The session this command runs in, as the runtime names it; null when it does not. */
|
|
27
|
+
export const sessionOf = (env = process.env) => env.CLAUDE_SESSION_ID || env.CLAUDE_CODE_SESSION_ID || null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The turn that typed the text: the session's own (CLAUDE_SESSION_ID or
|
|
31
|
+
* CLAUDE_CODE_SESSION_ID), within the window. No session id, or no turn the
|
|
32
|
+
* hook recorded for it, is no proof: another session's turn never stands in.
|
|
33
|
+
*/
|
|
34
|
+
export function typingTurn(turns, text, { env = process.env, now = Date.now() } = {}) {
|
|
35
|
+
const session = sessionOf(env);
|
|
36
|
+
if (!session) return null;
|
|
37
|
+
const own = turns.filter((turn) => {
|
|
38
|
+
const at = Date.parse(turn.at);
|
|
39
|
+
return turn.sessionId === session && Number.isFinite(at) && now - at <= TURN_WINDOW_MS && at - now <= 60_000;
|
|
40
|
+
});
|
|
41
|
+
const holding = own
|
|
42
|
+
.map((turn) => ({ turn, text: typedForm(turn.prompt, text) }))
|
|
43
|
+
.filter((match) => match.text !== null)
|
|
44
|
+
.sort((a, b) => Date.parse(b.turn.at) - Date.parse(a.turn.at));
|
|
45
|
+
return holding[0] ?? null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function readStdin(stream = process.stdin) {
|
|
49
|
+
const chunks = [];
|
|
50
|
+
for await (const chunk of stream) chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
51
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function rulingCommand(action, args, flags, { request = devRequest, turns = readTurns, env = process.env, now = Date.now, stdin = readStdin } = {}) {
|
|
55
|
+
if (action !== "file" || args.length) throw new CliError("USAGE", USAGE, 2);
|
|
56
|
+
// `--text -` reads the exact bytes from stdin; a heredoc's own closing newline is not the person's.
|
|
57
|
+
const text = flags.text === "-" ? String(await stdin()).replace(/\r?\n$/, "") : flags.text;
|
|
58
|
+
if (typeof text !== "string" || !text.trim()) throw new CliError("USAGE", USAGE, 2);
|
|
59
|
+
const words = text.trim();
|
|
60
|
+
if (words.length < RULING_MIN_CHARS || words.split(/\s+/).length < RULING_MIN_WORDS || words.length > RULING_MAX_CHARS)
|
|
61
|
+
throw new CliError("USAGE", `A ruling is the person's whole instruction: at least ${RULING_MIN_WORDS} words and ${RULING_MIN_CHARS} characters, at most ${RULING_MAX_CHARS}. ${USAGE}`, 2);
|
|
62
|
+
const match = typingTurn(await turns(), text, { env, now: now() });
|
|
63
|
+
if (!match)
|
|
64
|
+
throw new CliError("RULING_NOT_TYPED", sessionOf(env)
|
|
65
|
+
? "This session's prompt hook did not see these words typed in its current turn (within 30 minutes), so nothing was sent. File only the person's exact words, in the turn they typed them (MW1-115)."
|
|
66
|
+
: "This command does not know its session (no CLAUDE_SESSION_ID or CLAUDE_CODE_SESSION_ID), so no turn proves these words were typed and nothing was sent (MW1-115).", 2);
|
|
67
|
+
const payload = await request("POST", "/api/v1/rulings", { text: match.text, sessionId: match.turn.sessionId, typedAt: match.turn.at });
|
|
68
|
+
return {
|
|
69
|
+
payload,
|
|
70
|
+
human: (p) => {
|
|
71
|
+
const r = p?.data ?? {};
|
|
72
|
+
return [`Ruling ${r.id ?? "(no id)"} filed verbatim (MW1-115); it binds nothing until sorted and uploaded.`,
|
|
73
|
+
` person ${r.personId ?? "?"} · session ${r.sessionId ?? match.turn.sessionId} · typed ${r.typedAt ?? match.turn.at} · filed ${r.filedAt ?? "?"}`,
|
|
74
|
+
` "${r.text ?? match.text}"`].join("\n");
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
package/dist/runtime-launcher.js
CHANGED
|
@@ -4,13 +4,32 @@ import { homedir } from "node:os";
|
|
|
4
4
|
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { configPath } from "./core.js";
|
|
7
|
+
import { stubEnv } from "./drill-stub.js";
|
|
7
8
|
import { laneConfigName } from "./lane-env.js";
|
|
8
9
|
import { recordWatchedRun } from "./watchdog.js";
|
|
9
10
|
import { laneSwitchOn } from "./lane-switches.js";
|
|
10
11
|
import { laneStepKeys, laneTrim } from "./plugin-trim.js";
|
|
11
12
|
import { continuationInvocation, continueTaskMessage, sessionIdFromLog, subagentBudgetLine } from "./lane-supervisor.js";
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
// DEV-PROCESS-1: "stub" is the drill's stub runtime shipped in this package
|
|
15
|
+
// (drill-stub.js). It runs no model and uses no account, so a drill lane
|
|
16
|
+
// resumed by anyone still starts only the stub.
|
|
17
|
+
const RUNTIMES = new Set(["codex", "claude", "stub"]);
|
|
18
|
+
export const STUB_ENTRY = fileURLToPath(new URL("drill-stub.js", import.meta.url));
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A stub account: a drill folder, under ~/.nodii/drill/, and nothing else. A
|
|
22
|
+
* real profile, or any folder outside the drill's, is refused, so a planted
|
|
23
|
+
* failure can never mark a real account exhausted.
|
|
24
|
+
*/
|
|
25
|
+
function stubAccount(profileHome, home) {
|
|
26
|
+
absolutePath(profileHome, "launch.profileHome");
|
|
27
|
+
const drills = join(resolve(home), ".nodii", "drill");
|
|
28
|
+
const inside = relative(drills, resolve(profileHome));
|
|
29
|
+
if (!inside || inside.startsWith("..") || isAbsolute(inside) || /(?:^|\/)\.(?:claude|codex)(?:[-_.]|\/|$)/.test(inside))
|
|
30
|
+
throw new TypeError("the stub runtime takes no real account: launch.profileHome must be a stub account folder under ~/.nodii/drill/");
|
|
31
|
+
return profileHome;
|
|
32
|
+
}
|
|
14
33
|
|
|
15
34
|
const requiredText = (value, name) => {
|
|
16
35
|
if (typeof value !== "string" || !value.trim())
|
|
@@ -53,7 +72,7 @@ function validateData(data) {
|
|
|
53
72
|
const laneKey = requiredText(data?.lane?.key, "lane.key");
|
|
54
73
|
const runtime = requiredText(data?.launch?.runtime, "launch.runtime");
|
|
55
74
|
if (!RUNTIMES.has(runtime))
|
|
56
|
-
throw new TypeError("launch.runtime must be codex or
|
|
75
|
+
throw new TypeError("launch.runtime must be codex, claude or stub");
|
|
57
76
|
const model = requiredText(data?.launch?.model, "launch.model");
|
|
58
77
|
const cwd = absolutePath(data?.launch?.cwd, "launch.cwd");
|
|
59
78
|
const addDirs = data?.launch?.addDirs ?? [];
|
|
@@ -69,7 +88,7 @@ function validateLaunch(options) {
|
|
|
69
88
|
throw new TypeError("runId is not a safe state-directory name");
|
|
70
89
|
const laneKey = requiredText(options?.laneKey, "laneKey");
|
|
71
90
|
const runtime = requiredText(options?.runtime, "runtime");
|
|
72
|
-
if (!RUNTIMES.has(runtime)) throw new TypeError("runtime must be codex or
|
|
91
|
+
if (!RUNTIMES.has(runtime)) throw new TypeError("runtime must be codex, claude or stub");
|
|
73
92
|
const model = requiredText(options?.model, "model");
|
|
74
93
|
const cwd = absolutePath(options?.cwd, "cwd");
|
|
75
94
|
const devConfigPath = laneConfig(options?.devConfigPath, laneKey, "devConfigPath");
|
|
@@ -77,11 +96,13 @@ function validateLaunch(options) {
|
|
|
77
96
|
if (!Array.isArray(addDirs)) throw new TypeError("addDirs must be an array");
|
|
78
97
|
for (const [index, path] of addDirs.entries()) absolutePath(path, `addDirs[${index}]`);
|
|
79
98
|
const prompt = requiredText(options?.prompt, "prompt");
|
|
80
|
-
return { runId, laneKey, runtime, model, cwd, devConfigPath, addDirs, prompt, profileHome: options.profileHome };
|
|
99
|
+
return { runId, laneKey, runtime, model, cwd, devConfigPath, addDirs, prompt, profileHome: options.profileHome, stubScript: options.stubScript };
|
|
81
100
|
}
|
|
82
101
|
|
|
83
102
|
function profileVariable(runtime, profileHome, home) {
|
|
84
103
|
if (profileHome === undefined || profileHome === null) return {};
|
|
104
|
+
// The stub runs on no real account: its profile, if any, is a stub account (a drill folder), passed as an argument, never as a profile variable.
|
|
105
|
+
if (runtime === "stub") throw new TypeError("the stub runtime takes no profile variable");
|
|
85
106
|
absolutePath(profileHome, "launch.profileHome");
|
|
86
107
|
absolutePath(home, "home");
|
|
87
108
|
const child = relative(home, profileHome);
|
|
@@ -272,7 +293,7 @@ export function buildRecoveryPrompt(data) {
|
|
|
272
293
|
export function buildRecoveryInvocation(data, { env = process.env, home = homedir(), trim = null } = {}) {
|
|
273
294
|
const { runId, laneKey, runtime, model, cwd, addDirs } = validateData(data);
|
|
274
295
|
const devConfigPath = laneConfig(data?.launch?.devConfigPath, laneKey, "launch.devConfigPath");
|
|
275
|
-
return buildInvocation({ runId, laneKey, runtime, model, cwd, addDirs, profileHome: data.launch.profileHome, devConfigPath, trim }, { env, home });
|
|
296
|
+
return buildInvocation({ runId, laneKey, runtime, model, cwd, addDirs, profileHome: data.launch.profileHome, devConfigPath, trim, stubScript: data.launch.stubScript }, { env, home });
|
|
276
297
|
}
|
|
277
298
|
|
|
278
299
|
/** NODII-DEV-CLI-191 change (8): a recovered lane's scope, from its Freeze boundaries and its steps. */
|
|
@@ -284,7 +305,7 @@ export function recoveryScope(data) {
|
|
|
284
305
|
}
|
|
285
306
|
|
|
286
307
|
function buildInvocation(options, { env = process.env, home = homedir() } = {}) {
|
|
287
|
-
const { runId, laneKey, runtime, model, cwd, addDirs, profileHome, devConfigPath, trim = null } = options;
|
|
308
|
+
const { runId, laneKey, runtime, model, cwd, addDirs, profileHome, devConfigPath, trim = null, stubScript } = options;
|
|
288
309
|
// NODII-DEV-CLI-191 change (8): plugins and connectors outside the lane's scope stay off.
|
|
289
310
|
const trimmed = runtime === "claude" && trim ? trim : null;
|
|
290
311
|
// A headless lane has nobody to approve a tool call, so it runs in the
|
|
@@ -292,6 +313,20 @@ function buildInvocation(options, { env = process.env, home = homedir() } = {})
|
|
|
292
313
|
// lane's own profile, with the harness safety hooks as the guard (they
|
|
293
314
|
// still run in this mode). Without it every Bash call, `nodii-dev lane
|
|
294
315
|
// gather` included, is refused "requires approval" (AGENT-HARNESS-43).
|
|
316
|
+
if (runtime === "stub") return {
|
|
317
|
+
command: process.execPath,
|
|
318
|
+
args: [STUB_ENTRY, "--script", absolutePath(stubScript, "stubScript"), "--model", model, ...(profileHome ? ["--account", stubAccount(profileHome, home)] : [])],
|
|
319
|
+
...(profileHome ? { stubAccount: profileHome } : {}),
|
|
320
|
+
runtime,
|
|
321
|
+
cwd,
|
|
322
|
+
env: {
|
|
323
|
+
// No account or credential reaches the stub or its steps: an inherited profile could otherwise be recorded exhausted by a drill's planted limit.
|
|
324
|
+
...stubEnv(env),
|
|
325
|
+
NODII_DEV_RUN_ID: runId,
|
|
326
|
+
NODII_DEV_LANE_KEY: laneKey,
|
|
327
|
+
NODII_DEV_CONFIG_PATH: devConfigPath,
|
|
328
|
+
},
|
|
329
|
+
};
|
|
295
330
|
const args = runtime === "codex"
|
|
296
331
|
? ["exec", "--json", "--dangerously-bypass-approvals-and-sandbox", "--cd", cwd, "--model", model, ...addDirs.flatMap((path) => ["--add-dir", path]), "-"]
|
|
297
332
|
// Claude Code refuses --print with stream-json unless --verbose is set.
|
package/dist/safety.js
CHANGED
|
@@ -1185,7 +1185,9 @@ export const codexSafetyHooksSnippet = () => ({
|
|
|
1185
1185
|
});
|
|
1186
1186
|
|
|
1187
1187
|
// The compact entry re-grounds the Freeze; the other entry prints the session
|
|
1188
|
-
// kind on every other start, and the first prompt confirms it (MW1-92).
|
|
1188
|
+
// kind on every other start, and the first prompt confirms it (MW1-92). The
|
|
1189
|
+
// prompt hook runs every prompt: it keeps the turn locally as ruling file's
|
|
1190
|
+
// proof and asks the session to file the person's rules (MW1-115). Two
|
|
1189
1191
|
// entries, so a repository already carrying the compact one gains only the new.
|
|
1190
1192
|
export const regroundingHooksSnippet = () => ({
|
|
1191
1193
|
hooks: {
|
package/dist/session-kind.js
CHANGED
|
@@ -8,12 +8,16 @@
|
|
|
8
8
|
// with no branch or worktree, so it reuses lane Gather, Freeze and the
|
|
9
9
|
// post-compaction re-grounding. Every entry point fails open: no Dev, no
|
|
10
10
|
// sign-in or an unknown payload ends in the operator-assistant reading.
|
|
11
|
+
// Every prompt (O3 items 8 and 9, MW1-115, DEC-0569) also keeps the turn on
|
|
12
|
+
// this machine as `ruling file`'s proof and shows a steward its unread lane
|
|
13
|
+
// messages from its local inbox file.
|
|
14
|
+
import { createHash } from "node:crypto";
|
|
11
15
|
import { mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
12
16
|
import { basename, dirname, join } from "node:path";
|
|
13
17
|
import { CliError, configPath, devRequest, encode, query, readConfig, requireFlag } from "./core.js";
|
|
14
18
|
import { currentLane, regroundLane } from "./freeze.js";
|
|
15
19
|
import { coordinatorGatherPayload, gatherText } from "./gather.js";
|
|
16
|
-
import {
|
|
20
|
+
import { stewardInboxContext } from "./lane-messages.js";
|
|
17
21
|
import { managedBehindText } from "./managed-version.js";
|
|
18
22
|
|
|
19
23
|
export const SESSION_KINDS = ["lane", "coordinator", "steward", "operator_assistant"];
|
|
@@ -132,7 +136,7 @@ export async function kindContract(resolved, { request = devRequest, env = proce
|
|
|
132
136
|
},
|
|
133
137
|
coordinator: () => [
|
|
134
138
|
// What lanes wait on this coordinator for comes before its next action (MW1-12.6, MW1-12.7; DEC-0486).
|
|
135
|
-
`First, before your next action: \`nodii-dev coordinator items\` lists what lanes wait on you for, each with its command (\`nodii-dev lane leeway grant|refuse ID\`,
|
|
139
|
+
`First, before your next action: \`nodii-dev coordinator items\` lists what lanes wait on you for, each with its command (\`nodii-dev lane leeway grant|refuse ID\`, \`nodii-dev lane defer ID --reason TEXT\`). \`lane leeway grant\` asks for no TOTP code; the rule is in Dev: \`nodii-dev rules show MW1-12.7\`.`,
|
|
136
140
|
// The rule is MW1-38.15 in Dev's rulebook (`nodii-dev rules show MW1-38.15`); this line only names the command's default.
|
|
137
141
|
"MW1-38.15: `lane launch` gives a lane 4 subagent slots unless `--subagents N` says otherwise (fewer lanes, subagents fanned out inside each).",
|
|
138
142
|
"Next: `nodii-dev lane list` for this machine's lanes.",
|
|
@@ -162,11 +166,13 @@ async function stewardClauseMap(steward, request) {
|
|
|
162
166
|
}
|
|
163
167
|
|
|
164
168
|
/** Plain text for SessionStart: the kind, its contract and, where it has one, its stored contract. */
|
|
165
|
-
export async function sessionStartText(payload, { managed = async () => null, request = devRequest, config = readConfig, env = process.env, dev = kindFromDev, state = writeKindState } = {}) {
|
|
169
|
+
export async function sessionStartText(payload, { managed = async () => null, request = devRequest, config = readConfig, env = process.env, dev = kindFromDev, state = writeKindState, runtimePid = sessionRuntimePid } = {}) {
|
|
166
170
|
const cwd = payload?.cwd ?? process.cwd();
|
|
167
171
|
const compact = payload?.source === "compact";
|
|
168
172
|
const resolved = { ...(await dev({ cwd, env }, { request, config })), notes: [] };
|
|
169
|
-
|
|
173
|
+
// The runtime's pid lets `steward register` find this session's state when no session id reaches it.
|
|
174
|
+
const pid = await Promise.resolve().then(runtimePid).catch(() => null);
|
|
175
|
+
await state(payload?.session_id, { kind: resolved.kind, source: resolved.source, ...stewardKeyOf(resolved), ...(pid ? { runtimePid: pid } : {}) }).catch(() => {});
|
|
170
176
|
const parts = [await kindText(resolved, { request })];
|
|
171
177
|
const copy = await managed().catch(() => null);
|
|
172
178
|
if (copy?.behind) parts[0] = `${managedBehindText(copy)}\n${parts[0]}`;
|
|
@@ -215,7 +221,7 @@ export async function firstPromptText(payload, { request = devRequest, config =
|
|
|
215
221
|
if (before?.prompted) return null;
|
|
216
222
|
const prompt = kindFromPrompt(payload?.prompt);
|
|
217
223
|
const resolved = resolveKind(await dev({ cwd: payload?.cwd ?? process.cwd(), env }, { request, config }), prompt);
|
|
218
|
-
await state(session, { kind: resolved.kind, source: resolved.source, prompted: true }).catch(() => {});
|
|
224
|
+
await state(session, { kind: resolved.kind, source: resolved.source, prompted: true, ...stewardKeyOf(resolved) }).catch(() => {});
|
|
219
225
|
// SessionStart already printed this kind and nothing disagrees: say so in one line.
|
|
220
226
|
if (before?.kind === resolved.kind && !resolved.notes.length)
|
|
221
227
|
return prompt ? `Session kind: ${KIND_LABEL[resolved.kind]} (MW1-92), confirmed by the first prompt.` : null;
|
|
@@ -225,8 +231,107 @@ export async function firstPromptText(payload, { request = devRequest, config =
|
|
|
225
231
|
return text;
|
|
226
232
|
}
|
|
227
233
|
|
|
228
|
-
|
|
229
|
-
const
|
|
234
|
+
// The steward's lane key is its inbox key (NODII-DEV-CLI-191), read on every turn without a Dev call (O3 item 8).
|
|
235
|
+
const stewardKeyOf = (resolved) => (resolved.kind === "steward" && resolved.steward?.key ? { stewardKey: resolved.steward.key } : {});
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* O3 item 9 (MW1-115): every prompt, the hook keeps the turn on this machine
|
|
239
|
+
* only, so `ruling file` can prove its words were typed in it. One file per
|
|
240
|
+
* session, overwritten each turn; it is never sent.
|
|
241
|
+
*/
|
|
242
|
+
export const RULING_LINE = "nodii-dev: if the person's message gives an instruction or rule about how work is done, file it verbatim this turn, their exact words on stdin: `nodii-dev ruling file --text - <<'EOF'`, the words, then `EOF` on its own line; or `--text '<their exact words>'` in single quotes (MW1-115). File nothing else.";
|
|
243
|
+
|
|
244
|
+
/** A lane session (a lane run or a lane config) files no rulings, so its turns are not kept. */
|
|
245
|
+
const isLaneSession = (env) => Boolean(env.NODII_DEV_RUN_ID) || isLaneConfig(env);
|
|
246
|
+
|
|
247
|
+
/** UserPromptSubmit, every prompt: record the turn, the first prompt's kind, a steward's unread messages, the ruling line. */
|
|
248
|
+
export async function promptTurnText(payload, { env = process.env, turn = recordTurn, readState = readKindState, inbox = stewardInboxContext, first = firstPromptText, runtimePid = sessionRuntimePid, watched = watchedStewards, ...deps } = {}) {
|
|
249
|
+
const session = payload?.session_id;
|
|
250
|
+
// The ruling line asks only for what this turn's record can prove (review of #505).
|
|
251
|
+
const recorded = isLaneSession(env) ? null : await turn(session, payload?.prompt).catch(() => null);
|
|
252
|
+
const kind = await first(payload, { env, readState, ...deps }).catch(() => null);
|
|
253
|
+
// O3 item 8: a steward session sees its deliveries at its next turn, from its local inbox file alone.
|
|
254
|
+
const state = await readState(session).catch(() => null);
|
|
255
|
+
// Only the session the steward run watches reads its inbox: another session of the same agent would consume it (review of #505).
|
|
256
|
+
const mail = state?.kind === "steward" && state.stewardKey && !isLaneConfig(env) && (await isWatchedSteward(state.stewardKey, { runtimePid, watched }))
|
|
257
|
+
? await inbox(state.stewardKey, { env }).catch(() => null) : null;
|
|
258
|
+
return [kind, mail, recorded ? RULING_LINE : null].filter(Boolean).join("\n\n");
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** The pid of the Claude or Codex runtime this process runs under, or null. */
|
|
262
|
+
export async function sessionRuntimePid({ pid = process.pid } = {}) {
|
|
263
|
+
const tree = await import("./process-tree.js");
|
|
264
|
+
return tree.runtimeAncestor(tree.processTable(), pid)?.pid ?? null;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** The watched steward runs on this machine: [{ steward, pid }]. */
|
|
268
|
+
async function watchedStewards() {
|
|
269
|
+
const { readWatchedRuns } = await import("./watchdog.js");
|
|
270
|
+
return (await readWatchedRuns()).records.filter((record) => record.steward).map(({ steward, pid }) => ({ steward, pid }));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Is this session the one whose runtime the watched run for KEY names? */
|
|
274
|
+
async function isWatchedSteward(key, { runtimePid, watched }) {
|
|
275
|
+
try {
|
|
276
|
+
const records = (await watched()).filter((record) => record.steward === key);
|
|
277
|
+
if (!records.length) return false;
|
|
278
|
+
const pid = await runtimePid();
|
|
279
|
+
return Boolean(pid) && records.some((record) => record.pid === pid);
|
|
280
|
+
} catch { return false; }
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* The session `steward register` runs in: CLAUDE_SESSION_ID or
|
|
285
|
+
* CLAUDE_CODE_SESSION_ID, else the session-kinds state whose SessionStart
|
|
286
|
+
* recorded this runtime's pid. Null when neither names one.
|
|
287
|
+
*/
|
|
288
|
+
export async function callingSession({ env = process.env, pid = null, dir = stateDir() } = {}) {
|
|
289
|
+
const named = env.CLAUDE_SESSION_ID || env.CLAUDE_CODE_SESSION_ID;
|
|
290
|
+
if (named) return String(named);
|
|
291
|
+
if (!pid) return null;
|
|
292
|
+
let found = null;
|
|
293
|
+
for (const name of await readdir(dir).catch(() => [])) {
|
|
294
|
+
if (!name.endsWith(".json") || name.endsWith(TURN_SUFFIX)) continue;
|
|
295
|
+
try {
|
|
296
|
+
const state = JSON.parse(await readFile(join(dir, name), "utf8"));
|
|
297
|
+
if (state?.runtimePid === pid && (!found || Date.parse(state.at) > Date.parse(found.at))) found = { session: name.slice(0, -".json".length), at: state.at };
|
|
298
|
+
} catch {}
|
|
299
|
+
}
|
|
300
|
+
return found?.session ?? null;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export const kindStateDir = () => join(dirname(configPath()), STATE_DIR);
|
|
304
|
+
const stateDir = kindStateDir;
|
|
305
|
+
const safeSession = (session) => String(session).replace(/[^A-Za-z0-9_-]/g, "_");
|
|
306
|
+
const statePath = (session) => join(stateDir(), `${safeSession(session)}.json`);
|
|
307
|
+
export const TURN_SUFFIX = ".turn.json";
|
|
308
|
+
export const turnPath = (session, dir = stateDir()) => join(dir, `${safeSession(session)}${TURN_SUFFIX}`);
|
|
309
|
+
export const promptSha256 = (prompt) => createHash("sha256").update(String(prompt), "utf8").digest("hex");
|
|
310
|
+
|
|
311
|
+
/** The session's current turn, {sessionId, promptSha256, prompt, at}, replacing the one before (0600, never sent). */
|
|
312
|
+
export async function recordTurn(session, prompt, { now = Date.now(), dir = stateDir() } = {}) {
|
|
313
|
+
if (!session || typeof prompt !== "string") return null;
|
|
314
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
315
|
+
const record = { sessionId: String(session), promptSha256: promptSha256(prompt), prompt, at: new Date(now).toISOString() };
|
|
316
|
+
const path = turnPath(session, dir);
|
|
317
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
318
|
+
await writeFile(temporary, `${JSON.stringify(record)}\n`, { mode: 0o600 });
|
|
319
|
+
await rename(temporary, path);
|
|
320
|
+
return record;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Every session's recorded turn in the state dir; unreadable or altered files are left out. */
|
|
324
|
+
export async function readTurns({ dir = stateDir() } = {}) {
|
|
325
|
+
const turns = [];
|
|
326
|
+
for (const name of await readdir(dir).catch(() => [])) {
|
|
327
|
+
if (!name.endsWith(TURN_SUFFIX)) continue;
|
|
328
|
+
try {
|
|
329
|
+
const turn = JSON.parse(await readFile(join(dir, name), "utf8"));
|
|
330
|
+
if (typeof turn?.prompt === "string" && turn.promptSha256 === promptSha256(turn.prompt) && turn.sessionId && turn.at) turns.push(turn);
|
|
331
|
+
} catch {}
|
|
332
|
+
}
|
|
333
|
+
return turns;
|
|
334
|
+
}
|
|
230
335
|
|
|
231
336
|
export async function readKindState(session) {
|
|
232
337
|
if (!session) return null;
|
|
@@ -250,31 +355,75 @@ export async function writeKindState(session, update, { now = Date.now() } = {})
|
|
|
250
355
|
}
|
|
251
356
|
}
|
|
252
357
|
|
|
358
|
+
/**
|
|
359
|
+
* O3 item 6 (DEC-0569, MW1-36.5): the steward session's own long-lived
|
|
360
|
+
* process, the Claude or Codex runtime this CLI runs under. Null when none is
|
|
361
|
+
* found; then no process is sent.
|
|
362
|
+
*/
|
|
363
|
+
export async function stewardRuntimeProcess({ pid = process.pid, table, startedAt } = {}) {
|
|
364
|
+
const tree = await import("./process-tree.js");
|
|
365
|
+
const runtime = tree.runtimeAncestor(table ?? tree.processTable(), pid);
|
|
366
|
+
if (!runtime) return null;
|
|
367
|
+
const { processStartedAt } = await import("./watchdog.js");
|
|
368
|
+
const started = startedAt ? await startedAt(runtime.pid) : await processStartedAt(runtime.pid).catch(() => null);
|
|
369
|
+
return started ? { pid: runtime.pid, startedAt: started } : null;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const isoOf = (started) => { const at = Date.parse(started); return Number.isFinite(at) ? new Date(at).toISOString() : String(started); };
|
|
373
|
+
const REGISTER_USAGE = "steward register --focus TEXT (--repos R,... | --scratch) [--side frontend|backend|both] [--key KEY] | steward show";
|
|
374
|
+
|
|
253
375
|
/**
|
|
254
376
|
* `nodii-dev steward register|show` (MW1-93): a steward is a lane of kind
|
|
255
377
|
* `steward` with no branch or worktree, started at once on its gather step.
|
|
378
|
+
* `--scratch` (O3 item 12) registers a throwaway steward with no repository,
|
|
379
|
+
* outside the weekly numbers. Registering sends the session's runtime process
|
|
380
|
+
* so Dev reads the steward live or dead from it, and the watchdog sweep
|
|
381
|
+
* watches the run Dev returns (O3 item 6).
|
|
256
382
|
*/
|
|
257
|
-
export async function stewardCommand(action, args, flags, { request = devRequest, config = readConfig } = {}) {
|
|
383
|
+
export async function stewardCommand(action, args, flags, { request = devRequest, config = readConfig, runtime = stewardRuntimeProcess, watch = async (record) => (await import("./watchdog.js")).recordWatchedRun(record), env = process.env, findSession = callingSession, state = writeKindState } = {}) {
|
|
258
384
|
const current = await config();
|
|
259
385
|
if (action === "show") {
|
|
260
386
|
const steward = await activeSteward(current.agentId, { request });
|
|
261
387
|
if (!steward) throw new CliError("STEWARD_NOT_REGISTERED", "This agent has no live steward registration; `nodii-dev steward register --focus TEXT --repos R,...` makes one.", 1);
|
|
262
|
-
return { payload: { data: steward }, human: (p) => `${p.data.key} · steward · ${p.data.status}\nFocus: ${focusOf(p.data)}\nRepositories: ${(p.data.repos ?? []).join(", ")}` };
|
|
388
|
+
return { payload: { data: steward }, human: (p) => `${p.data.key} · steward${p.data.scratch ? " (scratch)" : ""} · ${p.data.status}\nFocus: ${focusOf(p.data)}\nRepositories: ${(p.data.repos ?? []).join(", ") || "none"}` };
|
|
263
389
|
}
|
|
264
|
-
if (action !== "register") throw new CliError("USAGE",
|
|
390
|
+
if (action !== "register") throw new CliError("USAGE", REGISTER_USAGE, 2);
|
|
265
391
|
const focus = String(requireFlag(flags, "focus")).trim();
|
|
266
392
|
if (!focus) throw new CliError("USAGE", "steward register --focus needs the operator's focus", 2);
|
|
267
|
-
const
|
|
268
|
-
if (!
|
|
393
|
+
const scratch = flags.scratch === true || flags.scratch === "true";
|
|
394
|
+
if (flags.scratch !== undefined && !scratch) throw new CliError("USAGE", "steward register --scratch takes no value", 2);
|
|
395
|
+
if (scratch && flags.repos !== undefined) throw new CliError("USAGE", "steward register --scratch works no repository: drop --repos", 2);
|
|
396
|
+
const repos = scratch ? [] : String(requireFlag(flags, "repos")).split(",").map((repo) => repo.trim()).filter(Boolean);
|
|
397
|
+
if (!scratch && !repos.length) throw new CliError("USAGE", "steward register --repos needs at least one repository", 2);
|
|
269
398
|
const side = flags.side ?? "frontend";
|
|
270
399
|
if (!["frontend", "backend", "both"].includes(side)) throw new CliError("USAGE", "steward register --side is frontend, backend or both", 2);
|
|
271
400
|
const agent = (await request("GET", `/api/v1/agents/${encode(current.agentId)}`)).data;
|
|
272
401
|
if (!agent?.machineId) throw new CliError("MACHINE_REQUIRED", "The current agent is not assigned to a machine.", 1);
|
|
273
402
|
const key = flags.key ?? `steward-${String(agent.name ?? current.agentId).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40) || current.agentId.slice(0, 8)}`;
|
|
274
403
|
await request("POST", "/api/v1/lanes", {
|
|
275
|
-
key, title: focus, kind: "steward", side, repos,
|
|
404
|
+
key, title: focus, kind: "steward", side, repos, ...(scratch ? { scratch: true } : {}),
|
|
276
405
|
agentId: current.agentId, machineId: agent.machineId, issueIds: [], via: "nodii-dev",
|
|
277
406
|
});
|
|
278
|
-
const
|
|
279
|
-
|
|
407
|
+
const session = await runtime().catch(() => null);
|
|
408
|
+
const payload = await request("POST", `/api/v1/lanes/${encode(key)}/start`, {
|
|
409
|
+
via: "nodii-dev", ...(session ? { process: { pid: session.pid, startedAt: isoOf(session.startedAt) } } : {}),
|
|
410
|
+
});
|
|
411
|
+
const runId = payload?.data?.runId ?? payload?.data?.run?.id ?? payload?.runId ?? null;
|
|
412
|
+
let watched = null;
|
|
413
|
+
if (session && runId) {
|
|
414
|
+
try { watched = await watch({ runId, pid: session.pid, processStartedAt: session.startedAt, configPath: configPath(), steward: key }); }
|
|
415
|
+
catch (error) { watched = { error: error?.code ?? "WATCHDOG_RECORD_FAILED" }; }
|
|
416
|
+
}
|
|
417
|
+
// The calling session is the steward from its next prompt: its kind state names the key its hook delivers to (review of #505).
|
|
418
|
+
const caller = await findSession({ env, pid: session?.pid ?? null }).catch(() => null);
|
|
419
|
+
if (caller) await state(caller, { kind: "steward", source: `steward register ${key} in this session`, stewardKey: key }).catch(() => {});
|
|
420
|
+
const liveness = !session
|
|
421
|
+
? "No Claude or Codex runtime was found above this command, so Dev has no process to read this steward's liveness from."
|
|
422
|
+
: runId && watched && !watched.error
|
|
423
|
+
? `Liveness: run ${runId}, process ${session.pid}; the watchdog sweep reports it dead when the session ends.`
|
|
424
|
+
: `Liveness: process ${session.pid} sent${runId ? `; the watchdog could not record run ${runId} (${watched?.error ?? "no record"})` : "; Dev returned no run id"}.`;
|
|
425
|
+
return {
|
|
426
|
+
payload: { ...payload, ...(session ? { process: { pid: session.pid, startedAt: session.startedAt } } : {}), ...(watched && !watched.error ? { watched: true } : {}) },
|
|
427
|
+
human: () => `Registered ${scratch ? "scratch " : ""}steward ${key} for: ${focus}\n${liveness}\nNext (MW1-94): \`nodii-dev lane gather ${key} --picker agent\`. A new focus is a lane amendment: \`nodii-dev lane amend ${key} --objective "<focus>" --reason TEXT\`.`,
|
|
428
|
+
};
|
|
280
429
|
}
|
package/dist/setup.js
CHANGED
|
@@ -19,7 +19,7 @@ description: Drive every Nodii build lane through nodii-dev from start to verifi
|
|
|
19
19
|
|
|
20
20
|
Use \`nodii-dev\` as the control plane. It talks only to Dev, through the platform edge, signed in with \`nodii-dev login\` as the platform tenant's OAuth app. The canonical policy is the build-workflow rulebook in Dev (\`nodii-dev rulebook list\`), §§1–8 (operator rulings A-020/A-021). Never change lane state in Dev by another route.
|
|
21
21
|
|
|
22
|
-
1. The machine coordinator runs \`nodii-dev coordinator start --machine NAME [--account RUNTIME:PROFILE ...]\` (each model account a lane may run on is registered once; its usage is reported then, before each launch and by the watchdog), then \`nodii-dev lane launch KEY\` with the issue (whose title is the objective), done check, build kind/side, repeated repository/branch pairs, runtime profile/model, and the lane's class (\`--class long|short|no-build\`, weighed against the account's usage band). \`--subagents N\` is optional and defaults to 4 (\`nodii-dev rules show MW1-38.15\`). A launched agent begins with \`nodii-dev lane gather\` from its worktree. Before its next action the coordinator clears what lanes wait on it for: \`nodii-dev coordinator items\` lists each item with its command (\`lane leeway grant|refuse ID\`, \`lane
|
|
22
|
+
1. The machine coordinator runs \`nodii-dev coordinator start --machine NAME [--account RUNTIME:PROFILE ...]\` (each model account a lane may run on is registered once; its usage is reported then, before each launch and by the watchdog), then \`nodii-dev lane launch KEY\` with the issue (whose title is the objective), done check, build kind/side, repeated repository/branch pairs, runtime profile/model, and the lane's class (\`--class long|short|no-build\`, weighed against the account's usage band). \`--subagents N\` is optional and defaults to 4 (\`nodii-dev rules show MW1-38.15\`). A launched agent begins with \`nodii-dev lane gather\` from its worktree. Before its next action the coordinator clears what lanes wait on it for: \`nodii-dev coordinator items\` lists each item with its command (\`lane leeway grant|refuse ID\`, \`lane defer ID --reason TEXT\`). \`lane leeway grant\` asks for no TOTP code (\`nodii-dev rules show MW1-12.7\`).
|
|
23
23
|
2. Re-run \`nodii-dev lane gather\` for the current steps and rules; start, complete, or block the reported API step with \`nodii-dev lane step\`. After an authoritative \`lane amend\`, every run is blocked until its own \`lane gather --delta\` acknowledgement. For a lane blocked on an open issue that no live lane holds, the command is \`nodii-dev lane leeway KEY --blocker ISSUE --reason TEXT\`; Dev refuses a second lane with \`LEEWAY_BLOCKER_HELD\` and names the holder, and \`lane gather --delta\` acknowledges the grant. The rules are in Dev: \`nodii-dev rules show MW1-12.6\` and \`MW1-12.8\`.
|
|
24
24
|
3. Record durable evidence with \`nodii-dev lane evidence KEY --pr|--commit|--figma|--deploy|--dev-check REF\` and heartbeat long-running work with \`nodii-dev lane heartbeat KEY --note "..."\` (notes are at most 500 characters).
|
|
25
25
|
4. Before a push or a pull request that changes a command, route, refusal code or hook, run \`nodii-dev repo docs-check\`: it reads the \`toolingDocs\` block of \`nodii.repo.yaml\`, and \`hook tooling-docs\` refuses \`git push\` and \`gh pr create|ready\` with \`TOOLING_DOCS_STALE\` on the same finding. The rule is in Dev: \`nodii-dev rules show MW1-46.3\`.
|
package/dist/starting.js
CHANGED
|
@@ -985,8 +985,8 @@ export async function currentMarker(run = execFile, load = loadJson, env = proce
|
|
|
985
985
|
return { ...marker, runId };
|
|
986
986
|
}
|
|
987
987
|
|
|
988
|
-
// An amendment, a leeway
|
|
989
|
-
const GUARD_EXEMPT_LANE_ACTIONS = new Set(["amend", "leeway", "
|
|
988
|
+
// An amendment, a leeway or its deferral, and a lane message change no brief by themselves.
|
|
989
|
+
const GUARD_EXEMPT_LANE_ACTIONS = new Set(["amend", "leeway", "defer", "message", "inbox"]);
|
|
990
990
|
|
|
991
991
|
/**
|
|
992
992
|
* MW1-12.9: what a lane hook tells a long-running session about an amendment
|
package/dist/surface.js
CHANGED
|
@@ -34,7 +34,7 @@ import { MIN_FIGMA_INTERVAL_MS, figmaRest } from "./figma-rest.js";
|
|
|
34
34
|
import { createRenderer } from "./vendor/render-templates.mjs";
|
|
35
35
|
|
|
36
36
|
/** Bumped whenever the emitted code changes shape for the same inputs. */
|
|
37
|
-
export const GENERATOR_FORMAT =
|
|
37
|
+
export const GENERATOR_FORMAT = 64;
|
|
38
38
|
/**
|
|
39
39
|
* DS parts that are an item of their parent's own list or grid, so they take no sizing
|
|
40
40
|
* wrapper: a Detail Section / Row's facts are the section grid's cells, a Right Pane / Row
|
|
@@ -1843,7 +1843,12 @@ function textNextTo(node, ctx) {
|
|
|
1843
1843
|
}
|
|
1844
1844
|
return null;
|
|
1845
1845
|
};
|
|
1846
|
-
|
|
1846
|
+
// A DS Label beside the toggle (or beside its size frame) names it through htmlFor
|
|
1847
|
+
// (pairLabelledControls), so the group's label is never borrowed over it (hub-629).
|
|
1848
|
+
const dsLabelBeside = (parent, target) =>
|
|
1849
|
+
(parent?.children ?? []).some((c) => c !== target && c.visible !== false && c.instance?.remote && c.instance.set === "Label");
|
|
1850
|
+
const labelled = dsLabelBeside(ctx.parent, node) || (ctx.grand ? dsLabelBeside(ctx.grand, ctx.parent) : false);
|
|
1851
|
+
return beside(ctx.parent, node) ?? (ctx.grand ? beside(ctx.grand, ctx.parent) : null) ?? (labelled ? null : fieldGroupLabel(ctx.slotOwner));
|
|
1847
1852
|
}
|
|
1848
1853
|
|
|
1849
1854
|
/**
|
|
@@ -3373,7 +3378,9 @@ const LABELLED_CONTROL = /<(?:Checkbox|Switch|RadioGroupItem|Textarea|Input|Sele
|
|
|
3373
3378
|
*/
|
|
3374
3379
|
function pairLabelledControls(codes) {
|
|
3375
3380
|
const out = [...codes];
|
|
3376
|
-
|
|
3381
|
+
// Only a sibling that IS a Label names a control. A container that holds Labels deeper
|
|
3382
|
+
// down (a FieldGroup's rows) pairs its own rows at its own level (hub-629).
|
|
3383
|
+
const labelOf = codes.map((c) => (/^\s*<Label\b/.test(c ?? "") ? LABEL_FOR.exec(c)?.[1] ?? null : null));
|
|
3377
3384
|
const used = new Set();
|
|
3378
3385
|
codes.forEach((code, i) => {
|
|
3379
3386
|
const control = code ? LABELLED_CONTROL.exec(code) : null;
|