@nodii/dev 0.6.175 → 0.6.176
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 +169 -19
- package/dist/accounts.js +62 -1
- package/dist/cli.js +98 -92
- package/dist/core.js +2 -2
- package/dist/flags.js +5 -1
- package/dist/freeze.js +35 -2
- package/dist/gather.js +14 -3
- package/dist/hook-handlers.js +127 -0
- package/dist/hooks.js +22 -6
- package/dist/issue-group.js +63 -0
- package/dist/lane-messages.js +313 -0
- package/dist/lane-runtime.js +7 -1
- package/dist/lane-supervisor.js +284 -19
- package/dist/lane-switches.js +32 -0
- package/dist/lanes.js +63 -15
- package/dist/managed-hooks.js +21 -2
- package/dist/nudges.js +54 -20
- package/dist/resume-gate.js +150 -0
- package/dist/runtime-launcher.js +64 -4
- package/dist/safety.js +69 -6
- package/dist/setup.js +3 -1
- package/dist/starting.js +5 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -26,18 +26,18 @@ import { FIGMA_HOOK_DENIALS, heartbeatFromHook, postHook, postHookFailure, preHo
|
|
|
26
26
|
import { setupCommand } from "./setup.js";
|
|
27
27
|
import { harnessCommand } from "./harness.js";
|
|
28
28
|
import { readPolicy, repoCommand } from "./repo-policy.js";
|
|
29
|
-
import { repoDocsCheckCommand
|
|
29
|
+
import { repoDocsCheckCommand } from "./tooling-docs.js";
|
|
30
30
|
import { testCommand } from "./impact.js";
|
|
31
|
-
import { hookRuntime, recordHookFire, safetyContext
|
|
31
|
+
import { hookRuntime, recordHookFire, safetyContext } from "./safety.js";
|
|
32
32
|
import { isLaneRunSession, isReviewSession } from "./review-session.js";
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
33
|
+
import { HOOK_ANSWERS, errorText } from "./hook-handlers.js";
|
|
34
|
+
import { SUBMIT_CHECK_FLAGS, changedPaths, nudgeStop, recordGathered, recordGuidelineRead, recordSubmitChecks, surfaceGenPre } from "./nudges.js";
|
|
35
|
+
import { firstPromptText, isLaneConfig, sessionStartText, stewardCommand } from "./session-kind.js";
|
|
35
36
|
import { doctorCommand } from "./doctor.js";
|
|
36
37
|
import { installManagedLatest, managedStatus } from "./managed-version.js";
|
|
37
38
|
import { dispatchManagedClaudeHook, dispatchManagedHook } from "./managed-hooks.js";
|
|
38
39
|
import { governorCommand, laneClose } from "./governor.js";
|
|
39
40
|
import { freezeCommand } from "./freeze.js";
|
|
40
|
-
import { laneReadCache } from "./read-cache.js";
|
|
41
41
|
import {
|
|
42
42
|
figmaChangeSetShow,
|
|
43
43
|
figmaChangeSetList,
|
|
@@ -139,8 +139,11 @@ import {
|
|
|
139
139
|
import { superviseLane } from "./lane-supervisor.js";
|
|
140
140
|
import { laneLeewayCommand } from "./leeway.js";
|
|
141
141
|
import { laneAnswerCommand, laneAskCommand, laneAsksCommand, laneDeferCommand } from "./lane-asks.js";
|
|
142
|
+
import { laneInboxCommand, laneMessageCommand } from "./lane-messages.js";
|
|
142
143
|
import { coordinatorGate, coordinatorItemsCommand, observeLaneItems, resetLaneItemsNotice, takeLaneItemsLine } from "./coordinator-items.js";
|
|
143
144
|
import { awsCli, superviseRemoteRun } from "./remote.js";
|
|
145
|
+
import { issueGroupText, proposeIssueSet } from "./issue-group.js";
|
|
146
|
+
import { assertLaneSwitchOn } from "./lane-switches.js";
|
|
144
147
|
|
|
145
148
|
const NOTICE_KINDS = ["lane_wait", "lane_escalation", "credential_expiry"];
|
|
146
149
|
const LANE_RUN_HOOKS = new Set(["nudge-pre", "nudge-stop", "lane-heartbeat", "session-start", "session-kind", "workflow-post"]);
|
|
@@ -162,6 +165,14 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
162
165
|
agent disconnect ID # retire one of your agents (there is no delete); its id
|
|
163
166
|
# can't be used again
|
|
164
167
|
issues list|show|create|update|claim|release
|
|
168
|
+
issues group --objective TEXT [--service ID ...] [--min N>=10] [--max N]
|
|
169
|
+
# OFF unless NODII_DEV_ISSUES_GROUP=1 (NODII-DEV-CLI-191: off until its clause
|
|
170
|
+
# is in Dev's rulebook); off, it refuses ISSUES_GROUP_OFF and calls nothing. On:
|
|
171
|
+
# NODII-DEV-CLI-191 (MW1-21.1): propose a lane's issue set from the open
|
|
172
|
+
# issues: titles that share the objective's terms (rarer terms weigh more)
|
|
173
|
+
# plus the dependency chain (an issue naming a picked one), with each
|
|
174
|
+
# issue's reason, the repos they touch and the lane launch line; under
|
|
175
|
+
# --min (10) it says so and never pads. It proposes; nothing is written
|
|
165
176
|
issues comment ISSUE --body TEXT # or --body-file FILE; issues update --comment TEXT|--comment-file FILE adds one too
|
|
166
177
|
issues transition ISSUE --to STATUS [--reason TEXT] [--dev-check REF]
|
|
167
178
|
# blocked and wont_do need --reason; done needs --dev-check
|
|
@@ -538,6 +549,21 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
538
549
|
# MW1-12.9: a lane asks its machine coordinator a question. The answer
|
|
539
550
|
# reaches it as an amendment it acknowledges with lane gather --delta;
|
|
540
551
|
# lane ask withdraw <ask id> takes the question back
|
|
552
|
+
lane message <to> --body TEXT|--body-file FILE [--issue ISSUE]
|
|
553
|
+
# OFF unless NODII_DEV_LANE_MESSAGES=1 (off until its clause is in Dev's
|
|
554
|
+
# rulebook): lane message and lane inbox then refuse LANE_MESSAGES_OFF and
|
|
555
|
+
# call nothing, and no hook delivers from an inbox file. On:
|
|
556
|
+
# NODII-DEV-CLI-191: message a lane, a steward (its lane key) or the
|
|
557
|
+
# coordinator by name. Dev keeps the record: a comment on the recipient
|
|
558
|
+
# lane's issue (the coordinator's: the sending lane's; --issue overrides),
|
|
559
|
+
# headed "[lane message] from <sender> to <to> · <time> · id <id>". When <to>
|
|
560
|
+
# runs on this machine its inbox (<config dir>/inbox/<key>.jsonl) rings too.
|
|
561
|
+
# The sender is the session's identity: its lane, else its Dev agent's name.
|
|
562
|
+
# A lane gets an unread message at its next tool call (nudge-pre), its next
|
|
563
|
+
# stop (the Stop hook holds it) or its next continuation (the supervisor
|
|
564
|
+
# puts it ahead of the prompt), Claude and Codex alike
|
|
565
|
+
lane inbox [<key>] [--all] # the unread messages (--all: every one), marked read; also pulls in Dev's
|
|
566
|
+
# record of messages sent from another machine
|
|
541
567
|
lane answer <ask id> --text TEXT # the coordinator (or staff) answers; Dev delivers it as that amendment
|
|
542
568
|
lane defer <ask or leeway id> --reason TEXT [--minutes N] [--leeway]
|
|
543
569
|
# the coordinator puts an ask or a leeway off, with a reason, for N minutes
|
|
@@ -561,6 +587,25 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
561
587
|
# account's band doesn't admit the class (ACCOUNT_BAND_REFUSED). The lane keeps its
|
|
562
588
|
# key, branch, worktree, slot and history. A lane stopped by two deaths moves off
|
|
563
589
|
# an exhausted account with no amendment or override
|
|
590
|
+
# NODII-DEV-CLI-191: a run that died on a usage limit, auth or the network is
|
|
591
|
+
# reported lane-account-KIND and its profile recorded exhausted until its reset
|
|
592
|
+
# (else 5 h for a limit, 1 h otherwise) in exhausted-accounts.json. Any lane resume
|
|
593
|
+
# then moves the lane to another account of its runtime with headroom, saying so,
|
|
594
|
+
# or refuses ACCOUNT_EXHAUSTED; --profile naming another account still goes
|
|
595
|
+
lane resume <key> --if-changed
|
|
596
|
+
# OFF unless NODII_DEV_RESUME_IF_CHANGED=1 (off until its clause is in Dev's
|
|
597
|
+
# rulebook); off, it refuses RESUME_IF_CHANGED_OFF and resumes nothing. On:
|
|
598
|
+
# NODII-DEV-CLI-191: resume only when what blocks the lane changed since its
|
|
599
|
+
# last resume (a PR's state, head or merge; an issue's status; a blocking
|
|
600
|
+
# lane's status; a leeway; an amendment), else print BLOCKERS_UNCHANGED and
|
|
601
|
+
# exit 0. A superseded lane (every issue it holds closed) is refused as
|
|
602
|
+
# LANE_DEAD with the evidence; nothing stops it here: the coordinator ends it
|
|
603
|
+
# by the MW1-28 exit that fits.
|
|
604
|
+
# A lane whose work is landed (MW1-30.1) before deploy is refused as
|
|
605
|
+
# LANDED_NOT_DONE and never stopped: landed is not done (MW1-28), so it goes
|
|
606
|
+
# on to deploy and the dev check. With NODII_DEV_SAME_SESSION_RESUME=1, a resume
|
|
607
|
+
# continues the dead run's own session when this machine has its log, with a
|
|
608
|
+
# short prompt instead of the Freeze; off (the default) it starts fresh as before
|
|
564
609
|
lane resume --host-lost [--min-free-gb N] [--stagger-seconds N]
|
|
565
610
|
# coordinator, after a reboot: resume every host_lost lane on this machine
|
|
566
611
|
# in priority order under its own key, agent, worktree and branch. No
|
|
@@ -680,7 +725,7 @@ notification-registry, skills, open-questions, decisions, drift, requests,
|
|
|
680
725
|
rulebook, ad-decisions, domains, standardizations, archive, harness, utils,
|
|
681
726
|
runs, releases, and operate.
|
|
682
727
|
|
|
683
|
-
Refusals of leeway, lane questions, the coordinator's items, lane finish, the managed hooks and the docs check
|
|
728
|
+
Refusals of leeway, lane questions, the coordinator's items, lane finish, lane resume, the managed hooks and the docs check
|
|
684
729
|
(each line: the code, what it means, and what to do next):
|
|
685
730
|
LEEWAY_BLOCKER_HELD Another live lane already holds leeway for this blocker; Dev names it and records your wait on it. Next: keep working what is not blocked and resume when the holder lands
|
|
686
731
|
LEEWAY_BRANCH_HELD Another live lane is already working this issue as its own, so its in-flight branch is not yours to change (MW1-12.8). Next: wait on that lane with lane heartbeat KEY --waiting-on LANE
|
|
@@ -704,10 +749,14 @@ Refusals of leeway, lane questions, the coordinator's items, lane finish, the ma
|
|
|
704
749
|
LANE_NOTES_FULL The grant's or answer's note would take the lane past its note cap. Next: fold superseded amendments into one note first (lane amendments fold)
|
|
705
750
|
MACHINE_REQUIRED The caller coordinates no machine, so Dev cannot tell whose items or asks to list. Next: pass --machine NAME|ID
|
|
706
751
|
LANE_ASKS_OFF lane ask, lane answer or lane asks while lane questions are off (the default). Next: write the question as an issue comment or a heartbeat note; NODII_DEV_LANE_ASKS=1 turns the commands on
|
|
752
|
+
RESUME_IF_CHANGED_OFF lane resume --if-changed while it is off (the default). Next: resume without it, as before; NODII_DEV_RESUME_IF_CHANGED=1 turns it on
|
|
753
|
+
LANE_MESSAGES_OFF lane message or lane inbox while lane messages are off (the default). Next: write to the other lane as a comment on its issue; NODII_DEV_LANE_MESSAGES=1 turns them on
|
|
754
|
+
ISSUES_GROUP_OFF issues group while it is off (the default). Next: choose the lane's issue set by hand with issues list; NODII_DEV_ISSUES_GROUP=1 turns it on
|
|
707
755
|
ASK_NOT_FOUND Dev has no lane ask with this id. Next: list them with lane asks
|
|
708
756
|
ASK_DECIDED The ask is already answered or withdrawn. Next: read it with lane asks --lane KEY
|
|
709
757
|
LANE_NOT_FINISHED lane close before the lane's own agent marked the lane finished. Next: the lane runs lane finish KEY --reason TEXT --evidence REF
|
|
710
758
|
LANE_ALREADY_FINISHED The lane is already marked finished. Next: nothing; its coordinator closes it with lane close
|
|
759
|
+
ACCOUNT_EXHAUSTED lane resume would relaunch onto a profile whose last run died on a usage limit, auth or the network, before its recorded reset, and no other account of its runtime has headroom. Next: resume after the reset it names, or move it with lane resume KEY --profile PATH --class CLASS
|
|
711
760
|
HARNESS_INVALID A managed hook entry is not one nodii-dev command, or Dev's harness cannot take the managed hooks. Next: run harness update, and file the entry as a harness issue
|
|
712
761
|
HARNESS_SETTINGS_INVALID .claude/settings.json or .codex/hooks.json is not valid JSON. Next: repair the file, then run harness update
|
|
713
762
|
TOOLING_DOCS_STALE The change touches a tooling file named in nodii.repo.yaml (toolingDocs.tooling) and no docs file (toolingDocs.docs), so hook tooling-docs refuses the push or the pull request (MW1-46.3). Next: update the docs in the same change, or add the commit trailer Docs-unaffected: <reason>; check with repo docs-check
|
|
@@ -795,6 +844,28 @@ async function login(flags, json) {
|
|
|
795
844
|
}
|
|
796
845
|
|
|
797
846
|
async function issues(action, args, f, json) {
|
|
847
|
+
if (action === "group") {
|
|
848
|
+
assertLaneSwitchOn("issuesGroup", "ISSUES_GROUP_OFF", "issues group", "Choose the lane's issue set by hand with issues list.");
|
|
849
|
+
const objective = typeof f.objective === "string" ? f.objective.trim() : "";
|
|
850
|
+
if (!objective) throw new CliError("USAGE", "issues group needs --objective TEXT: the lane's rough objective.", 2);
|
|
851
|
+
const min = f.min === undefined ? 10 : Number(f.min);
|
|
852
|
+
const max = f.max === undefined ? 30 : Number(f.max);
|
|
853
|
+
// MW1-21.1: a lane has 10 or more mapped issues, so the minimum never goes below it.
|
|
854
|
+
if (!Number.isInteger(min) || !Number.isInteger(max) || min < 10 || max < min || max > 100) throw new CliError("USAGE", "--min and --max are integers with 10 <= min <= max <= 100 (MW1-21.1: a lane has 10 or more issues).", 2);
|
|
855
|
+
const services = (Array.isArray(f.service) ? f.service : f.service === undefined ? [undefined] : [f.service]);
|
|
856
|
+
const all = [];
|
|
857
|
+
for (const service of services) {
|
|
858
|
+
let cursor;
|
|
859
|
+
for (let page = 0; page < 20; page += 1) {
|
|
860
|
+
const payload = await devRequest("GET", `/api/v1/issues${query({ ...(service ? { serviceId: service } : {}), limit: "100", ...(cursor ? { cursor } : {}) })}`);
|
|
861
|
+
all.push(...(payload.data ?? []));
|
|
862
|
+
cursor = payload.nextCursor;
|
|
863
|
+
if (!cursor) break;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
const set = proposeIssueSet(objective, all, { min, max });
|
|
867
|
+
return emit({ data: { objective, ...set } }, json, () => issueGroupText(set, { objective, min }));
|
|
868
|
+
}
|
|
798
869
|
if (action === "list") {
|
|
799
870
|
const payload = await devRequest(
|
|
800
871
|
"GET",
|
|
@@ -987,13 +1058,14 @@ export async function figmaFileAdd(value, flags, { request = devRequest } = {})
|
|
|
987
1058
|
// blocks the lane: a blocked lane needs them to unblock itself (AGENT-HARNESS-14).
|
|
988
1059
|
const readsHelp = (argv) => argv[0] === "help" || argv.some((token) => ["--help", "-h"].includes(token)) || (argv.length === 1 && ["--version", "-v"].includes(argv[0]));
|
|
989
1060
|
|
|
990
|
-
//
|
|
991
|
-
//
|
|
992
|
-
//
|
|
993
|
-
//
|
|
994
|
-
//
|
|
995
|
-
//
|
|
996
|
-
|
|
1061
|
+
// Amendment acknowledgement (CTRL-CLI-34) and waiting Results (MW5-16) are a
|
|
1062
|
+
// lane-wide backstop for every command the agent runs, read fresh from Dev each
|
|
1063
|
+
// time. No hook runs it (NODII-DEV-CLI-191): a hook cannot enforce it, since
|
|
1064
|
+
// it exits 0 on anything but a SAFETY_ or Figma denial (a pending amendment
|
|
1065
|
+
// failed the hook, which then skipped its own safety check), and its banner is
|
|
1066
|
+
// never claimed. A lane learns of an amendment from nudge-pre's context
|
|
1067
|
+
// instead (MW1-12.9). The managed hooks paid this read on every tool call.
|
|
1068
|
+
export const runsBackstop = (argv) => argv[0] !== "hook" && argv[0] !== "__run-supervisor" && !readsHelp(argv);
|
|
997
1069
|
|
|
998
1070
|
export async function main(argv = process.argv.slice(2)) {
|
|
999
1071
|
// Ahead of every check that reaches Dev: a session the lane spawned gets
|
|
@@ -1005,16 +1077,9 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1005
1077
|
setLaneItemsObserver(argv[0] === "hook" || argv[0]?.startsWith("__") ? null : observeLaneItems);
|
|
1006
1078
|
// A lane's own exit reporter runs after its runtime ends (NODII-DEV-CLI-1).
|
|
1007
1079
|
if (argv[0] === "__lane-supervisor") return superviseLane();
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
// surface-gen-pre runs in every session, lane or not, so it never reaches Dev.
|
|
1012
|
-
// The heartbeat hook fires on every tool call, so these checks would call Dev each
|
|
1013
|
-
// time past its rate limit, and a failed check would silently stop the heartbeat.
|
|
1014
|
-
if (argv[0] !== "__run-supervisor" && !readsHelp(argv) && !(argv[0] === "hook" && (argv[1]?.startsWith("nudge-") || argv[1] === "surface-gen-pre" || argv[1] === "coordinator-gate" || argv[1] === "tooling-docs" || argv[1] === "lane-heartbeat"))) {
|
|
1015
|
-
const cache = backstopCache(argv);
|
|
1016
|
-
await amendmentGuard(argv, { cache });
|
|
1017
|
-
await showWaitingResults({ acknowledge: argv[0] !== "hook", cache });
|
|
1080
|
+
if (runsBackstop(argv)) {
|
|
1081
|
+
await amendmentGuard(argv);
|
|
1082
|
+
await showWaitingResults();
|
|
1018
1083
|
}
|
|
1019
1084
|
if (argv.length === 1 && ["--version", "-v"].includes(argv[0]))
|
|
1020
1085
|
return console.log(VERSION);
|
|
@@ -1262,6 +1327,8 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1262
1327
|
if (command === "lane" && action === "asks") return emitCommand(await laneAsksCommand(rest, f));
|
|
1263
1328
|
if (command === "lane" && action === "answer") return emitCommand(await laneAnswerCommand(rest, f));
|
|
1264
1329
|
if (command === "lane" && action === "defer") return emitCommand(await laneDeferCommand(rest, f));
|
|
1330
|
+
if (command === "lane" && action === "message") return emitCommand(await laneMessageCommand(rest, f));
|
|
1331
|
+
if (command === "lane" && action === "inbox") return emitCommand(await laneInboxCommand(rest, f));
|
|
1265
1332
|
if (command === "lane" && action === "cap") return emitCommand(await laneCapCommand(rest, f));
|
|
1266
1333
|
if (command === "lane" && action === "close") {
|
|
1267
1334
|
const result = await laneClose(rest[0], f);
|
|
@@ -1807,63 +1874,13 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1807
1874
|
);
|
|
1808
1875
|
}
|
|
1809
1876
|
}
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
// Both runtimes show the model a PreToolUse nudge only as additionalContext;
|
|
1818
|
-
// Claude keeps plain stdout of an exit-0 hook out of the model's context.
|
|
1819
|
-
if (nudges.length)
|
|
1820
|
-
console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: "PreToolUse", additionalContext: nudges.join("\n") } }));
|
|
1821
|
-
return;
|
|
1822
|
-
} catch (error) {
|
|
1823
|
-
// Only an evaluated safety rule may deny. Discovery, parsing, git,
|
|
1824
|
-
// config and Dev errors fail open and produce no output.
|
|
1825
|
-
if (!String(error?.code ?? "").startsWith("SAFETY_")) return;
|
|
1826
|
-
if (payload && hookRuntime(payload) === "codex") {
|
|
1827
|
-
console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "deny", permissionDecisionReason: error?.message ?? String(error) } }));
|
|
1828
|
-
return;
|
|
1829
|
-
}
|
|
1830
|
-
throw new CliError(
|
|
1831
|
-
error?.code ?? "SAFETY_HOOK_FAILED",
|
|
1832
|
-
error?.message ?? String(error),
|
|
1833
|
-
2,
|
|
1834
|
-
error?.details,
|
|
1835
|
-
);
|
|
1836
|
-
}
|
|
1837
|
-
}
|
|
1838
|
-
if (action === "safety-post") {
|
|
1839
|
-
let payload;
|
|
1840
|
-
try {
|
|
1841
|
-
payload = JSON.parse(await stdinText());
|
|
1842
|
-
await recordHookFire(payload).catch(() => {});
|
|
1843
|
-
await safetyPostHook(payload);
|
|
1844
|
-
} catch {}
|
|
1845
|
-
return;
|
|
1846
|
-
}
|
|
1847
|
-
// Guideline nudges (AGENT-HARNESS-21) never block: any error, a payload
|
|
1848
|
-
// they don't know or a session outside a lane ends in no output.
|
|
1849
|
-
if (action === "nudge-pre") {
|
|
1850
|
-
try {
|
|
1851
|
-
const payload = JSON.parse(await stdinText());
|
|
1852
|
-
await recordHookFire(payload).catch(() => {});
|
|
1853
|
-
// Cite before you steer (MW1-95): a steward session, which is never a lane config.
|
|
1854
|
-
if (!isLaneConfig() && steerAct(payload)) {
|
|
1855
|
-
const config = await readConfig(false).catch(() => null);
|
|
1856
|
-
const steward = await activeSteward(config?.agentId).catch(() => null);
|
|
1857
|
-
const nudges = await stewardSteerNudges(payload, { steward });
|
|
1858
|
-
if (nudges.length) console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: "PreToolUse", additionalContext: nudges.join("\n") } }));
|
|
1859
|
-
if (steward) return;
|
|
1860
|
-
}
|
|
1861
|
-
// MW1-12.9: a lane that has not acknowledged an amendment (an answer, a leeway grant) is told here.
|
|
1862
|
-
const pending = isLaneConfig() ? await pendingAmendmentContext() : null;
|
|
1863
|
-
const nudges = (await nudgeCandidate(payload)) ? await nudgePre(payload, await safetyContext(payload.cwd ?? process.cwd())).catch(() => []) : [];
|
|
1864
|
-
const context = [pending, ...nudges].filter(Boolean);
|
|
1865
|
-
if (context.length) console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: "PreToolUse", additionalContext: context.join("\n") } }));
|
|
1866
|
-
} catch {}
|
|
1877
|
+
// safety-pre, safety-post, nudge-pre and tooling-docs (MW1-46.3). The managed
|
|
1878
|
+
// dispatcher runs them in its own process (NODII-DEV-CLI-191); here
|
|
1879
|
+
// each answers as its own process: its lines, and a denial as exit 2.
|
|
1880
|
+
if (Object.hasOwn(HOOK_ANSWERS, action)) {
|
|
1881
|
+
const { lines, denial } = await HOOK_ANSWERS[action](await stdinText());
|
|
1882
|
+
for (const text of lines) console.log(text);
|
|
1883
|
+
if (denial) throw denial;
|
|
1867
1884
|
return;
|
|
1868
1885
|
}
|
|
1869
1886
|
// MW1-37.2: the coordinator gate, as its own hook. The managed dispatcher
|
|
@@ -1877,15 +1894,6 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1877
1894
|
} catch {}
|
|
1878
1895
|
return;
|
|
1879
1896
|
}
|
|
1880
|
-
// MW1-46.3: docs move with tooling. Reads git only, never Dev; any error is
|
|
1881
|
-
// no output, so a broken check never holds a push.
|
|
1882
|
-
if (action === "tooling-docs") {
|
|
1883
|
-
try {
|
|
1884
|
-
const verdict = await toolingDocsHook(JSON.parse(await stdinText()));
|
|
1885
|
-
if (verdict?.deny) console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "deny", permissionDecisionReason: verdict.deny } }));
|
|
1886
|
-
} catch {}
|
|
1887
|
-
return;
|
|
1888
|
-
}
|
|
1889
1897
|
// MW8-17, for every session (the managed dispatcher calls it outside lanes
|
|
1890
1898
|
// too): reads only the edit, never blocks, and any error is no output.
|
|
1891
1899
|
if (action === "surface-gen-pre") {
|
|
@@ -1995,8 +2003,6 @@ export function fail(error) {
|
|
|
1995
2003
|
error instanceof CliError
|
|
1996
2004
|
? error
|
|
1997
2005
|
: new CliError("UNEXPECTED", error?.message ?? String(error));
|
|
1998
|
-
console.error(
|
|
1999
|
-
`${e.code}: ${e.message}${e.details ? `\n${JSON.stringify(e.details)}` : ""}`,
|
|
2000
|
-
);
|
|
2006
|
+
console.error(errorText(e));
|
|
2001
2007
|
process.exitCode = e.exitCode ?? 1;
|
|
2002
2008
|
}
|
package/dist/core.js
CHANGED
|
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
4
4
|
import { homedir, platform } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
|
|
7
|
-
export const VERSION = "0.6.
|
|
7
|
+
export const VERSION = "0.6.176";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
|
@@ -405,7 +405,7 @@ export async function checkLogin() {
|
|
|
405
405
|
export const encode = (value) => encodeURIComponent(value);
|
|
406
406
|
// Switches never take the next token as their value, so
|
|
407
407
|
// `docs upload --wait rulebook/` keeps rulebook/ as a path.
|
|
408
|
-
const SWITCHES = new Set(["all-pending", "confirm-raise", "actionable", "json", "wait", "pending", "dry-run", "check", "all", "fleet", "help", "yes", "mine", "no-browser", "include-drafts", "drafted", "library", "async", "sync", "force", "system", "delta", "probe", "no-probe", "not-required", "override", "critical", "no-embed", "behind", "write", "fetch"]);
|
|
408
|
+
const SWITCHES = new Set(["all-pending", "confirm-raise", "actionable", "json", "wait", "pending", "dry-run", "check", "all", "fleet", "help", "yes", "mine", "no-browser", "include-drafts", "drafted", "library", "async", "sync", "force", "system", "delta", "probe", "no-probe", "not-required", "override", "critical", "no-embed", "behind", "write", "fetch", "if-changed"]);
|
|
409
409
|
export function parseArgs(argv) {
|
|
410
410
|
const flags = {};
|
|
411
411
|
const args = [];
|
package/dist/flags.js
CHANGED
|
@@ -19,6 +19,9 @@ export const COMMAND_FLAGS = {
|
|
|
19
19
|
"lane ask": ["question", "options"],
|
|
20
20
|
"lane asks": ["machine", "state", "lane", "cursor", "limit"],
|
|
21
21
|
"lane answer": ["text"],
|
|
22
|
+
// NODII-DEV-CLI-191: lane-to-lane messaging.
|
|
23
|
+
"lane message": [...BODY, "issue"],
|
|
24
|
+
"lane inbox": ["all"],
|
|
22
25
|
"lane defer": ["reason", "minutes", "leeway"],
|
|
23
26
|
"coordinator heartbeat": ["machine", "run", "pid", "pid-started-at", "interval"],
|
|
24
27
|
"issues create": ["service", ...ISSUE_FIELDS],
|
|
@@ -26,6 +29,7 @@ export const COMMAND_FLAGS = {
|
|
|
26
29
|
"issues transition": ["to", "reason", "dev-check"],
|
|
27
30
|
"issues comment": BODY,
|
|
28
31
|
"issues claim": ["ttl"],
|
|
32
|
+
"issues group": ["objective", "service", "min", "max"],
|
|
29
33
|
"issues release": ["note"],
|
|
30
34
|
"lane launch": [
|
|
31
35
|
"machine", "coordinator-run", "machine-id", "repo", "branch", "base", "worktree", "owned-path",
|
|
@@ -48,7 +52,7 @@ export const COMMAND_FLAGS = {
|
|
|
48
52
|
"lane cap": ["confirm-raise", "reason"],
|
|
49
53
|
"lane heartbeat": ["note", "waiting-on"],
|
|
50
54
|
"lane waits": ["machine"],
|
|
51
|
-
"lane resume": ["override", "reason", "host-lost", "min-free-gb", "stagger-seconds", "profile", "class"],
|
|
55
|
+
"lane resume": ["override", "reason", "host-lost", "min-free-gb", "stagger-seconds", "profile", "class", "if-changed"],
|
|
52
56
|
"lane transfer": ["reason", "to-agent"],
|
|
53
57
|
"inbox ack": ["note"],
|
|
54
58
|
"lane stop": ["reason", "sweeper", "no-closeout", "no-closeout-push", "launched-in-error", "replaced-by"],
|
package/dist/freeze.js
CHANGED
|
@@ -108,12 +108,42 @@ function checkedGatherClauses(clauses) {
|
|
|
108
108
|
|
|
109
109
|
export const GATHER_LOOKUP_IDS = ["figma-guidelines"];
|
|
110
110
|
|
|
111
|
+
// NODII-DEV-CLI-191: a Dev before hub d14dbbde caps a Freeze's issue body at
|
|
112
|
+
// 20,000 characters and each lane note at 4,000, though its Lane contract
|
|
113
|
+
// carries longer ones. Dev stores the body only as its first-sentence gist
|
|
114
|
+
// (AGENT-HARNESS-45), so sending the body cut to the cap loses nothing it
|
|
115
|
+
// stores; a long note goes as consecutive notes, split between words.
|
|
116
|
+
export const FREEZE_ISSUE_BODY_SEND_MAX = 20_000;
|
|
117
|
+
export const FREEZE_LANE_NOTE_SEND_MAX = 4_000;
|
|
118
|
+
|
|
119
|
+
function issueWithinCap(issue) {
|
|
120
|
+
if (!issue?.body || issue.body.length <= FREEZE_ISSUE_BODY_SEND_MAX) return issue;
|
|
121
|
+
return { ...issue, body: issue.body.slice(0, FREEZE_ISSUE_BODY_SEND_MAX).trimEnd() };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function notesWithinCap(notes) {
|
|
125
|
+
return notes.flatMap((note) => {
|
|
126
|
+
if (typeof note !== "string" || note.length <= FREEZE_LANE_NOTE_SEND_MAX) return [note];
|
|
127
|
+
const parts = [];
|
|
128
|
+
let rest = note;
|
|
129
|
+
while (rest.length > FREEZE_LANE_NOTE_SEND_MAX) {
|
|
130
|
+
const space = rest.lastIndexOf(" ", FREEZE_LANE_NOTE_SEND_MAX);
|
|
131
|
+
const cut = space > 0 ? space : FREEZE_LANE_NOTE_SEND_MAX;
|
|
132
|
+
parts.push(rest.slice(0, cut));
|
|
133
|
+
rest = rest.slice(space > 0 ? cut + 1 : cut);
|
|
134
|
+
}
|
|
135
|
+
if (rest) parts.push(rest);
|
|
136
|
+
return parts;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
111
140
|
/** Build the stored contract; Delta Gather keeps lane-authored sections. */
|
|
112
141
|
export function freezeFromGather({
|
|
113
142
|
gather,
|
|
114
143
|
ask,
|
|
115
144
|
boundaries,
|
|
116
145
|
issue,
|
|
146
|
+
issueSet,
|
|
117
147
|
laneNotes,
|
|
118
148
|
doneCheck,
|
|
119
149
|
lookups = [],
|
|
@@ -136,11 +166,14 @@ export function freezeFromGather({
|
|
|
136
166
|
objective: {
|
|
137
167
|
// Dev's Lane contract names the ask; without one, Gather's objective.
|
|
138
168
|
ask: ask ?? gather.objective,
|
|
139
|
-
issue: issue === undefined ? (current?.objective?.issue ?? null) : issue,
|
|
140
|
-
|
|
169
|
+
issue: issueWithinCap(issue === undefined ? (current?.objective?.issue ?? null) : issue),
|
|
170
|
+
// NODII-DEV-CLI-191: the lane's other mapped issues, keys and titles only.
|
|
171
|
+
...((issueSet ?? current?.objective?.issueSet)?.length ? { issueSet: issueSet ?? current.objective.issueSet } : {}),
|
|
172
|
+
laneNotes: notesWithinCap(
|
|
141
173
|
laneNotes === undefined
|
|
142
174
|
? (current?.objective?.laneNotes ?? [])
|
|
143
175
|
: laneNotes,
|
|
176
|
+
),
|
|
144
177
|
doneCheck: effectiveDoneCheck,
|
|
145
178
|
},
|
|
146
179
|
boundaries,
|
package/dist/gather.js
CHANGED
|
@@ -581,9 +581,20 @@ const tags = (clause) => {
|
|
|
581
581
|
return parts.length ? ` [${parts.join("; ")}]` : "";
|
|
582
582
|
};
|
|
583
583
|
|
|
584
|
+
// A breadcrumb names where a clause sits; a SWAP breadcrumb carries the whole
|
|
585
|
+
// swap (24 KB across one lane's map), which `rules show <ID>` prints in full.
|
|
586
|
+
const CRUMB_MAX = 160;
|
|
587
|
+
const crumb = (text) => {
|
|
588
|
+
const flat = String(text ?? "").replace(/\s+/g, " ").trim();
|
|
589
|
+
return flat.length <= CRUMB_MAX ? flat : `${flat.slice(0, CRUMB_MAX - 1).trimEnd()}…`;
|
|
590
|
+
};
|
|
591
|
+
|
|
584
592
|
export function gatherText(payload, objective = "", reasons = {}) {
|
|
585
593
|
const data = payload?.data ?? payload ?? {};
|
|
586
|
-
|
|
594
|
+
// NODII-DEV-CLI-191: the objective and lane notes are in the contract
|
|
595
|
+
// above; the header no longer repeats them as JSON (4.7 KB on a long lane).
|
|
596
|
+
void objective;
|
|
597
|
+
const lines = ["Lane contract", data.laneContract ?? LANE_CONTRACT, "", "Clause map"];
|
|
587
598
|
for (const notice of data.notices ?? []) lines.push(`Notice: ${notice}`);
|
|
588
599
|
const documents = new Map();
|
|
589
600
|
for (const clause of data.clauses ?? []) {
|
|
@@ -597,13 +608,13 @@ export function gatherText(payload, objective = "", reasons = {}) {
|
|
|
597
608
|
const why = reasons instanceof Map ? reasons.get(document.code) : reasons[document.code];
|
|
598
609
|
lines.push(`${document.code}${why ? ` ← ${why}` : ""}`);
|
|
599
610
|
for (const section of document.sections.values()) {
|
|
600
|
-
lines.push(` ${section.breadcrumb}`);
|
|
611
|
+
lines.push(` ${crumb(section.breadcrumb)}`);
|
|
601
612
|
for (const clause of section.clauses)
|
|
602
613
|
lines.push(` ${clause.clauseId} ${clause.gist}${clause.counterInstinct ? " ⚑" : ""}${tags(clause)}`.trimEnd());
|
|
603
614
|
}
|
|
604
615
|
}
|
|
605
616
|
if (!documents.size) lines.push(" No clauses matched.");
|
|
606
|
-
lines.push("", 'Not sure something applies? nodii-dev rules find "<question>"');
|
|
617
|
+
lines.push("", 'Read a clause in full with `nodii-dev rules show <ID>`. Not sure something applies? nodii-dev rules find "<question>"');
|
|
607
618
|
return lines.join("\n");
|
|
608
619
|
}
|
|
609
620
|
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { CliError, readConfig } from "./core.js";
|
|
2
|
+
import { unsupervisedHeartbeat } from "./hooks.js";
|
|
3
|
+
import { nudgeCandidate, nudgePre, steerAct, stewardSteerNudges } from "./nudges.js";
|
|
4
|
+
import { isLaneRunSession, isReviewSession } from "./review-session.js";
|
|
5
|
+
import { hookRuntime, recordHookFire, safetyContext, safetyPostHook, safetyPreHook } from "./safety.js";
|
|
6
|
+
import { activeSteward, isLaneConfig } from "./session-kind.js";
|
|
7
|
+
import { toolingDocsHook } from "./tooling-docs.js";
|
|
8
|
+
import { pendingAmendmentContext } from "./starting.js";
|
|
9
|
+
import { inboxHookContext } from "./lane-messages.js";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* NODII-DEV-CLI-191: the hook handlers the managed dispatcher runs in its
|
|
13
|
+
* own process instead of starting `nodii-dev hook ACTION` for each. `hook
|
|
14
|
+
* ACTION` runs the same functions, so both answer alike: the stdout lines, and
|
|
15
|
+
* for Claude a denial raised as exit 2 with its reason on stderr.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const line = (event, fields) => JSON.stringify({ hookSpecificOutput: { hookEventName: event, ...fields } });
|
|
19
|
+
|
|
20
|
+
/** What `fail` prints for an error: the dispatcher reads it as a denial's reason. */
|
|
21
|
+
export const errorText = (error) => `${error.code}: ${error.message}${error.details ? `\n${JSON.stringify(error.details)}` : ""}`;
|
|
22
|
+
|
|
23
|
+
/** `hook safety-pre`. Only an evaluated safety rule may deny; every other failure is no output. */
|
|
24
|
+
export async function safetyPreAnswer(payloadText) {
|
|
25
|
+
let payload;
|
|
26
|
+
try {
|
|
27
|
+
payload = JSON.parse(payloadText);
|
|
28
|
+
await recordHookFire(payload).catch(() => {});
|
|
29
|
+
const nudges = (await safetyPreHook(payload)).nudges ?? [];
|
|
30
|
+
// Both runtimes show the model a PreToolUse nudge only as additionalContext;
|
|
31
|
+
// Claude keeps plain stdout of an exit-0 hook out of the model's context.
|
|
32
|
+
return { lines: nudges.length ? [line("PreToolUse", { additionalContext: nudges.join("\n") })] : [] };
|
|
33
|
+
} catch (error) {
|
|
34
|
+
// Discovery, parsing, git, config and Dev errors fail open and produce no output.
|
|
35
|
+
if (!String(error?.code ?? "").startsWith("SAFETY_")) return { lines: [] };
|
|
36
|
+
if (payload && hookRuntime(payload) === "codex")
|
|
37
|
+
return { lines: [line("PreToolUse", { permissionDecision: "deny", permissionDecisionReason: error?.message ?? String(error) })] };
|
|
38
|
+
return { lines: [], denial: new CliError(error?.code ?? "SAFETY_HOOK_FAILED", error?.message ?? String(error), 2, error?.details) };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** `hook safety-post`: records, never answers. */
|
|
43
|
+
export async function safetyPostAnswer(payloadText) {
|
|
44
|
+
try {
|
|
45
|
+
const payload = JSON.parse(payloadText);
|
|
46
|
+
await recordHookFire(payload).catch(() => {});
|
|
47
|
+
await safetyPostHook(payload);
|
|
48
|
+
} catch {}
|
|
49
|
+
return { lines: [] };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* `hook nudge-pre`. Guideline nudges (AGENT-HARNESS-21) never block: any error,
|
|
54
|
+
* a payload they don't know or a session outside a lane ends in no output.
|
|
55
|
+
* It also carries the tool-call heartbeat of a session no lane supervisor
|
|
56
|
+
* beats for, at most once per 5 minutes (NODII-DEV-CLI-191).
|
|
57
|
+
*/
|
|
58
|
+
export async function nudgePreAnswer(payloadText, { heartbeat = unsupervisedHeartbeat } = {}) {
|
|
59
|
+
const lines = [];
|
|
60
|
+
let beat = null;
|
|
61
|
+
try {
|
|
62
|
+
const payload = JSON.parse(payloadText);
|
|
63
|
+
await recordHookFire(payload).catch(() => {});
|
|
64
|
+
beat = Promise.resolve().then(() => heartbeat(payload)).catch(() => null);
|
|
65
|
+
// Cite before you steer (MW1-95): a steward session, which is never a lane config.
|
|
66
|
+
if (!isLaneConfig() && steerAct(payload)) {
|
|
67
|
+
const config = await readConfig(false).catch(() => null);
|
|
68
|
+
const steward = await activeSteward(config?.agentId).catch(() => null);
|
|
69
|
+
const nudges = await stewardSteerNudges(payload, { steward });
|
|
70
|
+
if (nudges.length) lines.push(line("PreToolUse", { additionalContext: nudges.join("\n") }));
|
|
71
|
+
if (steward) return { lines };
|
|
72
|
+
}
|
|
73
|
+
// MW1-12.9: a lane that has not acknowledged an amendment (an answer, a leeway grant) is told here.
|
|
74
|
+
// NODII-DEV-CLI-191: unread lane messages, from the local inbox file alone (no Dev call).
|
|
75
|
+
const mail = isLaneConfig() ? await inboxHookContext().catch(() => null) : null;
|
|
76
|
+
const pending = isLaneConfig() ? await pendingAmendmentContext() : null;
|
|
77
|
+
const nudges = (await nudgeCandidate(payload)) ? await nudgePre(payload, await safetyContext(payload.cwd ?? process.cwd())).catch(() => []) : [];
|
|
78
|
+
const context = [mail, pending, ...nudges].filter(Boolean);
|
|
79
|
+
if (context.length) lines.push(line("PreToolUse", { additionalContext: context.join("\n") }));
|
|
80
|
+
} catch {
|
|
81
|
+
} finally {
|
|
82
|
+
await beat;
|
|
83
|
+
}
|
|
84
|
+
return { lines };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** `hook tooling-docs` (MW1-46.3). Reads git only, never Dev; any error is no output, so a broken check never holds a push. */
|
|
88
|
+
export async function toolingDocsAnswer(payloadText) {
|
|
89
|
+
try {
|
|
90
|
+
const verdict = await toolingDocsHook(JSON.parse(payloadText));
|
|
91
|
+
if (verdict?.deny) return { lines: [line("PreToolUse", { permissionDecision: "deny", permissionDecisionReason: verdict.deny })] };
|
|
92
|
+
} catch {}
|
|
93
|
+
return { lines: [] };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** hub-284: a reviewer, or a session in this run other than the lane's own, gets nothing from a lane-run hook. */
|
|
97
|
+
export async function spawnedSession(payloadText, { env = process.env } = {}) {
|
|
98
|
+
if (await isReviewSession()) return true;
|
|
99
|
+
if (!env.NODII_DEV_RUN_ID) return false;
|
|
100
|
+
let payload = null;
|
|
101
|
+
try { payload = JSON.parse(payloadText); } catch {}
|
|
102
|
+
return !(await isLaneRunSession(payload));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The handlers with an in-process form, by `hook` action. */
|
|
106
|
+
export const HOOK_ANSWERS = { "safety-pre": safetyPreAnswer, "safety-post": safetyPostAnswer, "nudge-pre": nudgePreAnswer, "tooling-docs": toolingDocsAnswer };
|
|
107
|
+
// cli.js LANE_RUN_HOOKS, of the handlers above.
|
|
108
|
+
const LANE_RUN = new Set(["nudge-pre"]);
|
|
109
|
+
const EMPTY = { status: 0, stdout: "", stderr: "" };
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* One handler, in this process, answered as `nodii-dev hook ACTION` would exit:
|
|
113
|
+
* { status, stdout, stderr }. Null for a handler with no in-process form.
|
|
114
|
+
*/
|
|
115
|
+
export async function runHookInProcess(action, payloadText, { spawned = spawnedSession, heartbeat } = {}) {
|
|
116
|
+
if (!Object.hasOwn(HOOK_ANSWERS, action)) return null;
|
|
117
|
+
const answer = HOOK_ANSWERS[action];
|
|
118
|
+
try {
|
|
119
|
+
if (LANE_RUN.has(action) && (await spawned(payloadText))) return EMPTY;
|
|
120
|
+
const { lines, denial } = await answer(payloadText, heartbeat ? { heartbeat } : {});
|
|
121
|
+
const stdout = lines.map((text) => `${text}\n`).join("");
|
|
122
|
+
return denial ? { status: denial.exitCode ?? 1, stdout, stderr: `${errorText(denial)}\n` } : { ...EMPTY, stdout };
|
|
123
|
+
} catch {
|
|
124
|
+
// A hook that fails is no answer (nodii-dev.js exits 0 for it).
|
|
125
|
+
return EMPTY;
|
|
126
|
+
}
|
|
127
|
+
}
|
package/dist/hooks.js
CHANGED
|
@@ -5,6 +5,7 @@ import { execFile } from "node:child_process";
|
|
|
5
5
|
import { readFile, writeFile } from "node:fs/promises";
|
|
6
6
|
import { promisify } from "node:util";
|
|
7
7
|
import { safetySettingsSnippet } from "./safety.js";
|
|
8
|
+
import { laneSwitchOn } from "./lane-switches.js";
|
|
8
9
|
|
|
9
10
|
const execFileAsync = promisify(execFile);
|
|
10
11
|
|
|
@@ -219,10 +220,9 @@ export const settingsSnippet = () => {
|
|
|
219
220
|
} };
|
|
220
221
|
};
|
|
221
222
|
|
|
222
|
-
// MW1-34, MW5-17:
|
|
223
|
-
//
|
|
224
|
-
//
|
|
225
|
-
// the agent acted, which is what keeps `stuck` meaningful.
|
|
223
|
+
// MW1-34, MW5-17: a live lane is heartbeaten while its agent acts, about once a
|
|
224
|
+
// minute, and on stop. The lane heartbeat also refreshes the lane's run in Dev.
|
|
225
|
+
// It says the agent acted, which is what keeps `stuck` meaningful.
|
|
226
226
|
export const HEARTBEAT_STAMP = "nodii-lane-heartbeat-at";
|
|
227
227
|
export const HEARTBEAT_MIN_INTERVAL_MS = 60_000;
|
|
228
228
|
// hub-528: reading a lane costs hundreds of KB, so the hook keeps the lane it
|
|
@@ -234,11 +234,27 @@ export const HEARTBEAT_LANE_CACHE = "nodii-lane-heartbeat-lane.json";
|
|
|
234
234
|
export const HEARTBEAT_LANE_TTL_MS = 60 * 60_000;
|
|
235
235
|
export const HEARTBEAT_NO_LANE_TTL_MS = 5 * 60_000;
|
|
236
236
|
const LANE_ENDED = new Set(["LANE_NOT_FOUND", "LANE_TERMINAL"]);
|
|
237
|
-
|
|
237
|
+
// NODII-DEV-CLI-191: no heartbeat process on every tool call. A launched
|
|
238
|
+
// lane's supervisor beats the lane on its interval whenever the runtime wrote
|
|
239
|
+
// to its log or transcript (lane-supervisor.js), and the harness keeps one Stop
|
|
240
|
+
// beat. A session with no supervisor beats from nudge-pre, which already runs
|
|
241
|
+
// on each tool call, at most once per 5 minutes (Dev marks a lane quiet at 15).
|
|
242
|
+
export const HEARTBEAT_UNSUPERVISED_INTERVAL_MS = 5 * 60_000;
|
|
243
|
+
// Off unless NODII_DEV_STOP_ONLY_HEARTBEAT=1 until its clause is in force: the
|
|
244
|
+
// harness then keeps the tool-call beat as before, and neither the supervisor
|
|
245
|
+
// nor nudge-pre beats the lane.
|
|
246
|
+
export const heartbeatSettingsSnippet = (env = process.env) => {
|
|
238
247
|
const beat = [{ hooks: [{ type: "command", command: "nodii-dev hook lane-heartbeat" }] }];
|
|
239
|
-
return { hooks: { PostToolUse: beat, Stop: beat } };
|
|
248
|
+
return { hooks: laneSwitchOn("stopOnlyHeartbeat", env) ? { Stop: beat } : { PostToolUse: beat, Stop: beat } };
|
|
240
249
|
};
|
|
241
250
|
|
|
251
|
+
/** The tool-call beat for a session no lane supervisor beats for; a launched run (NODII_DEV_RUN_ID) sends none. */
|
|
252
|
+
export async function unsupervisedHeartbeat(payload, { env = process.env, ...options } = {}) {
|
|
253
|
+
if (!laneSwitchOn("stopOnlyHeartbeat", env)) return { heartbeated: false, reason: "the tool-call hook beats" };
|
|
254
|
+
if (env.NODII_DEV_RUN_ID) return { heartbeated: false, reason: "supervised run" };
|
|
255
|
+
return heartbeatFromHook(payload, { ...options, env, minIntervalMs: HEARTBEAT_UNSUPERVISED_INTERVAL_MS });
|
|
256
|
+
}
|
|
257
|
+
|
|
242
258
|
/** One rate-limited heartbeat for the worktree a hook fired in. The stamp is written first, so parallel tool calls send one. */
|
|
243
259
|
export async function heartbeatFromHook(payload, { request = devRequest, now = Date.now, minIntervalMs = HEARTBEAT_MIN_INTERVAL_MS, env = process.env } = {}) {
|
|
244
260
|
const cwd = payload?.cwd ?? process.cwd();
|