@nodii/dev 0.6.215 → 0.6.216

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 CHANGED
@@ -1493,6 +1493,13 @@ product-page catalog names the Surface by its published component-set key
1493
1493
  whole, `value={loading ? <Skeleton shape="text" /> : <PiiText value={emailValue} … />}`,
1494
1494
  so PiiText's `value` stays `string | null`. A value that reads nothing (fixed
1495
1495
  copy) is left as it is.
1496
+ - **A Field's label names its picker (hub-692).** Inside a
1497
+ `<Field htmlFor={x}>`, the first `MultiSelect`, `MultiCombobox`, `Combobox`,
1498
+ `InputChips` or `TimePicker` with no id of its own takes `id={x}`, so the
1499
+ label points at a control that declares that id in the source (the console's
1500
+ label fence reads the source, not the runtime Field wiring). A picker with its
1501
+ own id keeps it; only one picker per Field takes the id. `InputChips` takes
1502
+ `id` from DESIGN-SYSTEM-1132.
1496
1503
  - **A one-line Rich Cell truncates (hub-646).** In a fixed-layout
1497
1504
  table a Table Rich Cell (`contentLayout`) whose content slot holds only one
1498
1505
  text that hugs its width takes `truncate`, as a one-line Table cell does
@@ -1509,6 +1516,30 @@ product-page catalog names the Surface by its published component-set key
1509
1516
  optional, as a lifted table's person cell takes `{ value, model, relation,
1510
1517
  maskHint? }`. The page passes them through as served: the relation keeps a
1511
1518
  self value revealed, and the generator never sets a mask (P-10).
1519
+ - **Every PiiText passes the server's hint (NODII-DEV-CLI-257).** Outside a
1520
+ fact row too, a PiiText whose template draws no `maskHint` (a Code Connect
1521
+ from before DESIGN-SYSTEM-799) takes an optional `<scope>MaskHint` prop,
1522
+ placed after `relation`, so the console's mask-hint gate finds a hint on
1523
+ every generated tag. A hint the template already passes is kept once; a
1524
+ literal `forceVisible` (the viewer's own value) takes none.
1525
+ - **A name slot never takes an address, and an unresolved name says so
1526
+ (hub-692).** A PiiText whose table column or fact is named for an
1527
+ address (`email`, `workEmail`) or a phone (`phone`, `mobileNumber`) is drawn
1528
+ with that kind, `email` or `phone`, even where Figma's sample drew `name`; any
1529
+ other kind Figma states is kept. Every name-kind PiiText that reads the page's
1530
+ data also takes an optional unresolved flag (`<name>Unresolved?: boolean` for a
1531
+ fact, `unresolved?: boolean` on a lifted row's person field). When the page sets
1532
+ it, the slot draws the DS PersonName's `unresolved` state, "Name not available",
1533
+ in place of PiiText; left unset, the slot is PiiText as before. The page sets it
1534
+ when its identity resolution found no name (no row it can read), never for a
1535
+ withheld name, which stays PiiText's Restricted render or the server's hint.
1536
+ - **Every PiiText's mask hint is one optional prop, and it is rendered
1537
+ (NODII-DEV-CLI-257).** Wherever a PiiText sits, the `maskHint` the page
1538
+ declares for it is the one that PiiText renders, and it is optional, because
1539
+ the server may send no hint: the bare `maskHint={maskHint}` a strict or
1540
+ revealed drawing writes keeps its name (`maskHint`, `secondMaskHint`, …) and
1541
+ is no longer required, and a hint drawing's lifted sample is optional outside
1542
+ a fact row too. A page needs no second hand-added hint prop.
1512
1543
  - **A record page's title and body are its data (NODII-DEV-CLI-293).** On a
1513
1544
  page whose route ends in a record (`/app/me/forum/policies/$id`, or a tab of it
1514
1545
  with `?tab=`; with no route, a set named `… .$id …`), the first title-sized
@@ -1880,6 +1911,51 @@ Inside a lane, a failed check is noted in the step, and the harness files
1880
1911
  are left alone; the repository's orchestrator runs `harness update` in a
1881
1912
  `chore` lane (MW5-8).
1882
1913
 
1914
+ ### Push after every commit (O22)
1915
+
1916
+ `harness install` and `harness update` (not `--dry-run`) also write a git
1917
+ hook, `push-hook.sh` from this package, as both `post-commit` and
1918
+ `post-rewrite` in the directory `git rev-parse --git-path hooks` names, so a
1919
+ `core.hooksPath` is respected. They do this first, from the CLI's own copy,
1920
+ so a checkout that cannot reach Dev still gets them. A hook already there that
1921
+ nodii-dev did not write is moved to `<hook>.nodii-chained` and keeps running
1922
+ first, with the same arguments and input. When one is already chained, the new
1923
+ one is left alone and the output says so. The hooks sit in the git directory,
1924
+ not the working tree. Every worktree of the repository shares them, and they
1925
+ are not harness files.
1926
+
1927
+ After every commit, amend or rebase, the hook returns at once and, in the
1928
+ background:
1929
+
1930
+ - pushes the current branch's tip to `origin`, never with force and never
1931
+ `main` or `master`. A commit on a detached HEAD is not pushed: an `INFO`
1932
+ line logs it.
1933
+ - first scans the commits not yet on any origin ref with
1934
+ `gitleaks git --redact`. A finding means no push, `secret found: RULE FILE
1935
+ (commit SHORT)` in the log and the state `push blocked: secret`. gitleaks
1936
+ missing or failing also means no push: `secret scan unavailable`. The commit
1937
+ itself always succeeds, and a secret's value is never printed.
1938
+ - on a non-fast-forward, logs `superseded` when origin already holds the
1939
+ commit. Otherwise it logs `diverged: needs push --force-with-lease by a
1940
+ person`.
1941
+ - when the repository's own `pre-push` hook refuses, logs it and does not
1942
+ retry: push by hand.
1943
+ - retries any other failure, such as origin being unreachable, at 20 s,
1944
+ doubling up to 5 minutes, for up to 24 h.
1945
+ - after a push lands, opens a draft PR against main (`origin/HEAD`, else
1946
+ `main`) when the branch has no open PR, retried the same way. A repository
1947
+ without draft PRs gets a ready one.
1948
+
1949
+ GitHub is reached at `GITHUB_API_URL` (default `https://api.github.com`), with
1950
+ `GH_TOKEN`, `GITHUB_TOKEN` or `gh auth token`. On api.github.com, the PR list
1951
+ reads use `nodii-dev github research-token` when it works. The log is
1952
+ `<git-common-dir>/nodii-push.log`. Each branch's last state is in
1953
+ `<git-common-dir>/nodii-push/<branch, / as ~>.state`. `watchdog sweep` adds
1954
+ that state to the lane run's `worktree_unpushed` report, as `; push hook:
1955
+ STATE (at TIME)`. A commit that fires no hook (`git am`, `commit-tree` with
1956
+ `update-ref`, `-c core.hooksPath=/dev/null`) is left to the watchdog's
1957
+ unpushed-worktree report.
1958
+
1883
1959
  `harness update` keeps whether this machine's managed install needs root in
1884
1960
  `~/.config/nodii-dev/needs-root.json`: `true` when npm refuses with a
1885
1961
  permission error at `~/.local` (the fallback itself, or no fallback to
package/dist/core.js CHANGED
@@ -4,7 +4,7 @@ import { chmod, lstat, mkdir, readFile, rename, rm, writeFile } from "node:fs/pr
4
4
  import { homedir, platform } from "node:os";
5
5
  import { basename, dirname, join } from "node:path";
6
6
 
7
- export const VERSION = "0.6.215";
7
+ export const VERSION = "0.6.216";
8
8
  export const configPath = () =>
9
9
  process.env.NODII_DEV_CONFIG_PATH ??
10
10
  join(homedir(), ".config/nodii-dev/config.json");
package/dist/harness.js CHANGED
@@ -14,6 +14,7 @@ import { classifyClaudeManaged, claudeManagedSettingsPath, managedClaudeHookBund
14
14
  import { heartbeatSettingsSnippet, settingsSnippet } from "./hooks.js";
15
15
  import { nudgeSettingsSnippet } from "./nudges.js";
16
16
  import { toolingDocsSettingsSnippet } from "./tooling-docs.js";
17
+ import { installPushHooks, pushHooksLine } from "./push-hooks.js";
17
18
  import { codexSafetyHooksSnippet, regroundingHooksSnippet, safetySettingsSnippet } from "./safety.js";
18
19
 
19
20
  /** What this CLI wrote, per path: { mode, sha256 }, or for merge-json the hook entries it `added`. */
@@ -472,7 +473,7 @@ async function checkCommand(root, repo, state, fetchHarness) {
472
473
  };
473
474
  }
474
475
 
475
- export async function harnessCommand(action, flags, { request = devRequest, context = repoContext, managedHome, managedCliPath = fileURLToPath(new URL("../bin/nodii-dev", import.meta.url)), writeManaged = writeManagedHookBundle, writeManagedClaude = writeManagedClaudeHookBundle, refreshManaged = refreshManagedDispatchers, installManaged = async () => null, claudeManagedPath = claudeManagedSettingsPath(), readSystem = optional } = {}) {
476
+ export async function harnessCommand(action, flags, { request = devRequest, context = repoContext, managedHome, managedCliPath = fileURLToPath(new URL("../bin/nodii-dev", import.meta.url)), writeManaged = writeManagedHookBundle, writeManagedClaude = writeManagedClaudeHookBundle, refreshManaged = refreshManagedDispatchers, installManaged = async () => null, claudeManagedPath = claudeManagedSettingsPath(), readSystem = optional, pushHooks = installPushHooks } = {}) {
476
477
  if (!["install", "update", "check"].includes(action)) throw new CliError("USAGE", "harness install|update|check [--repo NAME] [--service ID] [--include-drafts[=false]] [--adopt PATH,...] [--dry-run] [--check] [--system]", 2);
477
478
  if (flags.fleet || flags.all) throw new CliError("USAGE", "The harness is installed one service at a time, in that service's repository. There is no fleet mode.", 2);
478
479
  if (flags.root === true || flags.repo === true) throw new CliError("USAGE", "--root and --repo need a value.", 2);
@@ -517,7 +518,16 @@ export async function harnessCommand(action, flags, { request = devRequest, cont
517
518
  if (action === "check" && (flags["dry-run"] || flags.adopt || flags.system)) throw new CliError("USAGE", "harness check writes nothing; --dry-run, --adopt and --system go with install and update.", 2);
518
519
  if (action === "check" || (action === "update" && flags.check)) return checkCommand(ctx.root, repo, state, fetchHarness);
519
520
 
520
- const harness = (await fetchHarness({ draftFallback: true })).data;
521
+ // The push hooks (O22) are git's, not Dev's: they go in first, from this
522
+ // CLI's own copy, so a checkout that cannot reach Dev still pushes its commits.
523
+ const pushed = ctx && !machineOnly ? await pushHooks(ctx.root, { dryRun: Boolean(flags["dry-run"]) }) : [];
524
+ const pushText = pushHooksLine(pushed, { dryRun: Boolean(flags["dry-run"]) });
525
+ let harness;
526
+ try { harness = (await fetchHarness({ draftFallback: true })).data; }
527
+ catch (error) {
528
+ if (pushText && error instanceof CliError) error.message = `${error.message}\n${pushText}`;
529
+ throw error;
530
+ }
521
531
  const plan = machineOnly ? { changes: [], conflicts: [] } : await planHarness(ctx.root, harness, { install: action === "install", adopt: flagList(flags.adopt), request: { ...(serviceId ? { serviceId } : {}), includeDrafts: effectiveIncludeDrafts } });
522
532
  const summary = {
523
533
  repo: harness.repo, serviceId: harness.serviceId ?? null,
@@ -526,12 +536,14 @@ export async function harnessCommand(action, flags, { request = devRequest, cont
526
536
  changes: plan.changes.map(({ path, action: a, mode }) => ({ path, action: a, mode })),
527
537
  conflicts: plan.conflicts, warnings: harness.warnings ?? [],
528
538
  };
539
+ if (pushed.length) summary.pushHooks = pushed;
529
540
  if (machineOnly) summary.machineOnly = true;
530
541
  const lines = [
531
542
  `${harness.repo}${harness.serviceId ? ` (${harness.serviceId})` : ""}: methodology ${summary.from ? `${summary.from} → ` : ""}${summary.to}`,
532
543
  ...summary.sources.map((x) => ` source ${x}`),
533
544
  ...plan.changes.map(changeLine),
534
545
  ...summary.warnings.map((w) => `warning: ${w}`),
546
+ ...(pushText ? [pushText] : []),
535
547
  ];
536
548
  if (plan.conflicts.length)
537
549
  throw new CliError("HARNESS_CONFLICT",
@@ -0,0 +1,189 @@
1
+ #!/usr/bin/env bash
2
+ # nodii-dev:push-hook (O22, DEV-PROCESS-13). `nodii-dev harness install|update` copies this file from
3
+ # nodii-dev's src/push-hook.sh; change it there.
4
+ # Installed as both post-commit and post-rewrite where `git rev-parse --git-path hooks` points.
5
+ #
6
+ # After every commit or rewrite it returns at once and, in the background:
7
+ # - pushes the CURRENT branch only (its tip, refs/heads/<br>), never main or master, never with force;
8
+ # a detached HEAD is not pushed and an INFO line is logged;
9
+ # - before any push, scans the commits not yet on any origin ref with `gitleaks git --redact`. A finding,
10
+ # or gitleaks missing or failing, means NO push ("push blocked: secret" / "secret scan unavailable");
11
+ # the commit has already succeeded and no secret's value is ever printed;
12
+ # - a non-fast-forward rejection: if origin already holds the commit it is "superseded"; otherwise the
13
+ # branch has diverged (amend or rebase after a push) and it logs
14
+ # "diverged: needs push --force-with-lease by a person";
15
+ # - a refusal by the repository's own pre-push hook is logged and not retried (push it by hand);
16
+ # - any other failure (origin unreachable) is retried with backoff (20 s doubling, capped at 300 s)
17
+ # until it lands, for up to 24 h;
18
+ # - after a push lands, opens a draft PR against main when the branch has none, retried the same way.
19
+ # The GitHub API base is GITHUB_API_URL (default https://api.github.com). Token: GH_TOKEN, GITHUB_TOKEN,
20
+ # else `gh auth token`; on api.github.com, PR reads use `nodii-dev github research-token` when it works.
21
+ # Log: <git-common-dir>/nodii-push.log. Last state per branch: <git-common-dir>/nodii-push/<branch>.state,
22
+ # which `nodii-dev watchdog sweep` adds to the lane run's unpushed-worktree report.
23
+ set -u
24
+ HOOK=$(basename "$0")
25
+ CHAINED="$0.nodii-chained"
26
+ input=""
27
+ [ "$HOOK" = post-rewrite ] && input=$(cat)
28
+ # A hook that was here before nodii-dev keeps running first, with the same arguments and input.
29
+ if [ -x "$CHAINED" ]; then
30
+ if [ "$HOOK" = post-rewrite ]; then printf '%s\n' "$input" | "$CHAINED" "$@"; else "$CHAINED" "$@"; fi
31
+ fi
32
+
33
+ GCD=$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null) || exit 0
34
+ LOG=$GCD/nodii-push.log
35
+ now() { date +%s; }
36
+ if ! br=$(git symbolic-ref --quiet --short HEAD); then
37
+ printf '%s - INFO detached commit %s not pushed (hook %s)\n' "$(now)" "$(git rev-parse HEAD 2>/dev/null)" "$HOOK" >> "$LOG"
38
+ exit 0
39
+ fi
40
+ case $br in main|master) exit 0 ;; esac
41
+ git remote get-url origin >/dev/null 2>&1 || exit 0
42
+
43
+ RETRY_S=20 RETRY_MAX_S=300 WINDOW_S=86400
44
+ API=${GITHUB_API_URL:-https://api.github.com}; API=${API%/}
45
+ STATE_DIR=$GCD/nodii-push
46
+ STATE_FILE=$STATE_DIR/$(printf '%s' "$br" | tr '/' '~').state
47
+ url=$(git config --get remote.origin.url || true)
48
+ owner_repo=$(printf '%s\n' "$url" | sed -nE 's#^(https://([^@/]+@)?github\.com/|git@github\.com:|ssh://git@github\.com/)([^/]+/[^/]+)$#\3#p' | sed 's/\.git$//; s#/$##')
49
+ log() { printf '%s %s %s\n' "$(now)" "$br" "$*" >> "$LOG"; }
50
+ state() { mkdir -p "$STATE_DIR" 2>/dev/null && printf '%s %s\n' "$(now)" "$*" > "$STATE_FILE"; }
51
+ token=""
52
+ write_token() {
53
+ [ -n "$token" ] && return 0
54
+ token=${GH_TOKEN:-${GITHUB_TOKEN:-}}
55
+ [ -z "$token" ] && command -v gh >/dev/null 2>&1 && token=$(gh auth token 2>/dev/null)
56
+ [ -n "$token" ]
57
+ }
58
+ read_token=""
59
+ get_read_token() { # O24: bulk-safe reads on the research App, only against the real GitHub
60
+ [ -n "$read_token" ] && return 0
61
+ if [ "$API" = https://api.github.com ] && command -v nodii-dev >/dev/null 2>&1; then
62
+ read_token=$(nodii-dev github research-token 2>/dev/null) || read_token=""
63
+ fi
64
+ [ -n "$read_token" ] || { write_token && read_token=$token; }
65
+ [ -n "$read_token" ]
66
+ }
67
+ api() { local t=$1; shift; curl -s --max-time 20 -H "Authorization: Bearer $t" -H 'Accept: application/vnd.github+json' "$@"; }
68
+ json_str() { node -e 'process.stdout.write(JSON.stringify(process.argv[1]))' "$1"; }
69
+
70
+ base_branch() {
71
+ local b; b=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null); b=${b#origin/}
72
+ case $b in ''|"$br") echo main ;; *) echo "$b" ;; esac
73
+ }
74
+
75
+ pr_list() { # prints the open PR numbers for the branch ("1,2"), "none", or "error"
76
+ local owner=${owner_repo%%/*}
77
+ get_read_token || { echo error; return; }
78
+ api "$read_token" "$API/repos/$owner_repo/pulls?state=open&head=$owner:$br" |
79
+ node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{const a=JSON.parse(s);console.log(Array.isArray(a)?(a.map(p=>p.number).join(",")||"none"):"error")}catch{console.log("error")}})'
80
+ }
81
+
82
+ pr_title() { # the branch's first commit subject past the base: a display name, never the branch or lane key
83
+ local t; t=$(git log --reverse --format=%s "refs/remotes/origin/$1..refs/heads/$br" 2>/dev/null | head -n 1)
84
+ [ -n "$t" ] || t=$(git log -1 --format=%s "refs/heads/$br" 2>/dev/null)
85
+ printf '%s' "${t:-Work in progress}"
86
+ }
87
+
88
+ open_pr_once() { # 0 = a PR is open for the branch now; 1 = try again
89
+ local nums code base body
90
+ nums=$(pr_list)
91
+ [ "$nums" = error ] && { log "pr-list failed"; read_token=""; return 1; }
92
+ [ "$nums" = none ] || { log "pr-exists #$nums"; state "pushed $(git rev-parse "refs/heads/$br") pr #$nums"; return 0; }
93
+ write_token || { log "pr-create failed: no GitHub token (GH_TOKEN, GITHUB_TOKEN or gh auth)"; return 1; }
94
+ base=$(base_branch)
95
+ body="Opened by the nodii-dev push hook (O22): this lane's branch is pushed after every commit."
96
+ for draft in true false; do
97
+ code=$(api "$token" -o "$STATE_DIR/pr-create.json" -w '%{http_code}' -X POST -H 'content-type: application/json' \
98
+ -d "{\"title\":$(json_str "$(pr_title "$base")"),\"head\":$(json_str "$br"),\"base\":$(json_str "$base"),\"body\":$(json_str "$body"),\"draft\":$draft}" \
99
+ "$API/repos/$owner_repo/pulls")
100
+ log "pr-create base=$base draft=$draft http=$code"
101
+ # A repository without draft PRs refuses draft:true with 422; try once as a ready PR.
102
+ [ "$code" = 422 ] && [ "$draft" = true ] && grep -qi 'draft' "$STATE_DIR/pr-create.json" 2>/dev/null && continue
103
+ break
104
+ done
105
+ rm -f "$STATE_DIR/pr-create.json"
106
+ # Read the result back in its own call (K03-16): the list, not the create's answer, says a PR exists.
107
+ if [ "$code" = 201 ]; then
108
+ nums=$(pr_list)
109
+ case $nums in none|error) log "pr-create read-back: list says $nums" ;; *) log "pr-exists #$nums (read back)"; state "pushed $(git rev-parse "refs/heads/$br") pr #$nums"; return 0 ;; esac
110
+ fi
111
+ return 1 # not created or not read back: the next list decides (a racing worker may have made it: 422)
112
+ }
113
+
114
+ open_pr() {
115
+ [ -n "$owner_repo" ] || { log "pr-skip: origin is not a github.com repository"; return 0; }
116
+ local wait=$RETRY_S start; start=$(now)
117
+ until open_pr_once; do
118
+ if [ $(( $(now) - start + wait )) -gt "$WINDOW_S" ]; then log "pr-gave-up; branch has no PR"; state "no PR: PR create kept failing"; return 1; fi
119
+ log "pr-retry in ${wait}s"; sleep "$wait"; wait=$((wait * 2)); [ "$wait" -gt "$RETRY_MAX_S" ] && wait=$RETRY_MAX_S
120
+ done
121
+ }
122
+
123
+ scan() { # 0 clean; 1 secret found; 2 scan unavailable (fail-closed). Values are never printed.
124
+ local sha=$1 rep rc top
125
+ if ! command -v gitleaks >/dev/null 2>&1; then
126
+ log "secret scan unavailable: gitleaks not installed; $sha not pushed (push blocked: secret scan unavailable)"
127
+ state "push blocked: secret scan unavailable (gitleaks not installed)"; return 2
128
+ fi
129
+ top=$(git rev-parse --show-toplevel); rep=$(mktemp "${TMPDIR:-/tmp}/nodii-push-gitleaks.XXXXXX")
130
+ gitleaks git --no-banner --redact --log-opts="$sha --not --remotes=origin" --report-format json \
131
+ --report-path "$rep" --exit-code 1 "$top" >/dev/null 2>&1; rc=$?
132
+ case $rc in
133
+ 0) rm -f "$rep"; return 0 ;;
134
+ 1) node -e 'for (const f of JSON.parse(require("fs").readFileSync(process.argv[1],"utf8")))
135
+ console.log(`${f.RuleID} ${f.File} ${String(f.Commit).slice(0,8)}`)' "$rep" 2>/dev/null |
136
+ while read -r rule file short; do log "secret found: $rule $file (commit $short)"; done
137
+ rm -f "$rep"; log "push blocked: secret; $sha not pushed"
138
+ state "push blocked: secret (see $LOG)"; return 1 ;;
139
+ *) rm -f "$rep"; log "secret scan unavailable: gitleaks exit $rc; $sha not pushed (push blocked: secret scan unavailable)"
140
+ state "push blocked: secret scan unavailable (gitleaks exit $rc)"; return 2 ;;
141
+ esac
142
+ }
143
+
144
+ # One line of git's error text, with any credentials in a URL removed (S13-6), for the log.
145
+ errline() { printf '%s' "$1" | tr '\n' ' ' | sed -E 's#(://)[^/@ ]+@#\1***@#g' | cut -c1-300; }
146
+ transport_error() { printf '%s' "$1" | grep -qiE 'unreachable|could not read from remote|unable to access|could not resolve|connection|timed out|early eof|remote end hung up|failed to lock|cannot lock ref|RPC failed|SSL|proxy'; }
147
+
148
+ work() {
149
+ local i=0 err wait=$RETRY_S start sha rt pp
150
+ start=$(now)
151
+ mkdir -p "$STATE_DIR"
152
+ while :; do
153
+ i=$((i + 1))
154
+ # Push the branch's tip as it is now, so a burst of commits lands as one push.
155
+ sha=$(git rev-parse --verify --quiet "refs/heads/$br") || { log "branch $br is gone; nothing pushed"; return 0; }
156
+ scan "$sha" || return 0
157
+ if err=$(git push --quiet origin "$sha:refs/heads/$br" 2>&1); then
158
+ # Read the remote branch back in its own call (K03-16): it must hold this commit.
159
+ rt=$(git ls-remote origin "refs/heads/$br" 2>/dev/null | cut -f1)
160
+ if [ "$rt" = "$sha" ] || { [ -n "$rt" ] && git merge-base --is-ancestor "$sha" "$rt" 2>/dev/null; }; then
161
+ log "pushed $sha attempt=$i (origin at $rt)"; state "pushed $sha"
162
+ open_pr; return 0
163
+ fi
164
+ err="push read-back: origin at ${rt:-nothing}, not $sha (connection)"
165
+ fi
166
+ if printf '%s' "$err" | grep -qE 'non-fast-forward|fetch first|\[rejected\]|stale info'; then
167
+ rt=$(git ls-remote origin "refs/heads/$br" 2>/dev/null | cut -f1)
168
+ if [ -n "$rt" ] && git merge-base --is-ancestor "$sha" "$rt" 2>/dev/null; then log "superseded $sha (origin at $rt)"; return 0; fi
169
+ if [ -n "$rt" ] && git merge-base --is-ancestor "$rt" "$sha" 2>/dev/null; then : # origin moved under us; push again
170
+ else
171
+ log "diverged: needs push --force-with-lease by a person; $sha not pushed (origin at ${rt:-none})"
172
+ state "diverged: needs push --force-with-lease by a person (origin at ${rt:-none}, local $sha)"; return 0
173
+ fi
174
+ elif ! transport_error "$err"; then
175
+ pp=$(git rev-parse --git-path hooks/pre-push)
176
+ if [ -x "$pp" ]; then
177
+ log "push refused (pre-push hook or remote): $sha not pushed; push it by hand: $(errline "$err")"
178
+ state "ahead of remote: push refused, push it by hand"; return 0
179
+ fi
180
+ fi
181
+ if [ $(( $(now) - start + wait )) -gt "$WINDOW_S" ]; then log "gave-up $sha after $i attempts; ahead of remote"; state "ahead of remote: gave up after 24 h"; return 1; fi
182
+ log "push-failed $sha attempt=$i, retry in ${wait}s: $(errline "$err")"
183
+ state "ahead of remote: push failing since $start, retrying"
184
+ sleep "$wait"; wait=$((wait * 2)); [ "$wait" -gt "$RETRY_MAX_S" ] && wait=$RETRY_MAX_S
185
+ done
186
+ }
187
+
188
+ ( work ) </dev/null >>"$LOG" 2>&1 &
189
+ exit 0
@@ -0,0 +1,86 @@
1
+ // The git hooks that push a lane's branch after every commit (O22, DEV-PROCESS-13).
2
+ //
3
+ // `nodii-dev harness install|update` writes push-hook.sh (beside this file) as
4
+ // both post-commit and post-rewrite where `git rev-parse --git-path hooks`
5
+ // points, so a core.hooksPath override is respected. A hook that was already
6
+ // there and is not nodii-dev's is kept as <hook>.nodii-chained and still runs
7
+ // first. Hooks live in the git directory, not the working tree, so they are no
8
+ // harness file (MW5-5) and every worktree of the repository shares them.
9
+ import { execFile } from "node:child_process";
10
+ import { chmod, readFile, rename, writeFile, mkdir } from "node:fs/promises";
11
+ import { isAbsolute, join } from "node:path";
12
+ import { promisify } from "node:util";
13
+
14
+ export const PUSH_HOOK_SCRIPT = new URL("./push-hook.sh", import.meta.url);
15
+ export const PUSH_HOOK_MARKER = "nodii-dev:push-hook";
16
+ export const PUSH_HOOK_NAMES = ["post-commit", "post-rewrite"];
17
+ export const CHAINED_SUFFIX = ".nodii-chained";
18
+
19
+ const execFileAsync = promisify(execFile);
20
+ const optional = (path) => readFile(path, "utf8").catch((error) => (error?.code === "ENOENT" ? null : Promise.reject(error)));
21
+ const ours = (text) => text !== null && text.split("\n").slice(0, 3).some((line) => line.includes(PUSH_HOOK_MARKER));
22
+
23
+ /** The hooks directory git uses for this checkout, absolute; null outside a git checkout. */
24
+ export async function gitHooksDir(root, { run = execFileAsync } = {}) {
25
+ let dir;
26
+ try { dir = (await run("git", ["rev-parse", "--git-path", "hooks"], { cwd: root, encoding: "utf8" })).stdout.trim(); }
27
+ catch { return null; }
28
+ return isAbsolute(dir) ? dir : join(root, dir);
29
+ }
30
+
31
+ /**
32
+ * Install or refresh the push hooks. Returns one entry per hook:
33
+ * { hook, path, action: "create"|"update"|"current"|"chain" }; "chain" means
34
+ * an existing hook was moved to <path>.nodii-chained and keeps running first.
35
+ * With `dryRun` it reports what it would do and writes nothing.
36
+ */
37
+ export async function installPushHooks(root, { dryRun = false, run, script } = {}) {
38
+ const dir = await gitHooksDir(root, { run });
39
+ if (!dir) return [];
40
+ const text = script ?? await readFile(PUSH_HOOK_SCRIPT, "utf8");
41
+ const out = [];
42
+ for (const hook of PUSH_HOOK_NAMES) {
43
+ const path = join(dir, hook);
44
+ const current = await optional(path);
45
+ let action;
46
+ if (current === null) action = "create";
47
+ else if (ours(current)) action = current === text ? "current" : "update";
48
+ // A foreign hook is moved aside, never overwritten; if a chained hook is
49
+ // already there too, both are left alone for a person to merge.
50
+ else if ((await optional(path + CHAINED_SUFFIX)) === null) action = "chain";
51
+ else { out.push({ hook, path, action: "skipped", reason: `it is not nodii-dev's and ${hook}${CHAINED_SUFFIX} already exists; merge them by hand` }); continue; }
52
+ if (!dryRun && action !== "current") {
53
+ await mkdir(dir, { recursive: true });
54
+ if (action === "chain") await rename(path, path + CHAINED_SUFFIX);
55
+ await writeFile(path, text);
56
+ await chmod(path, 0o755);
57
+ }
58
+ out.push({ hook, path, action });
59
+ }
60
+ return out;
61
+ }
62
+
63
+ /** One line for the harness command's output, or "" when nothing changed. */
64
+ export function pushHooksLine(results, { dryRun = false } = {}) {
65
+ const changed = results.filter((r) => r.action !== "current");
66
+ if (!changed.length) return "";
67
+ const words = { create: "installed", update: "updated", chain: "installed (the existing hook is kept as .nodii-chained and runs first)", skipped: "not installed" };
68
+ const lines = changed.map((r) => ` ${r.path}: ${dryRun ? "would be " : ""}${words[r.action] ?? r.action}${r.reason ? ` (${r.reason})` : ""}`);
69
+ return `Git push hooks (push the branch after every commit, O22):\n${lines.join("\n")}`;
70
+ }
71
+
72
+ /**
73
+ * The push hook's last recorded state for a branch, from
74
+ * <git-common-dir>/nodii-push/<branch with / as ~>.state, or null.
75
+ */
76
+ export async function pushHookState(worktree, branch, { run = execFileAsync } = {}) {
77
+ if (!branch) return null;
78
+ let common;
79
+ try { common = (await run("git", ["-C", worktree, "rev-parse", "--path-format=absolute", "--git-common-dir"], { encoding: "utf8" })).stdout.trim(); }
80
+ catch { return null; }
81
+ const text = await optional(join(common, "nodii-push", `${branch.replaceAll("/", "~")}.state`)).catch(() => null);
82
+ const line = text?.trim();
83
+ if (!line) return null;
84
+ const match = /^(\d+) (.*)$/.exec(line);
85
+ return match ? { at: new Date(Number(match[1]) * 1000).toISOString(), state: match[2] } : { at: null, state: line };
86
+ }
package/dist/surface.js CHANGED
@@ -34,7 +34,7 @@ import { MIN_FIGMA_INTERVAL_MS, figmaRest } from "./figma-rest.js";
34
34
  import { createRenderer } from "./vendor/render-templates.mjs";
35
35
 
36
36
  /** Bumped whenever the emitted code changes shape for the same inputs. */
37
- export const GENERATOR_FORMAT = 64;
37
+ export const GENERATOR_FORMAT = 65;
38
38
  /**
39
39
  * DS parts that are an item of their parent's own list or grid, so they take no sizing
40
40
  * wrapper: a Detail Section / Row's facts are the section grid's cells, a Right Pane / Row
@@ -719,6 +719,8 @@ export function emitSurface(tree, row, ds) {
719
719
  const data = dataProps(views, propsType);
720
720
  // After the props are typed from what each part draws: a fact's value is its skeleton while loading.
721
721
  skeletonFacts(views, imports, [...factTexts].map((token) => named.get(token) ?? token));
722
+ // Last: a name slot the page could not resolve says "Name not available" (hub-692).
723
+ unresolvedNames(views, data, imports);
722
724
  // A prop is optional when every template that draws it lists it in `metadata.optionalProps`.
723
725
  const optionalNames = new Map();
724
726
  for (const [token, name] of named) {
@@ -1192,6 +1194,8 @@ const literalText = (lit) => JSON.parse(lit.startsWith("{") ? lit.slice(1, -1) :
1192
1194
  */
1193
1195
  const FACT_VALUE_SLOTS = new Map([["Description List", "value"], ["Right Pane / Row", "valueSlot"], ["Detail Section / Row", "valueSlot"]]);
1194
1196
  const FACT_PII_PROPS = ["maskHint", "disposition"];
1197
+ /** A PiiText that never masks: the viewer's own value, `forceVisible` or `forceVisible={true}` (A-142). */
1198
+ const LITERAL_FORCE_VISIBLE = /(?:^|\s)forceVisible(?:=\{\s*true\s*\})?(?=[\s/]|$)/;
1195
1199
  function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
1196
1200
  const lifted = [];
1197
1201
  const lift = (at, name) => (lifted.push(name), mark(ctx, at, name));
@@ -1432,8 +1436,25 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
1432
1436
  // colleague HR withholds reads HR's hint, not "Restricted". Both are optional, the hint
1433
1437
  // too where Figma drew one (the server may send none), and the relation still decides
1434
1438
  // self, so nothing here can force a mask (P-10; DESIGN-SYSTEM-993).
1435
- const hintProp = () => (ctx.factValue ? (lifted.push("maskHint"), optionalMark(ctx, scope, "maskHint")) : lift(scope, "maskHint"));
1436
- let next = hint ? attrs.replace(hint[0], `maskHint={${hintProp()}}`) : attrs;
1439
+ // A fact named for an address or a phone is that kind, not the name Figma's sample drew
1440
+ // (hub-692): `<PiiText kind="name">` around an email masks and announces it as a name.
1441
+ const kindAttr = /\bkind="(name|text)"/.exec(attrs);
1442
+ if (kindAttr) {
1443
+ const kind = fieldPiiKind(scope, kindAttr[1]);
1444
+ if (kind !== kindAttr[1]) attrs = attrs.replace(kindAttr[0], `kind="${kind}"`);
1445
+ }
1446
+ // The hint is the server's, and the server may send none, so the page's prop is optional
1447
+ // wherever PiiText takes one: a hint drawing's lifted sample, and the bare
1448
+ // `maskHint={maskHint}` a strict or revealed drawing writes (DESIGN-SYSTEM-799), which
1449
+ // otherwise came out a required prop the page had to pass (NODII-DEV-CLI-257). The bare
1450
+ // one keeps its name: optionalMark gives it the scope scopeIdentifiers would.
1451
+ const hintProp = () => (lifted.push("maskHint"), optionalMark(ctx, scope, "maskHint"));
1452
+ const bareHint = /(^|\s)maskHint=\{maskHint\}/.exec(attrs);
1453
+ let next = hint
1454
+ ? attrs.replace(hint[0], `maskHint={${hintProp()}}`)
1455
+ : bareHint
1456
+ ? attrs.replace(bareHint[0], `${bareHint[1]}maskHint={${optionalMark(ctx, scope, "maskHint")}}`)
1457
+ : attrs;
1437
1458
  if (ctx.factValue) {
1438
1459
  for (const prop of FACT_PII_PROPS) {
1439
1460
  if (new RegExp(String.raw`\b${prop}=`).test(next)) continue;
@@ -1442,6 +1463,15 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
1442
1463
  const after = topLevelAttr(next, prop === "disposition" ? "maskHint" : "relation") ?? topLevelAttr(next, "relation");
1443
1464
  next = after ? `${next.slice(0, after.to)}${attr}${next.slice(after.to)}` : next.replace(/(\s*\/?\s*)$/, `${attr}$1`);
1444
1465
  }
1466
+ } else if (!/(?:^|\s)maskHint=/.test(maskStrings(next)) && !LITERAL_FORCE_VISIBLE.test(maskStrings(next))) {
1467
+ // Every PiiText passes the server's hint, wherever it sits (NODII-DEV-CLI-257): a template
1468
+ // drawn without one (a Code Connect from before DESIGN-SYSTEM-799) still generates a page that
1469
+ // takes the served `maskHint`, optional because the server may send none. Only the viewer's
1470
+ // own value on a self-scoped surface, a literal `forceVisible`, never masks and needs none.
1471
+ lifted.push("maskHint");
1472
+ const attr = ` maskHint={${optionalMark(ctx, scope, "maskHint")}}`;
1473
+ const after = topLevelAttr(next, "relation");
1474
+ next = after ? `${next.slice(0, after.to)}${attr}${next.slice(after.to)}` : next.replace(/(\s*\/?\s*)$/, `${attr}$1`);
1445
1475
  }
1446
1476
  return next;
1447
1477
  });
@@ -2018,7 +2048,43 @@ function controlDisabled(attrs, scope, ctx) {
2018
2048
  * page's too, in every view. Two fields of one label in one view are told
2019
2049
  * apart by their place (resolveScopes) (hub-481).
2020
2050
  */
2051
+ /**
2052
+ * The DS pickers that are no native form control (a Popover trigger, a chip input): a Field
2053
+ * wires an id onto them at runtime, but the label's `htmlFor` is only the picker's name in the
2054
+ * source when the picker declares that id itself, which the console's label fence reads
2055
+ * (hub-692). InputChips takes `id` from DESIGN-SYSTEM-1132.
2056
+ */
2057
+ const FIELD_PICKERS = "MultiSelect|MultiCombobox|Combobox|InputChips|TimePicker";
2058
+
2059
+ /**
2060
+ * A Field's label names the picker it holds: the first picker inside a `<Field htmlFor={x}>`
2061
+ * that has no id of its own takes id={x}, so the label points at a control that owns that id
2062
+ * (hub-692). A picker that already has an id keeps it, and only one picker per Field
2063
+ * takes the Field's id, so no id repeats.
2064
+ */
2065
+ export function idFieldPickers(code) {
2066
+ let out = "";
2067
+ let last = 0;
2068
+ for (const m of code.matchAll(/<Field(?=[\s>])/g)) {
2069
+ if (m.index < last) continue;
2070
+ const end = m.index + openTagEnd(code.slice(m.index));
2071
+ const target = /(?:^|\s)htmlFor=\{([A-Za-z_$][\w$]*)\}/.exec(code.slice(m.index, end + 1))?.[1];
2072
+ const close = code.indexOf("</Field>", end);
2073
+ if (!target || close < 0) continue;
2074
+ const body = code.slice(end + 1, close);
2075
+ const picker = new RegExp(`<(?:${FIELD_PICKERS})(?=[\\s/>])`).exec(body);
2076
+ if (!picker) continue;
2077
+ const open = body.slice(picker.index, picker.index + openTagEnd(body.slice(picker.index)) + 1);
2078
+ if (/(?:^|\s)id=/.test(open)) continue;
2079
+ const at = end + 1 + picker.index + picker[0].length;
2080
+ out += `${code.slice(last, at)} id={${target}}`;
2081
+ last = at;
2082
+ }
2083
+ return out + code.slice(last);
2084
+ }
2085
+
2021
2086
  function liftFieldControls(code, node, ctx, lift, scope) {
2087
+ code = idFieldPickers(code);
2022
2088
  const top = /^<([A-Za-z]+)/.exec(code.replace(/^<Field\b[^>]*>\s*/, ""))?.[1];
2023
2089
  code = rewriteTags(code, Object.keys(NAMED_CHANGE).join("|"), (attrs, tag) => {
2024
2090
  const { change: handler, value: valueAttr, word, byField, withWord } = NAMED_CHANGE[tag];
@@ -2593,6 +2659,70 @@ function skeletonFacts(views, imports, factTexts) {
2593
2659
  if (drawn) imports.push(`import { Skeleton } from "${module}";`);
2594
2660
  }
2595
2661
 
2662
+ /**
2663
+ * A person's name the page could not resolve says so in words (hub-692). PiiText
2664
+ * reads `null` as "the server withheld it" and draws the Restricted bar; a third party whose
2665
+ * record the viewer cannot read, or that no longer exists, is not withheld, and drawing the
2666
+ * bar (or nothing) there hides that the name is simply not available. So every name-kind
2667
+ * PiiText that reads the page's data also takes an optional unresolved flag, and when the
2668
+ * page sets it the slot draws the DS PersonName's `unresolved` state, the approved
2669
+ * "Name not available" (person-name.guidelines.ts; Figma 2433:16973):
2670
+ * - a scalar slot `raisedByValue` takes `raisedByUnresolved?: boolean`;
2671
+ * - a lifted row's person field takes `unresolved?: boolean` beside its served pair.
2672
+ * The flag is the page's to set from its own identity resolution; omitted, the slot is
2673
+ * PiiText exactly as before, so nothing here can reveal or mask a value (P-10; U05).
2674
+ * Only a name slot takes it: an address or a phone has no "Name not available".
2675
+ * Run last, after the props are typed and the facts' skeletons are drawn.
2676
+ */
2677
+ const UNRESOLVED_NAME = '<PersonName value={null} state="unresolved" />';
2678
+ const NAME_PII = /<PiiText value=\{(?:([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\.value\} kind=\{\1\.\2\.(?:kind|piiKind) \?\? "name"\}|([a-z][A-Za-z0-9]*)\} kind="name")/g;
2679
+ function unresolvedNames(views, data, imports) {
2680
+ const module = imports
2681
+ .map((s) => /^import\s+\{([^}]*)\}\s+from\s+["']([^"']+)["']/.exec(s.trim()))
2682
+ .find((m) => m && !/^(?:\.|@\/)/.test(m[2]) && /\bPiiText\b/.test(m[1]))?.[2];
2683
+ if (!module) return;
2684
+ let drawn = false;
2685
+ for (const view of views) {
2686
+ const body = view.body;
2687
+ const openers = listOpeners(body);
2688
+ const edits = [];
2689
+ for (const m of body.matchAll(NAME_PII)) {
2690
+ const [, param, key, read] = m;
2691
+ const end = m.index + openTagEnd(body.slice(m.index)) + 1;
2692
+ if (body[end - 2] !== "/") continue;
2693
+ let flag;
2694
+ if (param) {
2695
+ const list = listAt(openers, m.index, param);
2696
+ const field = list && data.get(list)?.members.get(key)?.get("\u0000pii");
2697
+ if (!field) continue;
2698
+ field.raw = field.raw.replace(PII_ROW_FIELD, piiRowField("kind", true)).replace(piiRowField(PII_UNION_KIND), piiRowField(PII_UNION_KIND, true));
2699
+ flag = `${param}.${key}.unresolved`;
2700
+ } else {
2701
+ if (JS_LITERALS.has(read)) continue;
2702
+ const base = read.replace(/Value$/, "") || read;
2703
+ flag = `${base}Unresolved`;
2704
+ const d = data.get(flag);
2705
+ if (d && d.raw !== "boolean") continue;
2706
+ if (!d) data.set(flag, { attrs: new Map(), child: false, nested: false, members: new Map(), list: false, raw: "boolean", optional: true });
2707
+ view.uses.add(flag);
2708
+ }
2709
+ // A JSX child takes braces; inside an expression (`value={…}`, `loading ? … : …`) parentheses.
2710
+ // Already alone in parentheses (`: (<PiiText … />)`), it takes none of its own.
2711
+ const before = body.slice(Math.max(0, m.index - 200), m.index);
2712
+ const child = /[>}]\s*$/.test(before);
2713
+ const wrapped = /\(\s*$/.test(before) && /^\s*\)/.test(body.slice(end));
2714
+ const ternary = `${flag} ? ${UNRESOLVED_NAME} : ${body.slice(m.index, end)}`;
2715
+ edits.push({ from: m.index, to: end, text: child ? `{${ternary}}` : wrapped ? ternary : `(${ternary})` });
2716
+ }
2717
+ if (!edits.length) continue;
2718
+ let next = body;
2719
+ for (const e of edits.reverse()) next = next.slice(0, e.from) + e.text + next.slice(e.to);
2720
+ view.body = next;
2721
+ drawn = true;
2722
+ }
2723
+ if (drawn) imports.push(`import { PersonName } from "${module}";`);
2724
+ }
2725
+
2596
2726
  /** The type the generated file declares for drawnProps (see there). */
2597
2727
  const DRAWN_TYPE = [
2598
2728
  "/** A DS component's props, narrowed to the member of their union this call draws: every required prop passed, every literal one fitting. */",
@@ -3497,8 +3627,28 @@ function tabStrip(run, ctx) {
3497
3627
  * PiiText's is offered, so a row can never force a value visible (U05; cli-140).
3498
3628
  */
3499
3629
  const PII_KINDS = new Set(["name", "email", "phone", "address", "dob", "document", "text"]);
3500
- const piiRowField = (kindField) =>
3501
- `{ ${[`${kindField}?`, "maskHint?", "model", "relation", "value"].map((k) => `${k}: ComponentProps<typeof PiiText>[${JSON.stringify(k === `${kindField}?` ? "kind" : k.replace("?", ""))}]`).join("; ")} }`;
3630
+ const piiRowField = (kindField, unresolved = false) =>
3631
+ `{ ${[`${kindField}?`, "maskHint?", "model", "relation", ...(unresolved ? ["unresolved?"] : []), "value"].map((k) => k === "unresolved?" ? `${k}: boolean` : `${k}: ComponentProps<typeof PiiText>[${JSON.stringify(k === `${kindField}?` ? "kind" : k.replace("?", ""))}]`).join("; ")} }`;
3632
+
3633
+ /**
3634
+ * The PiiText kind a field's own name states (hub-692): an `email`, `workEmail` or
3635
+ * `emailAddress` field is an address and a `phone` or `mobileNumber` field is a phone, whatever
3636
+ * sample Figma drew in it. Figma's HR · Users table draws its Email column with a name-kind
3637
+ * PiiText (`A··· K···`), and generating that as `kind="name"` asserted an address was a person's
3638
+ * name: it masked and announced it as one, which the console's no-address-as-name scan refuses.
3639
+ * Only a drawn `name` or `text` kind gives way; any other kind Figma states is kept.
3640
+ */
3641
+ function fieldPiiKind(field, drawn) {
3642
+ if (drawn !== "name" && drawn !== "text") return drawn;
3643
+ // Only a field NAMED for the address re-kinds (its head noun: `email`, `workEmail`,
3644
+ // `mobileNumber`, `phone`), never one that merely mentions it (`phoneVerifiedBy`,
3645
+ // `emailSentBy` are people's names).
3646
+ const words = String(field ?? "").replace(/([a-z0-9])([A-Z])/g, "$1 $2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
3647
+ const head = words.at(-1) === "number" || words.at(-1) === "address" ? words.at(-2) : words.at(-1);
3648
+ if (head === "email" || head === "mail") return "email";
3649
+ if (head === "phone" || head === "mobile" || head === "msisdn") return "phone";
3650
+ return drawn;
3651
+ }
3502
3652
  const PII_ROW_FIELD = piiRowField("kind");
3503
3653
  /**
3504
3654
  * In a person-or-text union `kind` is the discriminant, so the person's PiiText kind is
@@ -3672,7 +3822,8 @@ function piiTreeKind(cell) {
3672
3822
  /** That cell's PiiText, reading the served pair at `ref` (`row.employee`), with the kind the tree states for it. */
3673
3823
  function piiCellText({ cell, code }, ref, kindField = "kind") {
3674
3824
  const { attrs = "", before = "", after = "" } = piiCellParts({ code }) ?? {};
3675
- const kind = piiTreeKind(cell);
3825
+ // A column whose field names an address or a phone draws that kind (hub-692).
3826
+ const kind = fieldPiiKind(ref.split(".").pop(), piiTreeKind(cell));
3676
3827
  const size = /\ssize="\w+"/.exec(attrs)?.[0] ?? "";
3677
3828
  // Repeated people are a bulk disclosure surface even inside a record page or
3678
3829
  // a permissive ambient provider. Keep the served self relation unchanged.
package/dist/watchdog.js CHANGED
@@ -10,6 +10,7 @@ import { appendInbox, inboxDir, roleWaitDeliveries, stewardRole } from "./lane-m
10
10
  import { laneSwitchOn } from "./lane-switches.js";
11
11
  import { managedEntry, readNeedsRoot } from "./managed-version.js";
12
12
  import { envAssignment, execLine, installNote, installSupervised, lingerLine, logsDir, supervisedDirs, unitActive, unitPath, unitState, unitText } from "./systemd.js";
13
+ import { pushHookState } from "./push-hooks.js";
13
14
 
14
15
  const execFile = promisify(execFileCallback);
15
16
  export const WATCHDOG_LABEL = "com.nodii.watchdog";
@@ -146,6 +147,7 @@ export async function collectWatchdogFacts(records, {
146
147
  isPidAlive = isProcessAlive,
147
148
  listStaleSockets = () => findStaleSockets({ isPidAlive }),
148
149
  inspect = inspectWorktree,
150
+ readPushState = pushHookState,
149
151
  now = () => new Date(),
150
152
  errors = [],
151
153
  } = {}) {
@@ -163,7 +165,11 @@ export async function collectWatchdogFacts(records, {
163
165
  for (const worktree of new Set(records.map((record) => record.worktree).filter(Boolean))) {
164
166
  try {
165
167
  const result = await inspect(worktree);
166
- if (result.aheadCount > 0 || result.error === "remote_branch_missing") unpushedWorktrees.push(result);
168
+ if (result.aheadCount > 0 || result.error === "remote_branch_missing") {
169
+ // The push hook's own state (O22): "push blocked: secret", "diverged: ...", "ahead of remote: ...".
170
+ const pushHook = await readPushState(result.worktree, result.branch).catch(() => null);
171
+ unpushedWorktrees.push(pushHook ? { ...result, pushHook } : result);
172
+ }
167
173
  } catch (error) {
168
174
  errors.push({ kind: "worktree", worktree, code: error?.code ?? "GIT_INSPECTION_FAILED" });
169
175
  }
@@ -313,9 +319,10 @@ export async function sweepWatchdog({
313
319
  if (!record) continue;
314
320
  const remote = worktree.remoteBranch ?? "its missing remote branch";
315
321
  const commits = worktree.commits.slice(0, 20).join(",");
316
- const detail = worktree.error === "remote_branch_missing"
322
+ const detail = (worktree.error === "remote_branch_missing"
317
323
  ? `${worktree.branch} has no remote branch.`
318
- : `${worktree.branch} is ${worktree.aheadCount} commit(s) ahead of ${remote}${commits ? `: ${commits}` : ""}`;
324
+ : `${worktree.branch} is ${worktree.aheadCount} commit(s) ahead of ${remote}${commits ? `: ${commits}` : ""}`)
325
+ + (worktree.pushHook ? `; push hook: ${worktree.pushHook.state}${worktree.pushHook.at ? ` (at ${worktree.pushHook.at})` : ""}` : "");
319
326
  try {
320
327
  await request("POST", `/api/v1/runs/${encode(record.runId)}/watchdog`, observationBody({
321
328
  observation: "worktree_unpushed", machineId: effectiveMachineId, observedAt: now().toISOString(), detail,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.215",
3
+ "version": "0.6.216",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {