@nodii/dev 0.6.82 → 0.6.83

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/dist/cli.js CHANGED
@@ -21,7 +21,7 @@ import {
21
21
  refuseFromLane,
22
22
  revokeOAuth,
23
23
  } from "./oauth.js";
24
- import { FIGMA_HOOK_DENIALS, heartbeatCurrentLane, postHook, postHookFailure, preHook, settingsSnippet, workflowSuggestion } from "./hooks.js";
24
+ import { FIGMA_HOOK_DENIALS, heartbeatFromHook, postHook, postHookFailure, preHook, settingsSnippet, workflowSuggestion } from "./hooks.js";
25
25
  import { setupCommand } from "./setup.js";
26
26
  import { harnessCommand } from "./harness.js";
27
27
  import { repoCommand } from "./repo-policy.js";
@@ -686,7 +686,9 @@ export async function main(argv = process.argv.slice(2)) {
686
686
  // A nudge hook is fail-open and writes only its own JSON: it cannot run a
687
687
  // Delta gather, and a waiting-results banner would corrupt its output.
688
688
  // surface-gen-pre runs in every session, lane or not, so it never reaches Dev.
689
- if (argv[0] !== "__run-supervisor" && !readsHelp(argv) && !(argv[0] === "hook" && (argv[1]?.startsWith("nudge-") || argv[1] === "surface-gen-pre"))) {
689
+ // The heartbeat hook fires on every tool call, so these checks would call Dev each
690
+ // time past its rate limit, and a failed check would silently stop the heartbeat.
691
+ if (argv[0] !== "__run-supervisor" && !readsHelp(argv) && !(argv[0] === "hook" && (argv[1]?.startsWith("nudge-") || argv[1] === "surface-gen-pre" || argv[1] === "lane-heartbeat"))) {
690
692
  await amendmentGuard(argv);
691
693
  await showWaitingResults({ acknowledge: argv[0] !== "hook" });
692
694
  }
@@ -1459,8 +1461,16 @@ export async function main(argv = process.argv.slice(2)) {
1459
1461
  return;
1460
1462
  }
1461
1463
  if (action === "lane-heartbeat") {
1462
- const result = await heartbeatCurrentLane();
1463
- return emit(result, json, result.heartbeated ? `Heartbeat recorded for ${result.key}.` : "No current-branch lane; no heartbeat sent.");
1464
+ // A heartbeat never blocks the tool call or the stop that fired it.
1465
+ try {
1466
+ let payload = {};
1467
+ if (!process.stdin.isTTY) { try { payload = JSON.parse(await stdinText()); } catch {} }
1468
+ const result = await heartbeatFromHook(payload);
1469
+ return emit(result, json, result.heartbeated ? `Heartbeat recorded for ${result.key}.` : `No heartbeat sent: ${result.reason}.`);
1470
+ } catch (error) {
1471
+ process.stderr.write(`nodii-dev lane heartbeat: ${error?.code ?? "ERROR"}: ${error?.message ?? String(error)}\n`);
1472
+ return;
1473
+ }
1464
1474
  }
1465
1475
  const payload = JSON.parse(await stdinText());
1466
1476
  await recordHookFire(payload).catch(() => {});
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.82";
7
+ export const VERSION = "0.6.83";
8
8
  export const configPath = () =>
9
9
  process.env.NODII_DEV_CONFIG_PATH ??
10
10
  join(homedir(), ".config/nodii-dev/config.json");
package/dist/doctor.js CHANGED
@@ -342,7 +342,7 @@ export async function doctorCommand(deps = {}) {
342
342
  else if (claude && runtime.managedState === "merged_stale") checks.push(missing(key, `${runtime.managedPath} was merged by hand and its nodii-dev routes are out of date`, "update its hooks by hand from ~/.config/nodii-dev/claude-managed-hooks/managed-settings.json", extra));
343
343
  else if (!runtime.trusted) checks.push(missing(key, `hooks are installed but not trusted${runtime.trustStatuses?.length ? ` (${runtime.trustStatuses.join(", ")})` : ""}`, runtime.runtime.startsWith("codex") ? "review /hooks, or have an operator run the commands printed by `nodii-dev harness update --system`" : "review the runtime hook configuration", extra));
344
344
  else if (runtime.managed && runtime.cliStatus?.ok === false) checks.push(missing(key, `${runtime.cliStatus.message}; managed hooks fail open until this is fixed`, "update nodii-dev, then run `nodii-dev harness update --system` to refresh the absolute CLI path", extra));
345
- else if (!runtime.firing) checks.push(missing(key, `hooks are installed and trusted${runtime.managed ? " (managed)" : ""}, but no firing receipt exists`, "start a fresh runtime session and run doctor again", extra));
345
+ else if (!runtime.firing) checks.push(missing(key, `hooks are installed and trusted${runtime.managed ? " (managed)" : ""}, but no firing receipt from this profile in this worktree (receipts are per worktree)`, "start a fresh runtime session and run doctor again", extra));
346
346
  else checks.push(ok(key, `installed, trusted${runtime.managed ? " (managed)" : ""}, and firing (last ${runtime.lastFiredAt})`, extra));
347
347
  }
348
348
  } catch (error) {
package/dist/harness.js CHANGED
@@ -11,6 +11,7 @@ import { fileURLToPath } from "node:url";
11
11
  import { promisify } from "node:util";
12
12
  import { CliError, devRequest, query } from "./core.js";
13
13
  import { classifyClaudeManaged, claudeManagedSettingsPath, managedClaudeHookBundle, managedHookBundle, nodiiCommandArgs, refreshManagedDispatchers, writeManagedClaudeHookBundle, writeManagedHookBundle } from "./managed-hooks.js";
14
+ import { heartbeatSettingsSnippet } from "./hooks.js";
14
15
  import { nudgeSettingsSnippet } from "./nudges.js";
15
16
  import { codexSafetyHooksSnippet, regroundingHooksSnippet, safetySettingsSnippet } from "./safety.js";
16
17
 
@@ -199,6 +200,7 @@ export function withSafetyHooks(harness) {
199
200
  const parsed = JSON.parse(settings.content);
200
201
  let hooks = addHookEntries(parsed.hooks, safetySettingsSnippet().hooks);
201
202
  hooks = addHookEntries(hooks, regroundingHooksSnippet().hooks);
203
+ hooks = addHookEntries(hooks, heartbeatSettingsSnippet().hooks);
202
204
  hooks = addHookEntries(hooks, nudgeSettingsSnippet().hooks);
203
205
  assertNodiiHooks(hooks, ".claude/settings.json");
204
206
  settings.content = JSON.stringify({ ...parsed, hooks });
package/dist/hooks.js CHANGED
@@ -2,7 +2,7 @@ import { CliError, devRequest } from "./core.js";
2
2
  import { FOUNDATIONS_ID, figmaLockCheck, outOfScopeText } from "./figma.js";
3
3
  import { assertWithinLaneScope, currentLaneFigmaScope } from "./figma-scope.js";
4
4
  import { execFile } from "node:child_process";
5
- import { readFile } from "node:fs/promises";
5
+ import { readFile, writeFile } from "node:fs/promises";
6
6
  import { promisify } from "node:util";
7
7
  import { safetySettingsSnippet } from "./safety.js";
8
8
 
@@ -218,13 +218,38 @@ export const settingsSnippet = () => {
218
218
  } };
219
219
  };
220
220
 
221
- export async function heartbeatCurrentLane(request = devRequest) {
221
+ // MW1-34, MW5-17: the harness heartbeats a live lane on tool use and stop, about
222
+ // once a minute. The lane heartbeat also refreshes the lane's run in Dev. The
223
+ // supervisor's run heartbeat says only that the process is alive; this one says
224
+ // the agent acted, which is what keeps `stuck` meaningful.
225
+ export const HEARTBEAT_STAMP = "nodii-lane-heartbeat-at";
226
+ export const HEARTBEAT_MIN_INTERVAL_MS = 60_000;
227
+ export const heartbeatSettingsSnippet = () => {
228
+ const beat = [{ hooks: [{ type: "command", command: "nodii-dev hook lane-heartbeat" }] }];
229
+ return { hooks: { PostToolUse: beat, Stop: beat } };
230
+ };
231
+
232
+ /** One rate-limited heartbeat for the worktree a hook fired in. The stamp is written first, so parallel tool calls send one. */
233
+ export async function heartbeatFromHook(payload, { request = devRequest, now = Date.now, minIntervalMs = HEARTBEAT_MIN_INTERVAL_MS } = {}) {
234
+ const cwd = payload?.cwd ?? process.cwd();
235
+ let stamp;
236
+ try { stamp = (await execFileAsync("git", ["rev-parse", "--path-format=absolute", "--git-path", HEARTBEAT_STAMP], { cwd, encoding: "utf8" })).stdout.trim(); }
237
+ catch { return { heartbeated: false, reason: "not a git worktree" }; }
238
+ const last = Number(await readFile(stamp, "utf8").catch(() => 0));
239
+ const at = now();
240
+ // A stamp from the future (a clock change) must not silence the lane.
241
+ if (at >= last && at - last < minIntervalMs) return { heartbeated: false, reason: "rate limited" };
242
+ await writeFile(stamp, String(at));
243
+ return heartbeatCurrentLane(request, { cwd });
244
+ }
245
+
246
+ export async function heartbeatCurrentLane(request = devRequest, { cwd = process.cwd() } = {}) {
222
247
  let branch;
223
- try { branch = (await execFileAsync("git", ["branch", "--show-current"], { encoding: "utf8" })).stdout.trim(); }
248
+ try { branch = (await execFileAsync("git", ["branch", "--show-current"], { cwd, encoding: "utf8" })).stdout.trim(); }
224
249
  catch { return { heartbeated: false, reason: "not a git worktree" }; }
225
250
  if (!branch) return { heartbeated: false, reason: "detached HEAD" };
226
251
  try {
227
- const markerPath = (await execFileAsync("git", ["rev-parse", "--path-format=absolute", "--git-path", "nodii-lane.json"], { encoding: "utf8" })).stdout.trim();
252
+ const markerPath = (await execFileAsync("git", ["rev-parse", "--path-format=absolute", "--git-path", "nodii-lane.json"], { cwd, encoding: "utf8" })).stdout.trim();
228
253
  const marker = JSON.parse(await readFile(markerPath, "utf8"));
229
254
  const lane = (await request("GET", `/api/v1/lanes/${encodeURIComponent(marker.laneKey)}`)).data;
230
255
  if (lane.repositories?.some((repository) => repository.branch === branch)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.82",
3
+ "version": "0.6.83",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {