@nodii/dev 0.6.215 → 0.6.217
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 +99 -3
- package/dist/cli.js +12 -6
- package/dist/core.js +1 -1
- package/dist/drill.js +18 -5
- package/dist/harness.js +35 -2
- package/dist/heavy-slot.sh +115 -14
- package/dist/heavy.js +13 -5
- package/dist/machine-floor.js +10 -6
- package/dist/nodii-dev.js +5 -1
- package/dist/push-hook.sh +280 -0
- package/dist/push-hooks.js +86 -0
- package/dist/surface.js +157 -6
- package/dist/watchdog.js +10 -3
- package/package.json +1 -1
|
@@ -0,0 +1,280 @@
|
|
|
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
|
+
# Rule basis (interim, recorded): DEV-PROCESS-13 / Objective O22 and the operator's words of 25 Nov 2026
|
|
5
|
+
# (inputs.md §34, relayed by coordinator bb): "Lanes push after every commit, so nothing lives only on this
|
|
6
|
+
# Mac". No MW clause states it yet; the planner (steward-dev-process) ruled on 26 Nov that this citation is
|
|
7
|
+
# the basis until the MW clause it is drafting is uploaded. The shape follows the planner's done-check
|
|
8
|
+
# decisions on that page: a git hook installed by harness install, rewrites, 24 h retry, hooks path and
|
|
9
|
+
# chaining, PR whenever none, secret scan before push. One push worker per branch, a short debounce, and the
|
|
10
|
+
# PR opened outside the push lock follow the reviews of #539 and #542.
|
|
11
|
+
# Installed as both post-commit and post-rewrite where `git rev-parse --git-path hooks` points.
|
|
12
|
+
#
|
|
13
|
+
# After every commit or rewrite it returns at once and, in the background:
|
|
14
|
+
# - pushes the CURRENT branch only (its tip, refs/heads/<br>), never main or master, never with force;
|
|
15
|
+
# a detached HEAD is not pushed and an INFO line is logged;
|
|
16
|
+
# - before any push, scans the commits not yet on any origin ref with `gitleaks git --redact`. A finding,
|
|
17
|
+
# or gitleaks missing or failing, means NO push ("push blocked: secret" / "secret scan unavailable");
|
|
18
|
+
# the commit has already succeeded and no secret's value is ever printed;
|
|
19
|
+
# - a non-fast-forward rejection: if origin already holds the commit it is "superseded"; otherwise the
|
|
20
|
+
# branch has diverged (amend or rebase after a push) and it logs
|
|
21
|
+
# "diverged: needs push --force-with-lease by a person";
|
|
22
|
+
# - a refusal by the repository's own pre-push hook is logged and not retried (push it by hand);
|
|
23
|
+
# - any other failure (origin unreachable) is retried with backoff (20 s doubling, capped at 300 s)
|
|
24
|
+
# until it lands, for up to 24 h;
|
|
25
|
+
# - a burst of commits is debounced (2 s quiet), so it costs at most two scans and pushes;
|
|
26
|
+
# - after a push lands and the push lock is released, opens a draft PR against main when the branch has
|
|
27
|
+
# none, retried the same way under its own lock, so a failing PR create never delays a later push.
|
|
28
|
+
# The GitHub API base is GITHUB_API_URL (default https://api.github.com). Token: GH_TOKEN, GITHUB_TOKEN,
|
|
29
|
+
# else `gh auth token`; on api.github.com, PR reads use `nodii-dev github research-token` when it works.
|
|
30
|
+
# Log: <git-common-dir>/nodii-push.log. Last state per branch: <git-common-dir>/nodii-push/<branch>.state,
|
|
31
|
+
# which `nodii-dev watchdog sweep` adds to the lane run's unpushed-worktree report.
|
|
32
|
+
set -u
|
|
33
|
+
HOOK=$(basename "$0")
|
|
34
|
+
CHAINED="$0.nodii-chained"
|
|
35
|
+
input=""
|
|
36
|
+
[ "$HOOK" = post-rewrite ] && input=$(cat)
|
|
37
|
+
# A hook that was here before nodii-dev keeps running first, with the same arguments and input.
|
|
38
|
+
if [ -x "$CHAINED" ]; then
|
|
39
|
+
if [ "$HOOK" = post-rewrite ]; then printf '%s\n' "$input" | "$CHAINED" "$@"; else "$CHAINED" "$@"; fi
|
|
40
|
+
fi
|
|
41
|
+
|
|
42
|
+
GCD=$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null) || exit 0
|
|
43
|
+
LOG=$GCD/nodii-push.log
|
|
44
|
+
now() { date +%s; }
|
|
45
|
+
if ! br=$(git symbolic-ref --quiet --short HEAD); then
|
|
46
|
+
printf '%s - INFO detached commit %s not pushed (hook %s)\n' "$(now)" "$(git rev-parse HEAD 2>/dev/null)" "$HOOK" >> "$LOG"
|
|
47
|
+
exit 0
|
|
48
|
+
fi
|
|
49
|
+
case $br in main|master) exit 0 ;; esac
|
|
50
|
+
git remote get-url origin >/dev/null 2>&1 || exit 0
|
|
51
|
+
|
|
52
|
+
RETRY_S=20 RETRY_MAX_S=300 WINDOW_S=86400
|
|
53
|
+
API=${GITHUB_API_URL:-https://api.github.com}; API=${API%/}
|
|
54
|
+
STATE_DIR=$GCD/nodii-push
|
|
55
|
+
STATE_FILE=$STATE_DIR/$(printf '%s' "$br" | tr '/' '~').state
|
|
56
|
+
url=$(git config --get remote.origin.url || true)
|
|
57
|
+
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#/$##')
|
|
58
|
+
log() { printf '%s %s %s\n' "$(now)" "$br" "$*" >> "$LOG"; }
|
|
59
|
+
state() { mkdir -p "$STATE_DIR" 2>/dev/null && printf '%s %s\n' "$(now)" "$*" > "$STATE_FILE"; }
|
|
60
|
+
# The PR number goes on the state only while it still says "pushed": the PR step runs outside the push
|
|
61
|
+
# lock, so a later worker's "ahead of remote" or "push blocked" must not be overwritten.
|
|
62
|
+
pr_state() {
|
|
63
|
+
local cur; cur=$(cut -d' ' -f2- "$STATE_FILE" 2>/dev/null)
|
|
64
|
+
case $cur in pushed*) state "${cur%% pr #*} pr #$1" ;; esac
|
|
65
|
+
}
|
|
66
|
+
token=""
|
|
67
|
+
write_token() {
|
|
68
|
+
[ -n "$token" ] && return 0
|
|
69
|
+
token=${GH_TOKEN:-${GITHUB_TOKEN:-}}
|
|
70
|
+
[ -z "$token" ] && command -v gh >/dev/null 2>&1 && token=$(gh auth token 2>/dev/null)
|
|
71
|
+
[ -n "$token" ]
|
|
72
|
+
}
|
|
73
|
+
read_token=""
|
|
74
|
+
get_read_token() { # O24: bulk-safe reads on the research App, only against the real GitHub
|
|
75
|
+
[ -n "$read_token" ] && return 0
|
|
76
|
+
if [ "$API" = https://api.github.com ] && command -v nodii-dev >/dev/null 2>&1; then
|
|
77
|
+
read_token=$(nodii-dev github research-token 2>/dev/null) || read_token=""
|
|
78
|
+
fi
|
|
79
|
+
[ -n "$read_token" ] || { write_token && read_token=$token; }
|
|
80
|
+
[ -n "$read_token" ]
|
|
81
|
+
}
|
|
82
|
+
api() { local t=$1; shift; curl -s --max-time 20 -H "Authorization: Bearer $t" -H 'Accept: application/vnd.github+json' "$@"; }
|
|
83
|
+
json_str() { node -e 'process.stdout.write(JSON.stringify(process.argv[1]))' "$1"; }
|
|
84
|
+
|
|
85
|
+
base_branch() {
|
|
86
|
+
local b; b=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null); b=${b#origin/}
|
|
87
|
+
case $b in ''|"$br") echo main ;; *) echo "$b" ;; esac
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
pr_list() { # prints the open PR numbers for the branch ("1,2"), "none", or "error"
|
|
91
|
+
local owner=${owner_repo%%/*}
|
|
92
|
+
get_read_token || { echo error; return; }
|
|
93
|
+
api "$read_token" "$API/repos/$owner_repo/pulls?state=open&head=$owner:$br" |
|
|
94
|
+
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")}})'
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
pr_title() { # the branch's first commit subject past the base: a display name, never the branch or lane key
|
|
98
|
+
local t; t=$(git log --reverse --format=%s "refs/remotes/origin/$1..refs/heads/$br" 2>/dev/null | head -n 1)
|
|
99
|
+
[ -n "$t" ] || t=$(git log -1 --format=%s "refs/heads/$br" 2>/dev/null)
|
|
100
|
+
printf '%s' "${t:-Work in progress}"
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
open_pr_once() { # 0 = a PR is open for the branch now; 1 = try again
|
|
104
|
+
local nums code base body
|
|
105
|
+
nums=$(pr_list)
|
|
106
|
+
[ "$nums" = error ] && { log "pr-list failed"; read_token=""; return 1; }
|
|
107
|
+
[ "$nums" = none ] || { log "pr-exists #$nums"; pr_state "$nums"; return 0; }
|
|
108
|
+
write_token || { log "pr-create failed: no GitHub token (GH_TOKEN, GITHUB_TOKEN or gh auth)"; return 1; }
|
|
109
|
+
base=$(base_branch)
|
|
110
|
+
body="Opened by the nodii-dev push hook (O22): this lane's branch is pushed after every commit."
|
|
111
|
+
for draft in true false; do
|
|
112
|
+
code=$(api "$token" -o "$STATE_DIR/pr-create.json" -w '%{http_code}' -X POST -H 'content-type: application/json' \
|
|
113
|
+
-d "{\"title\":$(json_str "$(pr_title "$base")"),\"head\":$(json_str "$br"),\"base\":$(json_str "$base"),\"body\":$(json_str "$body"),\"draft\":$draft}" \
|
|
114
|
+
"$API/repos/$owner_repo/pulls")
|
|
115
|
+
log "pr-create base=$base draft=$draft http=$code"
|
|
116
|
+
# A repository without draft PRs refuses draft:true with 422; try once as a ready PR.
|
|
117
|
+
[ "$code" = 422 ] && [ "$draft" = true ] && grep -qi 'draft' "$STATE_DIR/pr-create.json" 2>/dev/null && continue
|
|
118
|
+
break
|
|
119
|
+
done
|
|
120
|
+
rm -f "$STATE_DIR/pr-create.json"
|
|
121
|
+
# Read the result back in its own call (K03-16): the list, not the create's answer, says a PR exists.
|
|
122
|
+
if [ "$code" = 201 ]; then
|
|
123
|
+
nums=$(pr_list)
|
|
124
|
+
case $nums in none|error) log "pr-create read-back: list says $nums" ;; *) log "pr-exists #$nums (read back)"; pr_state "$nums"; return 0 ;; esac
|
|
125
|
+
fi
|
|
126
|
+
return 1 # not created or not read back: the next list decides (a racing worker may have made it: 422)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
open_pr() {
|
|
130
|
+
[ -n "$owner_repo" ] || { log "pr-skip: origin is not a github.com repository"; return 0; }
|
|
131
|
+
local wait=$RETRY_S start; start=$(now)
|
|
132
|
+
until open_pr_once; do
|
|
133
|
+
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
|
|
134
|
+
log "pr-retry in ${wait}s"; beat; sleep "$wait"; wait=$((wait * 2)); [ "$wait" -gt "$RETRY_MAX_S" ] && wait=$RETRY_MAX_S
|
|
135
|
+
done
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
scan() { # 0 clean; 1 secret found; 2 scan unavailable (fail-closed). Values are never printed.
|
|
139
|
+
local sha=$1 rep rc top
|
|
140
|
+
if ! command -v gitleaks >/dev/null 2>&1; then
|
|
141
|
+
log "secret scan unavailable: gitleaks not installed; $sha not pushed (push blocked: secret scan unavailable)"
|
|
142
|
+
state "push blocked: secret scan unavailable (gitleaks not installed)"; return 2
|
|
143
|
+
fi
|
|
144
|
+
top=$(git rev-parse --show-toplevel); rep=$(mktemp "${TMPDIR:-/tmp}/nodii-push-gitleaks.XXXXXX")
|
|
145
|
+
gitleaks git --no-banner --redact --log-opts="$sha --not --remotes=origin" --report-format json \
|
|
146
|
+
--report-path "$rep" --exit-code 1 "$top" >/dev/null 2>&1; rc=$?
|
|
147
|
+
case $rc in
|
|
148
|
+
0) rm -f "$rep"; return 0 ;;
|
|
149
|
+
1) node -e 'for (const f of JSON.parse(require("fs").readFileSync(process.argv[1],"utf8")))
|
|
150
|
+
console.log(`${f.RuleID} ${f.File} ${String(f.Commit).slice(0,8)}`)' "$rep" 2>/dev/null |
|
|
151
|
+
while read -r rule file short; do log "secret found: $rule $file (commit $short)"; done
|
|
152
|
+
rm -f "$rep"; log "push blocked: secret; $sha not pushed"
|
|
153
|
+
state "push blocked: secret (see $LOG)"; return 1 ;;
|
|
154
|
+
*) rm -f "$rep"; log "secret scan unavailable: gitleaks exit $rc; $sha not pushed (push blocked: secret scan unavailable)"
|
|
155
|
+
state "push blocked: secret scan unavailable (gitleaks exit $rc)"; return 2 ;;
|
|
156
|
+
esac
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
# One line of git's error text, with any credentials in a URL removed (S13-6), for the log.
|
|
160
|
+
errline() { printf '%s' "$1" | tr '\n' ' ' | sed -E 's#(://)[^/@ ]+@#\1***@#g' | cut -c1-300; }
|
|
161
|
+
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'; }
|
|
162
|
+
|
|
163
|
+
work() {
|
|
164
|
+
local i=0 err wait=$RETRY_S start sha rt pp
|
|
165
|
+
start=$(now)
|
|
166
|
+
mkdir -p "$STATE_DIR"
|
|
167
|
+
while :; do
|
|
168
|
+
i=$((i + 1))
|
|
169
|
+
# Push the branch's tip as it is now, so a burst of commits lands as one push.
|
|
170
|
+
sha=$(git rev-parse --verify --quiet "refs/heads/$br") || { log "branch $br is gone; nothing pushed"; return 0; }
|
|
171
|
+
scan "$sha" || return 0
|
|
172
|
+
if err=$(git push --quiet origin "$sha:refs/heads/$br" 2>&1); then
|
|
173
|
+
# Read the remote branch back in its own call (K03-16): it must hold this commit.
|
|
174
|
+
rt=$(git ls-remote origin "refs/heads/$br" 2>/dev/null | cut -f1)
|
|
175
|
+
if [ "$rt" = "$sha" ] || { [ -n "$rt" ] && git merge-base --is-ancestor "$sha" "$rt" 2>/dev/null; }; then
|
|
176
|
+
log "pushed $sha attempt=$i (origin at $rt)"; state "pushed $sha"
|
|
177
|
+
PR_NEEDED=1; return 0
|
|
178
|
+
fi
|
|
179
|
+
err="push read-back: origin at ${rt:-nothing}, not $sha (connection)"
|
|
180
|
+
fi
|
|
181
|
+
if printf '%s' "$err" | grep -qE 'non-fast-forward|fetch first|\[rejected\]|stale info'; then
|
|
182
|
+
rt=$(git ls-remote origin "refs/heads/$br" 2>/dev/null | cut -f1)
|
|
183
|
+
if [ -n "$rt" ] && git merge-base --is-ancestor "$sha" "$rt" 2>/dev/null; then log "superseded $sha (origin at $rt)"; return 0; fi
|
|
184
|
+
if [ -n "$rt" ] && git merge-base --is-ancestor "$rt" "$sha" 2>/dev/null; then : # origin moved under us; push again
|
|
185
|
+
else
|
|
186
|
+
log "diverged: needs push --force-with-lease by a person; $sha not pushed (origin at ${rt:-none})"
|
|
187
|
+
state "diverged: needs push --force-with-lease by a person (origin at ${rt:-none}, local $sha)"; return 0
|
|
188
|
+
fi
|
|
189
|
+
elif ! transport_error "$err"; then
|
|
190
|
+
pp=$(git rev-parse --git-path hooks/pre-push)
|
|
191
|
+
if [ -x "$pp" ]; then
|
|
192
|
+
log "push refused (pre-push hook or remote): $sha not pushed; push it by hand: $(errline "$err")"
|
|
193
|
+
state "ahead of remote: push refused, push it by hand"; return 0
|
|
194
|
+
fi
|
|
195
|
+
fi
|
|
196
|
+
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
|
|
197
|
+
log "push-failed $sha attempt=$i, retry in ${wait}s: $(errline "$err")"
|
|
198
|
+
state "ahead of remote: push failing since $start, retrying"
|
|
199
|
+
beat; sleep "$wait"; wait=$((wait * 2)); [ "$wait" -gt "$RETRY_MAX_S" ] && wait=$RETRY_MAX_S
|
|
200
|
+
done
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
# One push worker per branch, holding <branch>.lock while it scans and pushes. A commit marks the branch
|
|
204
|
+
# dirty; the worker waits until no commit has marked it for DEBOUNCE_S, pushes the tip, and pushes again
|
|
205
|
+
# only if a commit marked it meanwhile, so a burst costs at most two scans and pushes. The PR is opened
|
|
206
|
+
# AFTER the push lock is released, under its own <branch>.pr lock, so a PR create that keeps failing
|
|
207
|
+
# (no token, GitHub down) never holds up the next commit's push.
|
|
208
|
+
DEBOUNCE_S=2
|
|
209
|
+
SLUG=$(printf '%s' "$br" | tr '/' '~')
|
|
210
|
+
LOCK=$STATE_DIR/$SLUG.lock PRLOCK=$STATE_DIR/$SLUG.pr DIRTY=$STATE_DIR/$SLUG.dirty
|
|
211
|
+
PR_NEEDED=0 HELD=""
|
|
212
|
+
# The worker touches the lock it holds before every wait (the longest is RETRY_MAX_S), so a lock
|
|
213
|
+
# untouched for LOCK_STALE_MIN minutes belongs to no worker, even if its pid has been reused.
|
|
214
|
+
LOCK_STALE_MIN=8
|
|
215
|
+
beat() { [ -n "$HELD" ] && touch "$HELD" 2>/dev/null; return 0; }
|
|
216
|
+
# A lock directory holds its worker's pid and, where ps may run, that process's start time. It is live
|
|
217
|
+
# while it was touched within LOCK_STALE_MIN minutes AND its pid runs (kill -0; "not permitted" counts
|
|
218
|
+
# as running) AND, when both start times can be read, the process is the one that took it. Before the
|
|
219
|
+
# pid is written it is live for its first minute. ps is optional: a sandbox may refuse to run it.
|
|
220
|
+
lock_live() {
|
|
221
|
+
local pid started cur err
|
|
222
|
+
[ -z "$(find "$1" -maxdepth 0 -mmin +"$LOCK_STALE_MIN" 2>/dev/null)" ] || return 1
|
|
223
|
+
pid=$(cat "$1/pid" 2>/dev/null)
|
|
224
|
+
if [ -z "$pid" ]; then [ -z "$(find "$1" -maxdepth 0 -mmin +1 2>/dev/null)" ]; return; fi
|
|
225
|
+
if ! err=$(LC_ALL=C kill -0 "$pid" 2>&1); then
|
|
226
|
+
case $err in *"not permitted"*) ;; *) return 1 ;; esac
|
|
227
|
+
fi
|
|
228
|
+
started=$(cat "$1/started" 2>/dev/null)
|
|
229
|
+
cur=$(ps -o lstart= -p "$pid" 2>/dev/null) || cur=""
|
|
230
|
+
[ -z "$started" ] || [ -z "$cur" ] || [ "$started" = "$cur" ]
|
|
231
|
+
}
|
|
232
|
+
own() { echo "$2" > "$1/pid"; ps -o lstart= -p "$2" > "$1/started" 2>/dev/null; }
|
|
233
|
+
take_lock() {
|
|
234
|
+
local l=$1 stale="$1.stale.$$"
|
|
235
|
+
mkdir "$l" 2>/dev/null && return 0
|
|
236
|
+
lock_live "$l" && return 1
|
|
237
|
+
# Take a stale lock over by renaming it away: only one hook's rename succeeds. If what it moved
|
|
238
|
+
# turns out to be live (another hook took the lock over first), it goes back.
|
|
239
|
+
mv "$l" "$stale" 2>/dev/null || return 1
|
|
240
|
+
if lock_live "$stale"; then mv "$stale" "$l" 2>/dev/null || rm -rf "$stale"; return 1; fi
|
|
241
|
+
rm -rf "$stale"
|
|
242
|
+
mkdir "$l" 2>/dev/null
|
|
243
|
+
}
|
|
244
|
+
settle() { # until DIRTY has not grown for DEBOUNCE_S, at most 30 s
|
|
245
|
+
local a b t0; t0=$(now); a=$({ wc -c < "$DIRTY"; } 2>/dev/null)
|
|
246
|
+
while :; do
|
|
247
|
+
beat; sleep "$DEBOUNCE_S"; b=$({ wc -c < "$DIRTY"; } 2>/dev/null)
|
|
248
|
+
[ "$a" = "$b" ] && return 0
|
|
249
|
+
a=$b; [ $(( $(now) - t0 )) -ge 30 ] && return 0
|
|
250
|
+
done
|
|
251
|
+
}
|
|
252
|
+
worker() {
|
|
253
|
+
local me="" n=0
|
|
254
|
+
# The hook writes this worker's pid ($!) into the lock; bash 3.2 has no $BASHPID.
|
|
255
|
+
while [ -z "$me" ] && [ "$n" -lt 50 ]; do me=$(cat "$LOCK/pid" 2>/dev/null); n=$((n + 1)); [ -n "$me" ] || sleep 0.1; done
|
|
256
|
+
HELD=$LOCK
|
|
257
|
+
while :; do
|
|
258
|
+
settle
|
|
259
|
+
rm -f "$DIRTY"
|
|
260
|
+
work
|
|
261
|
+
[ -e "$DIRTY" ] && continue
|
|
262
|
+
HELD=""; rm -rf "$LOCK"
|
|
263
|
+
# A commit that marked the branch dirty just before the release still gets pushed.
|
|
264
|
+
if [ -e "$DIRTY" ] && take_lock "$LOCK"; then [ -n "$me" ] && own "$LOCK" "$me"; HELD=$LOCK; continue; fi
|
|
265
|
+
break
|
|
266
|
+
done
|
|
267
|
+
# The PR step: one opener per branch; one that is already retrying covers this push too.
|
|
268
|
+
[ "$PR_NEEDED" = 1 ] || return 0
|
|
269
|
+
take_lock "$PRLOCK" || return 0
|
|
270
|
+
[ -n "$me" ] && own "$PRLOCK" "$me"
|
|
271
|
+
HELD=$PRLOCK
|
|
272
|
+
open_pr
|
|
273
|
+
HELD=""; rm -rf "$PRLOCK"
|
|
274
|
+
}
|
|
275
|
+
mkdir -p "$STATE_DIR" 2>/dev/null
|
|
276
|
+
echo >> "$DIRTY"
|
|
277
|
+
take_lock "$LOCK" || exit 0
|
|
278
|
+
( worker ) </dev/null >>"$LOG" 2>&1 &
|
|
279
|
+
own "$LOCK" $!
|
|
280
|
+
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 =
|
|
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
|
-
|
|
1436
|
-
|
|
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
|
-
|
|
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")
|
|
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,
|