@nodii/dev 0.6.174 → 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/session-kind.js +18 -5
- package/dist/setup.js +5 -4
- package/dist/starting.js +111 -20
- package/dist/tooling-docs.js +127 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
readConfig,
|
|
14
14
|
requestHash,
|
|
15
15
|
requireFlag,
|
|
16
|
+
setLaneItemsObserver,
|
|
16
17
|
writeConfig,
|
|
17
18
|
} from "./core.js";
|
|
18
19
|
import {
|
|
@@ -25,6 +26,7 @@ import { FIGMA_HOOK_DENIALS, heartbeatFromHook, postHook, postHookFailure, preHo
|
|
|
25
26
|
import { setupCommand } from "./setup.js";
|
|
26
27
|
import { harnessCommand } from "./harness.js";
|
|
27
28
|
import { readPolicy, repoCommand } from "./repo-policy.js";
|
|
29
|
+
import { repoDocsCheckCommand, toolingDocsHook } from "./tooling-docs.js";
|
|
28
30
|
import { testCommand } from "./impact.js";
|
|
29
31
|
import { hookRuntime, recordHookFire, safetyContext, safetyPostHook, safetyPreHook } from "./safety.js";
|
|
30
32
|
import { isLaneRunSession, isReviewSession } from "./review-session.js";
|
|
@@ -120,6 +122,7 @@ import {
|
|
|
120
122
|
import { laneTestCommand } from "./red-run.js";
|
|
121
123
|
import {
|
|
122
124
|
amendmentGuard,
|
|
125
|
+
pendingAmendmentContext,
|
|
123
126
|
amendLaneCommand,
|
|
124
127
|
foldLaneCommand,
|
|
125
128
|
laneAmendmentsCommand,
|
|
@@ -134,12 +137,15 @@ import {
|
|
|
134
137
|
superviseRun,
|
|
135
138
|
} from "./runs.js";
|
|
136
139
|
import { superviseLane } from "./lane-supervisor.js";
|
|
140
|
+
import { laneLeewayCommand } from "./leeway.js";
|
|
141
|
+
import { laneAnswerCommand, laneAskCommand, laneAsksCommand, laneDeferCommand } from "./lane-asks.js";
|
|
142
|
+
import { coordinatorGate, coordinatorItemsCommand, observeLaneItems, resetLaneItemsNotice, takeLaneItemsLine } from "./coordinator-items.js";
|
|
137
143
|
import { awsCli, superviseRemoteRun } from "./remote.js";
|
|
138
144
|
|
|
139
145
|
const NOTICE_KINDS = ["lane_wait", "lane_escalation", "credential_expiry"];
|
|
140
146
|
const LANE_RUN_HOOKS = new Set(["nudge-pre", "nudge-stop", "lane-heartbeat", "session-start", "session-kind", "workflow-post"]);
|
|
141
147
|
|
|
142
|
-
const HELP = `nodii-dev ${VERSION}
|
|
148
|
+
export const HELP = `nodii-dev ${VERSION}
|
|
143
149
|
|
|
144
150
|
Usage: nodii-dev <command> [options] [--json]
|
|
145
151
|
|
|
@@ -278,7 +284,7 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
278
284
|
figma file retire FILE_KEY --reason TEXT
|
|
279
285
|
# staff or the hub's Steward: not canonical. Closes its sets still editing
|
|
280
286
|
# or awaiting publish, and refuses new locks
|
|
281
|
-
hook claude-figma-pre|claude-figma-post|safety-pre|safety-post|nudge-pre|nudge-stop|surface-gen-pre|session-start|session-kind|managed-dispatch|claude-managed-dispatch|print-settings
|
|
287
|
+
hook claude-figma-pre|claude-figma-post|safety-pre|safety-post|nudge-pre|nudge-stop|surface-gen-pre|coordinator-gate|tooling-docs|session-start|session-kind|managed-dispatch|claude-managed-dispatch|print-settings
|
|
282
288
|
# session-start and session-kind (first prompt) print the session's kind:
|
|
283
289
|
# lane, coordinator, steward or operator assistant, with its contract (MW1-92)
|
|
284
290
|
steward register --focus TEXT --repos R,... [--side frontend|backend|both] [--key KEY]
|
|
@@ -294,6 +300,14 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
294
300
|
repo policy # print this repository's nodii.repo.yaml facts (STD-11)
|
|
295
301
|
repo lint # 0 clean, 1 findings: policy file missing or invalid, stray root
|
|
296
302
|
# files, docs layout, scratch not gitignored, test scripts
|
|
303
|
+
repo docs-check [--base REF] # MW1-46.3: docs move with tooling. 0 clean or not checked, 1 TOOLING_DOCS_STALE:
|
|
304
|
+
# the range REF...HEAD (default origin/main) changes a file matching
|
|
305
|
+
# toolingDocs.tooling in nodii.repo.yaml (commands, routes, refusal codes,
|
|
306
|
+
# hooks) and none matching toolingDocs.docs, and no commit in it carries
|
|
307
|
+
# the trailer "Docs-unaffected: <reason>". A repository without the
|
|
308
|
+
# toolingDocs block is not checked. hook tooling-docs (PreToolUse on Bash,
|
|
309
|
+
# installed by the harness, every session) refuses git push and
|
|
310
|
+
# gh pr create|ready on the same finding; it reads git only and fails open
|
|
297
311
|
watchdog install [--interval SECONDS] # install/update the per-machine liveness sweep (default 60s): launchd on
|
|
298
312
|
# macOS, a systemd user timer (nodii-watchdog.timer) on Linux
|
|
299
313
|
watchdog sweep # the job's entrypoint: report dead runs, stale sockets, unpushed worktrees,
|
|
@@ -352,18 +366,34 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
352
366
|
# the library publish dialog through the shared Chrome: ticks only the
|
|
353
367
|
# components of finished sets (awaiting_publish), unticks the rest, reports
|
|
354
368
|
# what it can't map, publishes and records it (figma published)
|
|
369
|
+
coordinator items [--machine NAME|ID]
|
|
370
|
+
# MW1-37.2: what lanes wait on this coordinator for (questions, leeway asks,
|
|
371
|
+
# waits, escalations), each with the command that clears it. Every command
|
|
372
|
+
# a coordinator runs prints the count first, on stderr:
|
|
373
|
+
# 3 from lanes waiting on you: 1 leeway (k), 2 questions (k 34 min, ...)
|
|
374
|
+
# While an ask or a leeway has waited over 10 minutes, the managed hooks
|
|
375
|
+
# refuse the coordinator's next nodii-dev write until it is answered, granted,
|
|
376
|
+
# refused or deferred; a question to the operator is never held (MW1-116) and
|
|
377
|
+
# passes with the waiting items named. Reads, inbox,
|
|
378
|
+
# lane answer|defer, lane leeway grant|refuse, lane resume|close|stop pass.
|
|
379
|
+
# The gate runs only where coordinator start wrote coordinator.json beside
|
|
380
|
+
# the config, and passes when Dev cannot be read
|
|
355
381
|
coordinator start --machine NAME [--account RUNTIME:PROFILE ...]
|
|
356
382
|
# register this machine's one watched coordinator; refuses a live second;
|
|
357
383
|
# registers each --account and reports every account's usage; a background
|
|
358
384
|
# heartbeater keeps the run alive while this session lives, then ends it
|
|
359
385
|
lane launch <key> --done-check TEXT --kind KIND --side SIDE
|
|
360
386
|
--issue KEY --repo NAME=/SOURCE --branch NAME=BRANCH [--repo ... --branch ...]
|
|
361
|
-
--machine NAME --runtime claude|codex --profile PATH --model MODEL --subagents N
|
|
387
|
+
--machine NAME --runtime claude|codex --profile PATH --model MODEL [--subagents N]
|
|
362
388
|
--class long|short|no-build # MW1-38.3 class, weighed against the account's MW1-38.2 band
|
|
363
389
|
[--base NAME=REF] [--worktree NAME=PATH] [--owned-path NAME=PATH]
|
|
364
390
|
[--route /app/... ...] [--figma FILE_KEY[=COMPONENT_SET_KEY[,KEY]]] [--notes TEXT]
|
|
365
391
|
[--narrowing-note TEXT --narrowing-remainder DESTINATION]
|
|
366
392
|
# authoritative preflight, one worktree per repo, watched launch
|
|
393
|
+
# --subagents defaults to 4 (0 to 100; 0 is none). Default shape: fewer
|
|
394
|
+
# lanes, with subagents fanned out inside each (MW1-38.15). Dev clamps a new
|
|
395
|
+
# lane's quota to 2 or 1 in the two_builds or one_build usage band and the
|
|
396
|
+
# launch prints the clamp
|
|
367
397
|
# uses the provisioned agents/lane-<key>.json Dev identity
|
|
368
398
|
# Figma scope by published key: --route derives it from the
|
|
369
399
|
# DS catalog (route -> Surfaces -> componentSetKey -> file)
|
|
@@ -373,12 +403,18 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
373
403
|
# open.md line. A pivot (most of the brief rewritten) is refused
|
|
374
404
|
# AMENDMENT_IS_A_PIVOT: stop the lane --launched-in-error instead.
|
|
375
405
|
# The stepped-up operator's own amendment applies at once; the operator's
|
|
376
|
-
# approval is the recorded word an --objective/--scope one needs (MW1-12.5)
|
|
406
|
+
# approval is the recorded word an --objective/--scope one needs (MW1-12.5).
|
|
407
|
+
# A leeway grant is not held this way: the coordinator's grant is enough, with
|
|
408
|
+
# no operator approval and no TOTP code (MW1-12.7, DEC-0486)
|
|
377
409
|
lane amendments [<key>] [--all|--state pending|approved|rejected|withdrawn|refused_pivot]
|
|
378
410
|
lane amendments show|withdraw <request>
|
|
379
|
-
lane amendments approve|reject <request> [--note TEXT]
|
|
411
|
+
lane amendments approve|reject <request> [<request> ...]|--all-pending [--note TEXT]
|
|
380
412
|
# approve/reject: the operator only (TOTP step-up); approval applies the
|
|
381
|
-
# amendment and the lane acks it with lane gather --delta
|
|
413
|
+
# amendment and the lane acks it with lane gather --delta. Several ids, or
|
|
414
|
+
# --all-pending (every pending request Dev lists to you), are answered in
|
|
415
|
+
# one run under ONE code; a shell loop asks for a code per request. A
|
|
416
|
+
# refusal stops the run and names what was done and what was not tried.
|
|
417
|
+
# A leeway grant never waits here (MW1-12.7, DEC-0486)
|
|
382
418
|
lane fold <key> --versions 3,4,5|3-9 --summary TEXT --reason TEXT
|
|
383
419
|
# folds superseded scope/rules amendments into one rules note, so a
|
|
384
420
|
# lane at its note cap (LANE_NOTES_FULL) takes amendments again;
|
|
@@ -409,7 +445,9 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
409
445
|
lane start <ISSUE> --key KEY --title TEXT --kind KIND --side SIDE
|
|
410
446
|
# --key names the lane; the positional is then its issue
|
|
411
447
|
lane step <key> --side SIDE --start|--done|--block <step> [--reason TEXT]
|
|
412
|
-
# --block --reason on a blocked step records its new reason
|
|
448
|
+
# --block --reason on a blocked step records its new reason. A step blocked
|
|
449
|
+
# on an open issue that no live lane holds is not blocked: ask for leeway
|
|
450
|
+
# with lane leeway instead of ending BLOCKED (MW1-12.6, DEC-0486)
|
|
413
451
|
lane step <key> --side SIDE --done <step> --review REVIEW.json
|
|
414
452
|
# records the review (as lane review) first, then marks the step done
|
|
415
453
|
lane step <key> --side SIDE --not-applicable gather --reason-code pre_harness_lane [--note TEXT]
|
|
@@ -447,7 +485,13 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
447
485
|
# send the lane records queued while Dev was down (MW1-64); --discard drops
|
|
448
486
|
# one Dev refuses for good, with a note on its lane
|
|
449
487
|
lane ready <key> --withdraw --reason TEXT # take READY back without closing the PR; a newer done check posts it again
|
|
450
|
-
lane done-check <key> --evidence TEXT|URL # the done check is met; a launched run that exits after it ends finished
|
|
488
|
+
lane done-check <key> --evidence TEXT|URL # the done check is met; a launched run that exits after it ends finished,
|
|
489
|
+
# and a clean exit also records the lane finished with this evidence,
|
|
490
|
+
# unless the lane still has an open wait or a blocked step
|
|
491
|
+
lane finish <key> --reason TEXT --evidence TEXT|URL
|
|
492
|
+
# the lane's own agent marks the lane finished (MW1-28.2): why, and what it
|
|
493
|
+
# delivered and where its branch and commits went. The lane keeps its status
|
|
494
|
+
# and slot; its coordinator's lane close needs this record (LANE_NOT_FINISHED)
|
|
451
495
|
lane subagent-quota <key> <n> # coordinator assigns 0-100 subagent slots
|
|
452
496
|
lane cap <machine> <n> [--confirm-raise --reason TEXT]
|
|
453
497
|
# coordinator declares the machine's lane cap, at least every 60 minutes;
|
|
@@ -459,7 +503,48 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
459
503
|
# catalog_publish and worker_ready checks (DEV_CHECK_REQUIRED, DEV_CHECK_FAILED)
|
|
460
504
|
lane heartbeat <key> --note "BLOCKED: ..."|"WAITING: ..."
|
|
461
505
|
# a note starting BLOCKED or WAITING: (capitals) marks the lane blocked:
|
|
462
|
-
# an exit then ends its run blocked and never counts as a death
|
|
506
|
+
# an exit then ends its run blocked and never counts as a death. When the
|
|
507
|
+
# note names an open issue no live lane holds, Dev answers with the
|
|
508
|
+
# lane leeway command to run and the heartbeat prints it: the lane is then
|
|
509
|
+
# not blocked, and the Stop gate and the supervisor continue its session
|
|
510
|
+
lane leeway <key> --blocker ISSUE [--repo NAME] --reason TEXT
|
|
511
|
+
# MW1-12.6 (DEC-0486): a lane blocked on an open issue no live lane holds asks
|
|
512
|
+
# its machine coordinator for leeway to fix it, instead of ending BLOCKED. Dev
|
|
513
|
+
# claims the issue for the lane (MW1-21.1); LEEWAY_BLOCKER_HELD names the lane
|
|
514
|
+
# that already holds it and records a wait on it. --repo names the repository
|
|
515
|
+
# of the fix when the lane does not work in it. The lane keeps working
|
|
516
|
+
# what is not blocked and starts the fix only after the grant's Delta gather
|
|
517
|
+
lane leeway grant <id> [--note TEXT] [--source PATH] [--worktree PATH]
|
|
518
|
+
lane leeway refuse <id> [--note TEXT]
|
|
519
|
+
# the lane's machine coordinator (or staff). The coordinator's grant is
|
|
520
|
+
# enough: no operator approval and no TOTP code (MW1-12.7, DEC-0486). A grant
|
|
521
|
+
# widens the lane's contract to exactly that issue and repository, as an
|
|
522
|
+
# amendment the lane acknowledges with lane gather --delta. For a repository the lane lacks, the CLI sends Dev
|
|
523
|
+
# the worktree path, then creates the worktree on fix/<lane key> from
|
|
524
|
+
# origin/main as lane launch does (--source is that repository's checkout,
|
|
525
|
+
# by default the one beside the lane's first repository; --worktree
|
|
526
|
+
# overrides <source>/.claude/worktrees/<lane key>). The fix is its own PR,
|
|
527
|
+
# merged by the repository's steward where it has one; the lane rebases its
|
|
528
|
+
# own PR after the fix merges. Leeway never reaches Prod, a locked
|
|
529
|
+
# component or lock change, a Figma publish, a steward's merge, another
|
|
530
|
+
# lane's in-flight branch, or credentials; chains stop at depth 2 and a lane
|
|
531
|
+
# holds at most 2 open leeways (MW1-12.8). Refusal codes: see "Refusals" below
|
|
532
|
+
lane leeway withdraw <id> # the lane takes its ask back
|
|
533
|
+
lane ask <key> --question TEXT [--options a,b]
|
|
534
|
+
# OFF unless NODII_DEV_LANE_ASKS=1 (MW1-37.2: lane asks ship off by default):
|
|
535
|
+
# lane ask, lane answer and lane asks then refuse LANE_ASKS_OFF and call
|
|
536
|
+
# nothing, lane defer takes its id as a leeway, and the coordinator's count,
|
|
537
|
+
# coordinator items and the gate leave questions out. On:
|
|
538
|
+
# MW1-12.9: a lane asks its machine coordinator a question. The answer
|
|
539
|
+
# reaches it as an amendment it acknowledges with lane gather --delta;
|
|
540
|
+
# lane ask withdraw <ask id> takes the question back
|
|
541
|
+
lane answer <ask id> --text TEXT # the coordinator (or staff) answers; Dev delivers it as that amendment
|
|
542
|
+
lane defer <ask or leeway id> --reason TEXT [--minutes N] [--leeway]
|
|
543
|
+
# the coordinator puts an ask or a leeway off, with a reason, for N minutes
|
|
544
|
+
# (default 60, at most 240); it counts again after that. The id is tried as
|
|
545
|
+
# an ask, then as a leeway; --leeway goes straight to the leeway
|
|
546
|
+
lane asks [--machine M] [--state S] [--lane KEY] [--cursor C] [--limit N]
|
|
547
|
+
lane leeway list [--machine M] [--state S] [--lane KEY] [--cursor C] [--limit N] | lane leeway show <id>
|
|
463
548
|
lane heartbeat <key> --waiting-on LANE|owner/repo#n|Q-nnn|DEC-nnnn|release:PKG|launch-day [...]
|
|
464
549
|
# repeatable; replaces the lane's waits (a WAITING note's lane keys and
|
|
465
550
|
# repo#n count too; a note that is no wait clears them). A wait on another
|
|
@@ -595,6 +680,38 @@ notification-registry, skills, open-questions, decisions, drift, requests,
|
|
|
595
680
|
rulebook, ad-decisions, domains, standardizations, archive, harness, utils,
|
|
596
681
|
runs, releases, and operate.
|
|
597
682
|
|
|
683
|
+
Refusals of leeway, lane questions, the coordinator's items, lane finish, the managed hooks and the docs check
|
|
684
|
+
(each line: the code, what it means, and what to do next):
|
|
685
|
+
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
|
+
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
|
|
687
|
+
LEEWAY_CYCLE The lane that holds this blocker is itself waiting on you. Next: land your own work first, or ask the coordinator in an issue comment or a heartbeat note
|
|
688
|
+
LEEWAY_PROD Leeway never reaches Prod (MW1-12.8). Next: raise the operator item
|
|
689
|
+
LEEWAY_LOCKED_COMPONENT The blocker touches a locked component or a lock change (U07-34). Next: raise the operator item
|
|
690
|
+
LEEWAY_FIGMA_PUBLISH A Figma publish stays with the operator. Next: raise the operator item
|
|
691
|
+
LEEWAY_CREDENTIALS An issue of kind credential or operator prerequisite is not fixed by leeway (MW1-38.8). Next: raise the operator item
|
|
692
|
+
LEEWAY_DEPTH Leeway chains stop at depth 2. Next: ask the coordinator to launch a lane for the blocker
|
|
693
|
+
LEEWAY_LIMIT A lane holds at most 2 open leeways. Next: finish or withdraw one (lane leeway withdraw ID) first
|
|
694
|
+
LEEWAY_ISSUE_CLOSED The blocker issue is already done or closed, so there is nothing left to fix. Next: re-check what blocks the lane
|
|
695
|
+
LEEWAY_OWN_ISSUE The blocker is already this lane's own issue and needs no leeway. Next: fix it in the lane
|
|
696
|
+
LEEWAY_ALREADY_ASKED This lane already asked for leeway on this blocker; Dev names the ask. Next: read it with lane leeway show ID and wait for the coordinator
|
|
697
|
+
LEEWAY_DECIDED The leeway is already granted, refused or withdrawn. Next: read it with lane leeway show ID
|
|
698
|
+
LEEWAY_NOT_FOUND Dev has no leeway with this id. Next: list them with lane leeway list
|
|
699
|
+
LEEWAY_WORKTREE_REQUIRED The grant names a repository the lane does not work in and carries no worktree for it. Next: run lane leeway grant from a current CLI, which creates the worktree, or pass --worktree PATH
|
|
700
|
+
LEEWAY_SOURCE_REQUIRED The grant needs a local clone of the leeway's repository to create the worktree from, and found none; nothing was granted. Next: pass --source PATH, the repository's clone
|
|
701
|
+
LEEWAY_WORKTREE_FAILED The leeway is granted, but its worktree could not be created. Next: create it with the worktree command the refusal prints, then tell the lane
|
|
702
|
+
REPO_NOT_GRANTED The lane's agent has no grant for the repository the leeway adds. Next: grant the agent the repository, then grant the leeway again
|
|
703
|
+
LANE_WORKTREE_TAKEN Another lane already records the worktree path the grant names. Next: pass another --worktree PATH
|
|
704
|
+
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
|
+
MACHINE_REQUIRED The caller coordinates no machine, so Dev cannot tell whose items or asks to list. Next: pass --machine NAME|ID
|
|
706
|
+
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
|
|
707
|
+
ASK_NOT_FOUND Dev has no lane ask with this id. Next: list them with lane asks
|
|
708
|
+
ASK_DECIDED The ask is already answered or withdrawn. Next: read it with lane asks --lane KEY
|
|
709
|
+
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
|
+
LANE_ALREADY_FINISHED The lane is already marked finished. Next: nothing; its coordinator closes it with lane close
|
|
711
|
+
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
|
+
HARNESS_SETTINGS_INVALID .claude/settings.json or .codex/hooks.json is not valid JSON. Next: repair the file, then run harness update
|
|
713
|
+
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
|
|
714
|
+
|
|
598
715
|
Run a command with --help or see the package README for all flags.`;
|
|
599
716
|
|
|
600
717
|
// Verbs of the local-stack CLI, which shared this name until it became
|
|
@@ -623,7 +740,14 @@ function stdinText() {
|
|
|
623
740
|
}
|
|
624
741
|
const bodyFlag = async (f, name = "body") =>
|
|
625
742
|
f[`${name}-file`] ? readFile(f[`${name}-file`], "utf8") : f[name];
|
|
743
|
+
/** MW1-37.2: what lanes wait on this coordinator for, first and on stderr, so JSON stdout stays parseable. */
|
|
744
|
+
function laneItemsNotice() {
|
|
745
|
+
const line = takeLaneItemsLine();
|
|
746
|
+
if (line) process.stderr.write(`${line}\n`);
|
|
747
|
+
}
|
|
748
|
+
|
|
626
749
|
function emit(payload, json, human) {
|
|
750
|
+
laneItemsNotice();
|
|
627
751
|
if (json) console.log(JSON.stringify(payload));
|
|
628
752
|
else
|
|
629
753
|
console.log(
|
|
@@ -875,6 +999,10 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
875
999
|
// Ahead of every check that reaches Dev: a session the lane spawned gets
|
|
876
1000
|
// nothing from these hooks. The safety hooks still run.
|
|
877
1001
|
if (argv[0] === "hook" && LANE_RUN_HOOKS.has(argv[1]) && (await inSpawnedSession())) return;
|
|
1002
|
+
// MW1-37.2: a command prints what lanes wait on its coordinator for. A hook
|
|
1003
|
+
// and a supervisor write only their own answer.
|
|
1004
|
+
resetLaneItemsNotice();
|
|
1005
|
+
setLaneItemsObserver(argv[0] === "hook" || argv[0]?.startsWith("__") ? null : observeLaneItems);
|
|
878
1006
|
// A lane's own exit reporter runs after its runtime ends (NODII-DEV-CLI-1).
|
|
879
1007
|
if (argv[0] === "__lane-supervisor") return superviseLane();
|
|
880
1008
|
// Amendment acknowledgement is a lane-wide backstop for every other command.
|
|
@@ -883,7 +1011,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
883
1011
|
// surface-gen-pre runs in every session, lane or not, so it never reaches Dev.
|
|
884
1012
|
// The heartbeat hook fires on every tool call, so these checks would call Dev each
|
|
885
1013
|
// time past its rate limit, and a failed check would silently stop the heartbeat.
|
|
886
|
-
if (argv[0] !== "__run-supervisor" && !readsHelp(argv) && !(argv[0] === "hook" && (argv[1]?.startsWith("nudge-") || argv[1] === "surface-gen-pre" || argv[1] === "lane-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"))) {
|
|
887
1015
|
const cache = backstopCache(argv);
|
|
888
1016
|
await amendmentGuard(argv, { cache });
|
|
889
1017
|
await showWaitingResults({ acknowledge: argv[0] !== "hook", cache });
|
|
@@ -1054,6 +1182,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1054
1182
|
}
|
|
1055
1183
|
return emitCommand(result);
|
|
1056
1184
|
}
|
|
1185
|
+
if (command === "repo" && action === "docs-check") return emitCommand(await repoDocsCheckCommand(rest, f));
|
|
1057
1186
|
if (command === "repo" && ["policy", "lint"].includes(action)) return emitCommand(await repoCommand(action, rest, f));
|
|
1058
1187
|
if (command === "test") return emitCommand(await testCommand(action, rest, f, { readPolicy }));
|
|
1059
1188
|
if (command === "watchdog") {
|
|
@@ -1120,10 +1249,19 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1120
1249
|
if (command === "chrome") return emitCommand(await (await import("./chrome.js")).chromeCommand(action, rest, f));
|
|
1121
1250
|
if (command === "coordinator" && ["board", "watch"].includes(action))
|
|
1122
1251
|
return emitCommand(await (await import("./coordinator-watch.js")).coordinatorWatchCommand(action, rest, f));
|
|
1252
|
+
if (command === "coordinator" && action === "items") {
|
|
1253
|
+
if (rest.length) throw new CliError("USAGE", "coordinator items [--machine NAME|ID]", 2);
|
|
1254
|
+
return emitCommand(await coordinatorItemsCommand(f));
|
|
1255
|
+
}
|
|
1123
1256
|
if (command === "coordinator") return emitCommand(await coordinatorCommand(action, f, { installWatchdog }));
|
|
1124
1257
|
if (command === "steward") return emitCommand(await stewardCommand(action, rest, f));
|
|
1125
1258
|
if (command === "lane" && action === "launch") return emitCommand(await launchLaneCommand(rest[0], f));
|
|
1126
1259
|
if (command === "lane" && action === "repo") return emitCommand(await laneRepoCommand(rest[0], rest.slice(1), f));
|
|
1260
|
+
if (command === "lane" && action === "leeway") return emitCommand(await laneLeewayCommand(rest, f));
|
|
1261
|
+
if (command === "lane" && action === "ask") return emitCommand(await laneAskCommand(rest, f));
|
|
1262
|
+
if (command === "lane" && action === "asks") return emitCommand(await laneAsksCommand(rest, f));
|
|
1263
|
+
if (command === "lane" && action === "answer") return emitCommand(await laneAnswerCommand(rest, f));
|
|
1264
|
+
if (command === "lane" && action === "defer") return emitCommand(await laneDeferCommand(rest, f));
|
|
1127
1265
|
if (command === "lane" && action === "cap") return emitCommand(await laneCapCommand(rest, f));
|
|
1128
1266
|
if (command === "lane" && action === "close") {
|
|
1129
1267
|
const result = await laneClose(rest[0], f);
|
|
@@ -1720,9 +1858,31 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1720
1858
|
if (nudges.length) console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: "PreToolUse", additionalContext: nudges.join("\n") } }));
|
|
1721
1859
|
if (steward) return;
|
|
1722
1860
|
}
|
|
1723
|
-
|
|
1724
|
-
const
|
|
1725
|
-
|
|
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 {}
|
|
1867
|
+
return;
|
|
1868
|
+
}
|
|
1869
|
+
// MW1-37.2: the coordinator gate, as its own hook. The managed dispatcher
|
|
1870
|
+
// runs the same check for a coordinator session; this is the direct form
|
|
1871
|
+
// (a deny on stdout, or context). It fails open: any error is no output.
|
|
1872
|
+
if (action === "coordinator-gate") {
|
|
1873
|
+
try {
|
|
1874
|
+
const verdict = await coordinatorGate(JSON.parse(await stdinText()));
|
|
1875
|
+
if (verdict?.deny) console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: "PreToolUse", permissionDecision: "deny", permissionDecisionReason: verdict.deny } }));
|
|
1876
|
+
else if (verdict?.context) console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: "PreToolUse", additionalContext: verdict.context } }));
|
|
1877
|
+
} catch {}
|
|
1878
|
+
return;
|
|
1879
|
+
}
|
|
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 } }));
|
|
1726
1886
|
} catch {}
|
|
1727
1887
|
return;
|
|
1728
1888
|
}
|
|
@@ -1750,7 +1910,10 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1750
1910
|
let payload = {};
|
|
1751
1911
|
if (!process.stdin.isTTY) { try { payload = JSON.parse(await stdinText()); } catch {} }
|
|
1752
1912
|
const result = await heartbeatFromHook(payload);
|
|
1753
|
-
|
|
1913
|
+
// MW1-12.9: after a tool call, a lane that has not acknowledged an amendment is told so (a Stop takes no context).
|
|
1914
|
+
const pending = payload.hook_event_name === "PostToolUse" && isLaneConfig() ? await pendingAmendmentContext() : null;
|
|
1915
|
+
if (pending && !json) return console.log(JSON.stringify({ hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: pending } }));
|
|
1916
|
+
return emit(pending ? { ...result, pendingAmendment: pending } : result, json, result.heartbeated ? `Heartbeat recorded for ${result.key}.` : `No heartbeat sent: ${result.reason}.`);
|
|
1754
1917
|
} catch (error) {
|
|
1755
1918
|
process.stderr.write(`nodii-dev lane heartbeat: ${error?.code ?? "ERROR"}: ${error?.message ?? String(error)}\n`);
|
|
1756
1919
|
return;
|
|
@@ -1827,6 +1990,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1827
1990
|
}
|
|
1828
1991
|
|
|
1829
1992
|
export function fail(error) {
|
|
1993
|
+
laneItemsNotice();
|
|
1830
1994
|
const e =
|
|
1831
1995
|
error instanceof CliError
|
|
1832
1996
|
? error
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { access, readFile, rm } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { devRequest, query } from "./core.js";
|
|
5
|
+
import { laneAsksOn } from "./lane-asks.js";
|
|
6
|
+
import { cachedGet, laneReadCache } from "./read-cache.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* hub-525 (MW1-37.2): the coordinator clears lane items first.
|
|
10
|
+
* Lanes ask questions and ask for leeway; Dev counts what waits on a machine's
|
|
11
|
+
* coordinator and says so in a response header on every answer to that
|
|
12
|
+
* coordinator. The CLI prints one line for it before each command's output,
|
|
13
|
+
* `coordinator items` lists the items, and the coordinator gate (a PreToolUse
|
|
14
|
+
* hook in the managed dispatcher) holds the coordinator's next nodii-dev write
|
|
15
|
+
* while an ask or a leeway has waited over 10 minutes.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export const LANE_ITEMS_HEADER = "x-dev-lane-items";
|
|
19
|
+
const ITEMS_PATH = "/api/v1/coordinator/items";
|
|
20
|
+
// Asks and leeways gate after this long; waits and escalations never do.
|
|
21
|
+
export const GATE_AFTER_SECONDS = 10 * 60;
|
|
22
|
+
const GATE_CACHE_TTL_MS = 10_000;
|
|
23
|
+
const LINE_CACHE_KEY = "coordinator-items-line";
|
|
24
|
+
const LINE_CACHE_TTL_MS = 5 * 60_000;
|
|
25
|
+
const DETAIL_TIMEOUT_MS = 3_000;
|
|
26
|
+
const GATE_TIMEOUT_MS = 5_000;
|
|
27
|
+
|
|
28
|
+
// kind, singular, plural: in the order the line names them.
|
|
29
|
+
const KINDS = [["leeway", "leeway", "leeways"], ["ask", "question", "questions"], ["wait", "wait", "waits"], ["escalation", "escalation", "escalations"]];
|
|
30
|
+
|
|
31
|
+
/** `total=3;leeway=1;ask=2;wait=0;escalation=0;oldest=2040` as numbers, or null when there is nothing to say. */
|
|
32
|
+
export function parseLaneItemsHeader(value, env = process.env) {
|
|
33
|
+
if (typeof value !== "string" || !value.trim()) return null;
|
|
34
|
+
const fields = Object.fromEntries(value.split(";").map((part) => part.split("=").map((piece) => piece.trim())).filter(([name, number]) => name && /^\d+$/.test(number ?? "")).map(([name, number]) => [name, Number(number)]));
|
|
35
|
+
if (!Number.isInteger(fields.total) || fields.total <= 0) return null;
|
|
36
|
+
// Lane asks off (MW1-37.2): they are not counted, and questions alone are nothing to say.
|
|
37
|
+
const ask = laneAsksOn(env) ? (fields.ask ?? 0) : 0;
|
|
38
|
+
const total = fields.total - ((fields.ask ?? 0) - ask);
|
|
39
|
+
if (total <= 0) return null;
|
|
40
|
+
return { total, leeway: fields.leeway ?? 0, ask, wait: fields.wait ?? 0, escalation: fields.escalation ?? 0, oldest: fields.oldest ?? 0 };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const age = (seconds) => {
|
|
44
|
+
const minutes = Math.max(0, Math.floor(Number(seconds ?? 0) / 60));
|
|
45
|
+
return minutes >= 120 ? `${Math.round(minutes / 60)} h` : `${minutes} min`;
|
|
46
|
+
};
|
|
47
|
+
const deferred = (item, now) => Boolean(item?.deferredUntil) && Date.parse(item.deferredUntil) > now;
|
|
48
|
+
|
|
49
|
+
/** The one line a coordinator's command prints first. With no detail it is the counts alone. */
|
|
50
|
+
export function laneItemsLine(counts, items, { elapsedSeconds = 0, now = Date.now() } = {}) {
|
|
51
|
+
const parts = KINDS.filter(([kind]) => counts[kind] > 0).map(([kind, one, many]) => {
|
|
52
|
+
const open = (Array.isArray(items) ? items : []).filter((item) => item?.kind === kind && item.laneKey && !deferred(item, now));
|
|
53
|
+
const names = open.slice(0, 5).map((item) => (kind === "ask" ? `${item.laneKey} ${age(Number(item.ageSeconds ?? 0) + elapsedSeconds)}` : item.laneKey));
|
|
54
|
+
const more = open.length > 5 ? `, +${open.length - 5} more` : "";
|
|
55
|
+
return `${counts[kind]} ${counts[kind] === 1 ? one : many}${names.length ? ` (${names.join(", ")}${more})` : ""}`;
|
|
56
|
+
});
|
|
57
|
+
return `${counts.total} from lanes waiting on you${parts.length ? `: ${parts.join(", ")}` : ""} · nodii-dev coordinator items`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ─── The count line ─────────────────────────────────────────────────────────
|
|
61
|
+
|
|
62
|
+
let current = null;
|
|
63
|
+
let refreshing = false;
|
|
64
|
+
let printed = false;
|
|
65
|
+
|
|
66
|
+
/** A new command starts with nothing seen and nothing printed. */
|
|
67
|
+
export function resetLaneItemsNotice() {
|
|
68
|
+
current = null;
|
|
69
|
+
printed = false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Called with each Dev response's header. The names in the line come from the
|
|
74
|
+
* cached `/coordinator/items` detail, read again when the header's total
|
|
75
|
+
* changes (or the cache is five minutes old); a failed read leaves the counts.
|
|
76
|
+
* Never throws.
|
|
77
|
+
*/
|
|
78
|
+
export async function observeLaneItems(header, { request = devRequest, cache = laneReadCache({ ttlMs: LINE_CACHE_TTL_MS }), now = Date.now } = {}) {
|
|
79
|
+
// The detail read's own answer carries the header too.
|
|
80
|
+
if (refreshing) return;
|
|
81
|
+
try {
|
|
82
|
+
const counts = parseLaneItemsHeader(header);
|
|
83
|
+
if (!counts) { current = null; return; }
|
|
84
|
+
let detail = await cache.get(LINE_CACHE_KEY);
|
|
85
|
+
if (!detail || detail.total !== counts.total) {
|
|
86
|
+
refreshing = true;
|
|
87
|
+
try {
|
|
88
|
+
const data = (await request("GET", ITEMS_PATH, undefined, { signal: AbortSignal.timeout(DETAIL_TIMEOUT_MS) })).data;
|
|
89
|
+
detail = { total: counts.total, at: now(), items: data?.items ?? [] };
|
|
90
|
+
await cache.set(LINE_CACHE_KEY, detail);
|
|
91
|
+
} catch {
|
|
92
|
+
detail = null;
|
|
93
|
+
} finally {
|
|
94
|
+
refreshing = false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
current = laneItemsLine(counts, detail?.items ?? null, { elapsedSeconds: detail ? Math.max(0, Math.round((now() - detail.at) / 1000)) : 0, now: now() });
|
|
98
|
+
} catch {
|
|
99
|
+
current = null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The line to print before this command's output, once; null when there is none. */
|
|
104
|
+
export function takeLaneItemsLine() {
|
|
105
|
+
if (!current || printed) return null;
|
|
106
|
+
printed = true;
|
|
107
|
+
return current;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ─── coordinator items ──────────────────────────────────────────────────────
|
|
111
|
+
|
|
112
|
+
/** `nodii-dev coordinator items [--machine NAME|ID]`: what lanes wait on, each with the command that clears it. */
|
|
113
|
+
export async function coordinatorItemsCommand(flags, { request = devRequest, now = Date.now, env = process.env } = {}) {
|
|
114
|
+
const payload = await request("GET", `${ITEMS_PATH}${query({ machine: typeof flags.machine === "string" ? flags.machine : undefined })}`);
|
|
115
|
+
const data = payload.data ?? {};
|
|
116
|
+
// Lane asks off (MW1-37.2): none is listed or counted.
|
|
117
|
+
const asksOn = laneAsksOn(env);
|
|
118
|
+
const asksOff = asksOn ? "" : "Lane questions are off (NODII_DEV_LANE_ASKS): none is listed or counted.";
|
|
119
|
+
const items = (data.items ?? []).filter((item) => asksOn || item?.kind !== "ask");
|
|
120
|
+
const counts = data.counts ?? {};
|
|
121
|
+
const total = Math.max(0, Number(data.total ?? 0) - (asksOn ? 0 : Number(counts.ask ?? 0)));
|
|
122
|
+
if (!total && !items.length) return { payload, human: ["Nothing from lanes is waiting on you.", asksOff].filter(Boolean).join(" ") };
|
|
123
|
+
const count = (kind, one, many) => `${counts[kind] ?? 0} ${(counts[kind] ?? 0) === 1 ? one : many}`;
|
|
124
|
+
const lines = [`${total} from lanes waiting on you (oldest ${age(data.oldestSeconds)}): ${asksOn ? `${count("ask", "question", "questions")}, ` : ""}${count("leeway", "leeway", "leeways")}, ${count("wait", "wait", "waits")}, ${count("escalation", "escalation", "escalations")}.`];
|
|
125
|
+
for (const item of items) {
|
|
126
|
+
const note = deferred(item, now()) || item.deferredUntil ? ` (deferred until ${item.deferredUntil})` : item.gates ? "" : " (counted, never gates)";
|
|
127
|
+
lines.push(`${item.kind}\t${item.laneKey}\t${age(item.ageSeconds)}\t${String(item.summary ?? "").replace(/\s+/g, " ").trim()}${note}`);
|
|
128
|
+
if (item.command) lines.push(` ${item.command}`);
|
|
129
|
+
}
|
|
130
|
+
lines.push(
|
|
131
|
+
asksOn
|
|
132
|
+
? `Asks and leeways older than ${GATE_AFTER_SECONDS / 60} minutes hold your next nodii-dev write: answer, grant, refuse, or defer with a reason (nodii-dev lane defer <id> --reason TEXT [--minutes N]).`
|
|
133
|
+
: `Leeways older than ${GATE_AFTER_SECONDS / 60} minutes hold your next nodii-dev write: grant, refuse, or defer with a reason (nodii-dev lane defer <id> --reason TEXT [--minutes N]). ${asksOff}`,
|
|
134
|
+
);
|
|
135
|
+
return { payload, human: lines.join("\n") };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ─── The coordinator gate ───────────────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
/** `coordinator start` writes this beside the config; the dispatcher checks it so only a coordinator session pays for the gate. */
|
|
141
|
+
export const coordinatorMarkerPath = (env = process.env) => join(dirname(env.NODII_DEV_CONFIG_PATH ?? join(homedir(), ".config/nodii-dev/config.json")), "coordinator.json");
|
|
142
|
+
|
|
143
|
+
const markerExists = async (env) => {
|
|
144
|
+
try { await access(coordinatorMarkerPath(env)); return true; } catch { return false; }
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/** Remove the marker when it names this run (the coordinator session ended). */
|
|
148
|
+
export async function clearCoordinatorMarker(runId, { env = process.env } = {}) {
|
|
149
|
+
try {
|
|
150
|
+
const path = coordinatorMarkerPath(env);
|
|
151
|
+
if (JSON.parse(await readFile(path, "utf8"))?.runId === runId) await rm(path, { force: true });
|
|
152
|
+
} catch {}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Commands that never write lane or issue state in Dev, or that a coordinator must always be able to run.
|
|
156
|
+
const NEVER_GATED = new Set(["hook", "heavy", "run", "help", "doctor", "whoami", "config", "login", "logout", "rulebook", "rules", "inbox", "coordinator", "harness", "setup", "watchdog", "test", "repo", "state", "heartbeat", "next", "gather", "chrome", "receipt", "sync"]);
|
|
157
|
+
const READ_ACTIONS = new Set(["list", "show", "get", "diff", "versions", "status", "find", "parked", "audit", "usage", "accounts", "entries", "check", "board", "watch", "history", "timings", "behind", "resolve", "methodology", "lane-state", "overrides", "reviews", "waits", "asks"]);
|
|
158
|
+
// The lane actions that clear an item, close out a lane or bring one back.
|
|
159
|
+
const LANE_ALLOWED = new Set(["answer", "defer", "resume", "close", "stop", "closeout"]);
|
|
160
|
+
// Lane actions with a subcommand: which of them write.
|
|
161
|
+
const LANE_SUB_WRITES = {
|
|
162
|
+
leeway: (sub) => !["grant", "refuse", "show", "list"].includes(sub),
|
|
163
|
+
amendments: (sub) => ["approve", "reject", "withdraw"].includes(sub),
|
|
164
|
+
freeze: (sub) => ["add", "drop", "swap"].includes(sub),
|
|
165
|
+
authority: (sub) => sub === "record",
|
|
166
|
+
};
|
|
167
|
+
const SUB_VERBS = new Set(["withdraw", "approve", "reject", "add", "drop", "swap", "record"]);
|
|
168
|
+
const INVOCATION = /(?:nodii-dev(?:\.js)?|@nodii\/dev(?:@[\w.-]+)?)["']?((?:\s+--?[\w-]+(?:=\S+)?)*)\s+([a-z][\w-]*)([^;&|\n]*)/g;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The nodii-dev write a Bash command makes, as "lane launch", or null. Reads,
|
|
172
|
+
* local commands and the commands that clear lane items are never writes here.
|
|
173
|
+
*/
|
|
174
|
+
export function gatedCommand(command) {
|
|
175
|
+
for (const [, , name, rest] of String(command ?? "").matchAll(INVOCATION)) {
|
|
176
|
+
if (NEVER_GATED.has(name)) continue;
|
|
177
|
+
const tokens = rest.trim().split(/\s+/).filter(Boolean);
|
|
178
|
+
if (tokens.some((token) => token === "--help" || token === "-h")) continue;
|
|
179
|
+
// The action is the first word; a flag's value is never one of ours, since flags follow the action.
|
|
180
|
+
const action = tokens[0] && !tokens[0].startsWith("-") ? tokens[0] : undefined;
|
|
181
|
+
const third = action && tokens[1] && !tokens[1].startsWith("-") ? tokens[1] : undefined;
|
|
182
|
+
if (!action) continue;
|
|
183
|
+
if (name === "lane") {
|
|
184
|
+
if (LANE_ALLOWED.has(action) || READ_ACTIONS.has(action)) continue;
|
|
185
|
+
if (LANE_SUB_WRITES[action]) {
|
|
186
|
+
if (!LANE_SUB_WRITES[action](third)) continue;
|
|
187
|
+
return `lane ${action}${SUB_VERBS.has(third) ? ` ${third}` : ""}`;
|
|
188
|
+
}
|
|
189
|
+
return `lane ${action}`;
|
|
190
|
+
}
|
|
191
|
+
if (READ_ACTIONS.has(action)) continue;
|
|
192
|
+
return `${name} ${action}`;
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* PreToolUse on Bash and AskUserQuestion, for a coordinator session. Denies a
|
|
199
|
+
* nodii-dev write while an ask or a leeway has waited over 10 minutes
|
|
200
|
+
* undeferred, naming each with the command that clears it. A question to the
|
|
201
|
+
* operator is never denied (MW1-116: an override or a lock change is asked the
|
|
202
|
+
* moment it arises): it passes with the same items named as context. Fails
|
|
203
|
+
* open: when Dev cannot be read the call passes with a note.
|
|
204
|
+
* Returns { deny }, { context } or null.
|
|
205
|
+
*/
|
|
206
|
+
export async function coordinatorGate(payload, deps = {}) {
|
|
207
|
+
const tool = payload?.tool_name;
|
|
208
|
+
const what = tool === "AskUserQuestion" ? "asking the operator" : tool === "Bash" ? gatedCommand(payload?.tool_input?.command) : null;
|
|
209
|
+
if (!what) return null;
|
|
210
|
+
const env = deps.env ?? process.env;
|
|
211
|
+
if (!(await (deps.coordinatorMarker ?? markerExists)(env))) return null;
|
|
212
|
+
const now = (deps.now ?? Date.now)();
|
|
213
|
+
let items;
|
|
214
|
+
try {
|
|
215
|
+
const request = deps.request ?? devRequest;
|
|
216
|
+
const cache = "cache" in deps ? deps.cache : laneReadCache({ ttlMs: GATE_CACHE_TTL_MS });
|
|
217
|
+
const read = (method, path) => request(method, path, undefined, { signal: AbortSignal.timeout(GATE_TIMEOUT_MS) });
|
|
218
|
+
items = (await cachedGet(cache, read, ITEMS_PATH)).data?.items ?? [];
|
|
219
|
+
} catch {
|
|
220
|
+
return { context: "lane items unread: Dev unreachable" };
|
|
221
|
+
}
|
|
222
|
+
// Lane asks off (MW1-37.2): a question never holds the coordinator, since it could not clear one.
|
|
223
|
+
const asksOn = laneAsksOn(env);
|
|
224
|
+
const overdue = items.filter((item) => item?.gates === true && (asksOn || item.kind !== "ask") && Number(item.ageSeconds) > GATE_AFTER_SECONDS && !deferred(item, now));
|
|
225
|
+
if (!overdue.length) return null;
|
|
226
|
+
const lines = [
|
|
227
|
+
...overdue.flatMap((item) => [` ${item.kind} ${item.laneKey} (${age(item.ageSeconds)}): ${String(item.summary ?? "").replace(/\s+/g, " ").trim()}`, ...(item.command ? [` ${item.command}`] : [])]),
|
|
228
|
+
"Defer one with a reason: nodii-dev lane defer <id> --reason TEXT [--minutes N]. List them: nodii-dev coordinator items.",
|
|
229
|
+
];
|
|
230
|
+
const waited = `${overdue.length} lane item${overdue.length === 1 ? " has" : "s have"} waited over ${GATE_AFTER_SECONDS / 60} minutes.`;
|
|
231
|
+
// MW1-116: the operator question goes through; the coordinator is told what still waits.
|
|
232
|
+
if (tool === "AskUserQuestion")
|
|
233
|
+
return { context: [`nodii-dev coordinator gate (MW1-37.2): ${waited} Your question to the operator is not held (MW1-116); ${asksOn ? "answer, " : ""}grant, refuse or defer each right after it:`, ...lines].join("\n") };
|
|
234
|
+
return { deny: [`nodii-dev coordinator gate (MW1-37.2): ${waited} ${asksOn ? "Answer, grant" : "Grant"}, refuse or defer each before \`${what}\`:`, ...lines].join("\n") };
|
|
235
|
+
}
|
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.175";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
|
@@ -339,9 +339,20 @@ async function devFetch(method, path, bodyText, contentType, accept, extra = {},
|
|
|
339
339
|
return send(grant);
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
+
// MW1-37.2: Dev names the lane items waiting on a machine's coordinator in a
|
|
343
|
+
// response header. The CLI's entry point registers who reads it; it never
|
|
344
|
+
// fails a request.
|
|
345
|
+
let laneItemsObserver = null;
|
|
346
|
+
export function setLaneItemsObserver(observer) {
|
|
347
|
+
laneItemsObserver = observer;
|
|
348
|
+
}
|
|
349
|
+
|
|
342
350
|
/** A JSON call that keeps the status: `{ status, payload }`. Errors throw as devRawRequest's do. */
|
|
343
351
|
export async function devExchange(method, path, bodyText, { contentType = "application/json", headers = {}, signal } = {}) {
|
|
344
352
|
const { response, raw } = await devFetch(method, path, bodyText, contentType, "application/json", headers, signal);
|
|
353
|
+
if (laneItemsObserver) {
|
|
354
|
+
try { await laneItemsObserver(response.headers?.get?.("x-dev-lane-items") ?? null); } catch {}
|
|
355
|
+
}
|
|
345
356
|
let payload;
|
|
346
357
|
try {
|
|
347
358
|
payload = raw ? JSON.parse(raw) : {};
|
|
@@ -394,7 +405,7 @@ export async function checkLogin() {
|
|
|
394
405
|
export const encode = (value) => encodeURIComponent(value);
|
|
395
406
|
// Switches never take the next token as their value, so
|
|
396
407
|
// `docs upload --wait rulebook/` keeps rulebook/ as a path.
|
|
397
|
-
const SWITCHES = new Set(["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"]);
|
|
398
409
|
export function parseArgs(argv) {
|
|
399
410
|
const flags = {};
|
|
400
411
|
const args = [];
|