@giamme/forge 0.15.0 → 0.16.0
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/CHANGELOG.md +29 -0
- package/VERSION +1 -1
- package/docs/artifacts.md +1 -1
- package/docs/commands.md +14 -3
- package/docs/forge-ui.md +14 -0
- package/docs/memory.md +22 -0
- package/docs/reviews.md +7 -0
- package/forge +11 -0
- package/package.json +1 -1
- package/references/dataset.md +5 -2
- package/references/decompose.md +51 -5
- package/references/harnesses.md +4 -1
- package/references/solo.md +5 -1
- package/references/ui.md +10 -1
- package/scripts/forge-artifact.sh +53 -0
- package/scripts/forge-contract.py +55 -8
- package/scripts/forge-control.py +0 -2
- package/scripts/forge-dispatch.sh +28 -12
- package/scripts/forge-fail-first.py +3 -1
- package/scripts/forge-guard.py +247 -8
- package/scripts/forge-issues.py +12 -0
- package/scripts/forge-lib-adopt.sh +260 -0
- package/scripts/forge-lib-attribute.sh +10 -2
- package/scripts/forge-lib-plans.sh +16 -4
- package/scripts/forge-lib-review.sh +8 -2
- package/scripts/forge-lib-task.sh +19 -5
- package/scripts/forge-memory.sh +41 -4
- package/scripts/forge-metrics.sh +7 -0
- package/scripts/forge-parallel.sh +96 -13
- package/scripts/forge-route.py +16 -2
- package/scripts/forge-runs-rm.py +23 -7
- package/scripts/forge-runtime.py +25 -2
- package/scripts/forge-schedule.py +5 -2
- package/scripts/forge-shadow.py +2 -0
- package/scripts/forge-solo.sh +6 -0
- package/scripts/forge_dataset/cli.py +16 -0
- package/scripts/forge_dataset/export.py +1 -0
- package/scripts/forge_dataset/harvest.py +11 -0
- package/scripts/forge_dataset/history.py +126 -0
- package/scripts/forge_dataset/worktrees.py +95 -0
- package/scripts/forge_memory_list.py +153 -0
- package/scripts/forge_worktrees.py +88 -0
- package/ui/README.md +31 -0
- package/ui/docs/api.md +81 -4
- package/ui/forge_ui/__init__.py +14 -1
- package/ui/forge_ui/__main__.py +1 -1
- package/ui/forge_ui/control.py +77 -0
- package/ui/forge_ui/findings.py +7 -0
- package/ui/forge_ui/projects.py +571 -0
- package/ui/forge_ui/reader.py +27 -7
- package/ui/forge_ui/static/app.js +99 -21
- package/ui/forge_ui/static/cloudui.js +6 -2
- package/ui/forge_ui/static/convo.js +1 -1
- package/ui/forge_ui/static/diffview.js +2 -2
- package/ui/forge_ui/static/files.js +1 -1
- package/ui/forge_ui/static/index.html +5 -1
- package/ui/forge_ui/static/panel.js +28 -2
- package/ui/forge_ui/static/projectsview.js +372 -0
- package/ui/forge_ui/static/settings.js +136 -4
- package/ui/forge_ui/static/style.css +93 -3
- package/ui/forge_ui/static/uikit.js +94 -1
- package/ui/forge_ui/static/worktreesview.js +250 -0
- package/ui/forge_ui/worktrees.py +570 -0
|
@@ -56,8 +56,9 @@
|
|
|
56
56
|
# 9 the session was not continued (--continue-session only): the harness cannot
|
|
57
57
|
# continue one, or it ran and failed. The caller may dispatch fresh; dispatch
|
|
58
58
|
# never does, so each dispatch keeps its own record. $ROLE.continue says why.
|
|
59
|
-
# A process still alive in the harness's group after it exited
|
|
60
|
-
#
|
|
59
|
+
# A process still alive in the harness's group after it exited, or one the harness started
|
|
60
|
+
# that moved to a session of its own (#129), is killed and listed in $ROLE.orphans (only
|
|
61
|
+
# written when there is something to list). A timeout ends them the same way.
|
|
61
62
|
set -uo pipefail
|
|
62
63
|
|
|
63
64
|
SKILL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
@@ -417,7 +418,7 @@ write_continue() { :; } # redefined below once there is an attempt to archive
|
|
|
417
418
|
ATTEMPT=""
|
|
418
419
|
if [ "$PREFLIGHT" != 1 ] && [ "$DRY" != 1 ]; then
|
|
419
420
|
ATTEMPT="$(python3 "$RUNTIME" begin "$RUN_DIR" "$ROLE")" || exit 3
|
|
420
|
-
rm -f "$RUN_DIR/$ROLE.last" "$RUN_DIR/$ROLE.log" "$RUN_DIR/$ROLE.clock" "$RUN_DIR/$ROLE.resolved" "$RUN_DIR/$ROLE.cmd" "$RUN_DIR/$ROLE.timedout" "$RUN_DIR/$ROLE.settled" "$RUN_DIR/$ROLE.infra" "$RUN_DIR/$ROLE.orphans" "$RUN_DIR/$ROLE.session" "$RUN_DIR/$ROLE.continue" "$RUN_DIR/$ROLE.harness"
|
|
421
|
+
rm -f "$RUN_DIR/$ROLE.last" "$RUN_DIR/$ROLE.log" "$RUN_DIR/$ROLE.clock" "$RUN_DIR/$ROLE.resolved" "$RUN_DIR/$ROLE.cmd" "$RUN_DIR/$ROLE.timedout" "$RUN_DIR/$ROLE.settled" "$RUN_DIR/$ROLE.infra" "$RUN_DIR/$ROLE.orphans" "$RUN_DIR/$ROLE.session" "$RUN_DIR/$ROLE.continue" "$RUN_DIR/$ROLE.harness" "$RUN_DIR/$ROLE.tracked"
|
|
421
422
|
trap 'exit 143' TERM
|
|
422
423
|
trap 'exit 130' INT
|
|
423
424
|
# GUARD_ON is 1 only when the harness was started in its own process group (see the
|
|
@@ -425,17 +426,22 @@ if [ "$PREFLIGHT" != 1 ] && [ "$DRY" != 1 ]; then
|
|
|
425
426
|
# signalled. Every wait here is bounded: this runs on the way out of an interrupted
|
|
426
427
|
# dispatch and must not be the thing that hangs it.
|
|
427
428
|
exit_cleanup() {
|
|
429
|
+
[ -z "${tpid:-}" ] || kill -TERM "$tpid" 2>/dev/null
|
|
428
430
|
if [ -n "${hpid:-}" ] && kill -0 "$hpid" 2>/dev/null; then
|
|
429
431
|
[ "${GUARD_ON:-0}" != 1 ] || kill -s TERM -- "-$hpid" 2>/dev/null
|
|
430
432
|
pkill -TERM -P "$hpid" 2>/dev/null; kill -TERM "$hpid" 2>/dev/null
|
|
431
|
-
if [ "${GUARD_ON:-0}" = 1 ]; then
|
|
433
|
+
if [ "${GUARD_ON:-0}" = 1 ]; then
|
|
434
|
+
sleep 1; kill -s KILL -- "-$hpid" 2>/dev/null
|
|
435
|
+
# what it started in sessions of their own (#129)
|
|
436
|
+
python3 "$GUARD" reap "$hpid" "$RUN_DIR/$ROLE.orphans" --tracked "$RUN_DIR/$ROLE.tracked" >/dev/null 2>&1
|
|
437
|
+
fi
|
|
432
438
|
elif [ "${GUARD_ON:-0}" = 1 ] && [ "${reaped:-0}" != 1 ] && [ -n "${hpid:-}" ]; then
|
|
433
439
|
# Interrupted after the harness exited but before the normal reap.
|
|
434
|
-
python3 "$GUARD" reap "$hpid" "$RUN_DIR/$ROLE.orphans" >/dev/null 2>&1
|
|
440
|
+
python3 "$GUARD" reap "$hpid" "$RUN_DIR/$ROLE.orphans" --tracked "$RUN_DIR/$ROLE.tracked" >/dev/null 2>&1
|
|
435
441
|
fi
|
|
436
442
|
for watcher in ${wpid:-} ${spid:-}; do pkill -P "$watcher" 2>/dev/null; kill "$watcher" 2>/dev/null; done
|
|
437
443
|
[ -z "${cpid:-}" ] || kill "$cpid" 2>/dev/null
|
|
438
|
-
rm -f "$RUN_DIR/$ROLE.harness"
|
|
444
|
+
rm -f "$RUN_DIR/$ROLE.harness" "$RUN_DIR/$ROLE.tracked"
|
|
439
445
|
}
|
|
440
446
|
# What the EXIT trap's `finish` archives. Pessimistic until an outcome is known, so every
|
|
441
447
|
# path out of a continue request (a signal, a usage error after this point) leaves a record.
|
|
@@ -808,7 +814,7 @@ fi
|
|
|
808
814
|
# when a stale $LAST is already there. That is harmless when each run gets a fresh
|
|
809
815
|
# run-dir, and silently wrong for `forge-parallel.sh retry`, which reuses the task
|
|
810
816
|
# directory — it would read the first attempt's result and never notice.
|
|
811
|
-
rm -f "$LAST" "$LOG" "$RUN_DIR/$ROLE.clock" "$RUN_DIR/$ROLE.clock.stop" "$RUN_DIR/$ROLE.timedout" "$RUN_DIR/$ROLE.settled" "$RUN_DIR/$ROLE.infra" "$RUN_DIR/$ROLE.orphans" "$RUN_DIR/$ROLE.harness"
|
|
817
|
+
rm -f "$LAST" "$LOG" "$RUN_DIR/$ROLE.clock" "$RUN_DIR/$ROLE.clock.stop" "$RUN_DIR/$ROLE.timedout" "$RUN_DIR/$ROLE.settled" "$RUN_DIR/$ROLE.infra" "$RUN_DIR/$ROLE.orphans" "$RUN_DIR/$ROLE.harness" "$RUN_DIR/$ROLE.tracked"
|
|
812
818
|
python3 "$RUNTIME" phase "$ATTEMPT" model
|
|
813
819
|
t0="$(date +%s)"
|
|
814
820
|
# Process-group guard. A dwarf that starts `npm test &` and ends its turn leaves that
|
|
@@ -848,6 +854,13 @@ if [ "$GUARD_ON" = 1 ]; then
|
|
|
848
854
|
&& mv -f "$RUN_DIR/.$ROLE.harness.tmp" "$RUN_DIR/$ROLE.harness"
|
|
849
855
|
fi
|
|
850
856
|
fi
|
|
857
|
+
# The harness's descendants, sampled while it runs (#129). A tool that starts a session of its
|
|
858
|
+
# own (a test runner's web server) leaves the group the reap below signals, but the tracker saw
|
|
859
|
+
# it as a descendant, so the reap finds it by pid and start time. Advisory, like the guard.
|
|
860
|
+
tpid=""
|
|
861
|
+
if [ "$GUARD_ON" = 1 ]; then
|
|
862
|
+
python3 "$GUARD" track "$hpid" "$RUN_DIR/$ROLE.tracked" </dev/null >/dev/null 2>&1 & tpid=$!
|
|
863
|
+
fi
|
|
851
864
|
|
|
852
865
|
# Ends the harness: the whole process group first when the harness has its own (GUARD_ON),
|
|
853
866
|
# then children, then the process itself, then SIGKILL for a CLI that traps TERM and takes
|
|
@@ -908,15 +921,18 @@ for watcher in $wpid $spid; do
|
|
|
908
921
|
kill "$watcher" 2>/dev/null
|
|
909
922
|
wait "$watcher" 2>/dev/null
|
|
910
923
|
done
|
|
911
|
-
# Anything the harness left running in its group is an abandoned background job
|
|
912
|
-
#
|
|
913
|
-
#
|
|
924
|
+
# Anything the harness left running in its group is an abandoned background job, and so is
|
|
925
|
+
# anything the tracker saw it start that is still alive, in whatever session: a timeout stops
|
|
926
|
+
# the harness, not the test servers its tools started (#129). Kill them before reading the
|
|
927
|
+
# tree, and leave the list for the caller. Bounded (~6s) and advisory: a reaper failure
|
|
928
|
+
# changes nothing about the exit code.
|
|
929
|
+
if [ -n "$tpid" ]; then kill -TERM "$tpid" 2>/dev/null; wait "$tpid" 2>/dev/null; tpid=""; fi
|
|
914
930
|
if [ "$GUARD_ON" = 1 ]; then
|
|
915
|
-
orphans_found="$(python3 "$GUARD" reap "$hpid" "$RUN_DIR/$ROLE.orphans" 2>/dev/null)"
|
|
931
|
+
orphans_found="$(python3 "$GUARD" reap "$hpid" "$RUN_DIR/$ROLE.orphans" --tracked "$RUN_DIR/$ROLE.tracked" 2>/dev/null)"
|
|
916
932
|
case "$orphans_found" in ''|*[!0-9]*|0) ;; *) note "$HARNESS left $orphans_found process(es) running after it exited; killed — see $RUN_DIR/$ROLE.orphans" ;; esac
|
|
917
933
|
fi
|
|
918
934
|
reaped=1
|
|
919
|
-
rm -f "$RUN_DIR/$ROLE.harness"
|
|
935
|
+
rm -f "$RUN_DIR/$ROLE.harness" "$RUN_DIR/$ROLE.tracked"
|
|
920
936
|
# Neither CLI refuses a fast request it cannot honour: it runs slower and still exits 0.
|
|
921
937
|
# One note when the log shows that. The exit below stays the one the harness already returned.
|
|
922
938
|
if [ "$SERVICE_TIER" = fast ]; then
|
|
@@ -44,7 +44,9 @@ TEST_PATH = re.compile(r'(^|/)(tests?|spec|specs|__tests__)/'
|
|
|
44
44
|
r'|(^|/)test_[^/]*$|_test\.[^/]+$|\.(test|spec)\.[^/]+$')
|
|
45
45
|
CODE_SUFFIXES = ('.py', '.go', '.js', '.jsx', '.ts', '.tsx', '.rb', '.rs', '.java',
|
|
46
46
|
'.kt', '.php', '.sh', '.mjs', '.cjs')
|
|
47
|
-
|
|
47
|
+
# forge-artifact.sh's FORGE_DEP_DIRS: where package managers install into a checkout (#127)
|
|
48
|
+
DEP_DIRS = ('node_modules', 'bower_components', '.venv', 'venv', 'vendor', '.bundle', 'Pods', 'deps', '_build',
|
|
49
|
+
'.dart_tool', 'elm-stuff', '.build')
|
|
48
50
|
MAX_FILES = 20
|
|
49
51
|
TAIL = 2000
|
|
50
52
|
|
package/scripts/forge-guard.py
CHANGED
|
@@ -11,11 +11,27 @@
|
|
|
11
11
|
be signalled or reaped as a unit. macOS has no `setsid` binary; this is why the
|
|
12
12
|
helper exists.
|
|
13
13
|
|
|
14
|
-
forge-guard.py reap <pgid> <orphans-file>
|
|
14
|
+
forge-guard.py reap <pgid> <orphans-file> [--tracked <file>]
|
|
15
15
|
After the harness exited: anything still alive in its process group is an orphan
|
|
16
16
|
the implementer abandoned. List it (only when something is found), TERM, wait a
|
|
17
17
|
bounded ~2s, KILL, print how many were found. Never exits nonzero for an ordinary
|
|
18
|
-
outcome, and never touches its own or its caller's group.
|
|
18
|
+
outcome, and never touches its own or its caller's group. With --tracked, also every
|
|
19
|
+
process `track` recorded that is still alive with its recorded start time, and its
|
|
20
|
+
descendants now, whatever group or session it moved to (#129).
|
|
21
|
+
|
|
22
|
+
forge-guard.py track <pid> <file> [--interval S]
|
|
23
|
+
While the harness runs: every S seconds (default 2), append each new descendant of
|
|
24
|
+
<pid>, and of every process already recorded and still alive, as
|
|
25
|
+
`<pid><TAB><start time><TAB><command>`. A tool that starts a session of its own (a
|
|
26
|
+
test runner's web server) leaves the harness's group, but not its ancestry, so this is
|
|
27
|
+
how `reap --tracked` finds it. Runs until TERM, or until its parent is gone.
|
|
28
|
+
|
|
29
|
+
forge-guard.py stop-tree <pid> [--wait S]
|
|
30
|
+
A controller's interrupt (a standalone retry, #129): TERM the pid and every descendant it
|
|
31
|
+
has now, in any group or session, then wait up to S seconds (default 20) while they
|
|
32
|
+
clean up (a dispatch's EXIT trap stops its harness and reaps), then KILL what is left.
|
|
33
|
+
Each pid is matched by its start time, so a reused one is never signalled. Prints how
|
|
34
|
+
many processes were signalled.
|
|
19
35
|
|
|
20
36
|
forge-guard.py identity <pid>
|
|
21
37
|
Print the process's start time, which survives exec. Dispatch records it with the
|
|
@@ -29,6 +45,8 @@
|
|
|
29
45
|
pid with another start time was reused and is left alone. A dead pid's group may
|
|
30
46
|
still hold the harness's background jobs, and cannot have been reused while they
|
|
31
47
|
live, so it is reaped. The record is removed; prints how many processes were signalled.
|
|
48
|
+
A `<role>.tracked` file beside a `<role>.harness` record is reaped as `reap --tracked`
|
|
49
|
+
would, so a dispatch that died early leaves no tool behind either.
|
|
32
50
|
|
|
33
51
|
forge-guard.py promises <file> [--tail-bytes N]
|
|
34
52
|
Scan the tail of an implementer's final message for promises of later work ("it is
|
|
@@ -166,8 +184,200 @@ def _reap_group(pgid: int, orphans_file: str | None) -> int:
|
|
|
166
184
|
return len(found)
|
|
167
185
|
|
|
168
186
|
|
|
169
|
-
|
|
170
|
-
|
|
187
|
+
# --- track / tracked reap --------------------------------------------------------
|
|
188
|
+
TRACK_INTERVAL_S = 2.0
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def ps_table():
|
|
192
|
+
"""{pid: (ppid, start time, command)} of every live process but zombies, or None when ps is
|
|
193
|
+
unavailable. The start time is `identity`'s, whitespace-normalised the same way."""
|
|
194
|
+
for ps in PS_CANDIDATES:
|
|
195
|
+
if not os.access(ps, os.X_OK):
|
|
196
|
+
continue
|
|
197
|
+
try:
|
|
198
|
+
out = subprocess.run([ps, '-axo', 'pid=,ppid=,stat=,lstart=,command='], stdout=subprocess.PIPE,
|
|
199
|
+
stderr=subprocess.DEVNULL, timeout=5,
|
|
200
|
+
env=dict(os.environ, LC_ALL='C')).stdout.decode(errors='replace')
|
|
201
|
+
except (OSError, subprocess.SubprocessError):
|
|
202
|
+
continue
|
|
203
|
+
table = {}
|
|
204
|
+
for line in out.splitlines():
|
|
205
|
+
parts = line.split(None, 8) # pid ppid stat + lstart's five words + command
|
|
206
|
+
if len(parts) < 8:
|
|
207
|
+
continue
|
|
208
|
+
try:
|
|
209
|
+
pid, ppid = int(parts[0]), int(parts[1])
|
|
210
|
+
except ValueError:
|
|
211
|
+
continue
|
|
212
|
+
if parts[2].startswith('Z'):
|
|
213
|
+
continue
|
|
214
|
+
table[pid] = (ppid, ' '.join(parts[3:8]), parts[8].strip() if len(parts) > 8 else '')
|
|
215
|
+
return table
|
|
216
|
+
return None
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def descendants(table, roots):
|
|
220
|
+
"""Every live descendant of `roots` in a ps_table, the roots excluded."""
|
|
221
|
+
children = {}
|
|
222
|
+
for pid, (ppid, _start, _command) in table.items():
|
|
223
|
+
children.setdefault(ppid, []).append(pid)
|
|
224
|
+
out, todo = set(), [r for r in roots if r > 1]
|
|
225
|
+
while todo:
|
|
226
|
+
for child in children.get(todo.pop(), ()):
|
|
227
|
+
if child not in out and child not in roots:
|
|
228
|
+
out.add(child)
|
|
229
|
+
todo.append(child)
|
|
230
|
+
return out
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def read_tracked(path):
|
|
234
|
+
"""{pid: start time} of a track file; a torn last line is skipped."""
|
|
235
|
+
found = {}
|
|
236
|
+
try:
|
|
237
|
+
with open(path, errors='replace') as handle:
|
|
238
|
+
for line in handle:
|
|
239
|
+
if not line.endswith('\n'):
|
|
240
|
+
break
|
|
241
|
+
pid_text, _, rest = line.partition('\t')
|
|
242
|
+
start = rest.split('\t', 1)[0].strip()
|
|
243
|
+
try:
|
|
244
|
+
pid = int(pid_text)
|
|
245
|
+
except ValueError:
|
|
246
|
+
continue
|
|
247
|
+
if pid > 1 and start:
|
|
248
|
+
found[pid] = start
|
|
249
|
+
except OSError:
|
|
250
|
+
pass
|
|
251
|
+
return found
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _mine(table, known):
|
|
255
|
+
"""The recorded processes still alive with their recorded start time (not a reused pid)."""
|
|
256
|
+
return {pid for pid, start in known.items() if pid in table and table[pid][1] == start}
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def track(root: int, path: str, interval: float = TRACK_INTERVAL_S) -> int:
|
|
260
|
+
known = read_tracked(path)
|
|
261
|
+
parent = os.getppid()
|
|
262
|
+
stopping = []
|
|
263
|
+
signal.signal(signal.SIGTERM, lambda *_: stopping.append(1))
|
|
264
|
+
while not stopping:
|
|
265
|
+
table = ps_table()
|
|
266
|
+
if table is None:
|
|
267
|
+
return 0
|
|
268
|
+
new = []
|
|
269
|
+
for pid in sorted(descendants(table, {root} | _mine(table, known))):
|
|
270
|
+
start = table[pid][1]
|
|
271
|
+
if known.get(pid) != start and pid != os.getpid():
|
|
272
|
+
known[pid] = start
|
|
273
|
+
new.append('%d\t%s\t%s\n' % (pid, start, ' '.join(table[pid][2].split()).replace('\t', ' ')))
|
|
274
|
+
if new:
|
|
275
|
+
try:
|
|
276
|
+
with open(path, 'a') as handle:
|
|
277
|
+
handle.write(''.join(new))
|
|
278
|
+
except OSError:
|
|
279
|
+
pass
|
|
280
|
+
if os.getppid() != parent:
|
|
281
|
+
return 0 # the dispatch is gone; its EXIT trap reaps
|
|
282
|
+
deadline = time.monotonic() + interval
|
|
283
|
+
while not stopping and time.monotonic() < deadline:
|
|
284
|
+
time.sleep(0.05)
|
|
285
|
+
return 0
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def _never(table) -> set:
|
|
289
|
+
"""Pids a tracked reap never signals: init, this process and its ancestors."""
|
|
290
|
+
never, pid = {0, 1}, os.getpid()
|
|
291
|
+
while pid and pid not in never:
|
|
292
|
+
never.add(pid)
|
|
293
|
+
pid = table.get(pid, (0,))[0] if table else 0
|
|
294
|
+
return never
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def _reap_tracked(path: str, skip_group: int | None) -> list:
|
|
298
|
+
"""TERM, then KILL, what a track file recorded that is still ours, and its descendants now;
|
|
299
|
+
[(pid, command)] of what was found. Members of `skip_group` are left to the group reap."""
|
|
300
|
+
known = read_tracked(path) if path else {}
|
|
301
|
+
if not known:
|
|
302
|
+
return []
|
|
303
|
+
found = {}
|
|
304
|
+
for sig, wait in ((signal.SIGTERM, TERM_WAIT_S), (signal.SIGKILL, KILL_WAIT_S)):
|
|
305
|
+
table = ps_table()
|
|
306
|
+
if table is None:
|
|
307
|
+
break
|
|
308
|
+
never = _never(table)
|
|
309
|
+
targets = _mine(table, known)
|
|
310
|
+
targets |= descendants(table, targets)
|
|
311
|
+
targets -= never
|
|
312
|
+
if skip_group is not None:
|
|
313
|
+
targets = {pid for pid in targets if _pgid(pid) != skip_group}
|
|
314
|
+
if not targets:
|
|
315
|
+
break
|
|
316
|
+
for pid in targets:
|
|
317
|
+
found.setdefault(pid, table[pid][2])
|
|
318
|
+
try:
|
|
319
|
+
os.kill(pid, sig)
|
|
320
|
+
except OSError:
|
|
321
|
+
pass
|
|
322
|
+
deadline = time.monotonic() + wait
|
|
323
|
+
while time.monotonic() < deadline:
|
|
324
|
+
table = ps_table() or {}
|
|
325
|
+
if not any(pid in table for pid in targets):
|
|
326
|
+
break
|
|
327
|
+
time.sleep(0.05)
|
|
328
|
+
return sorted(found.items())
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def _pgid(pid: int):
|
|
332
|
+
try:
|
|
333
|
+
return os.getpgid(pid)
|
|
334
|
+
except OSError:
|
|
335
|
+
return None
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def _write_orphans(orphans_file, rows, append=False):
|
|
339
|
+
if not orphans_file or not rows:
|
|
340
|
+
return
|
|
341
|
+
try:
|
|
342
|
+
with open(orphans_file, 'a' if append else 'w') as handle:
|
|
343
|
+
for pid, command in rows:
|
|
344
|
+
handle.write('%s\t%s\n' % (pid or '?', ' '.join(command.split()) or '?'))
|
|
345
|
+
except OSError:
|
|
346
|
+
pass
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def stop_tree(root: int, wait: float) -> int:
|
|
350
|
+
table = ps_table()
|
|
351
|
+
if table is None or root <= 1:
|
|
352
|
+
print(0)
|
|
353
|
+
return 0
|
|
354
|
+
targets = (({root} if root in table else set()) | descendants(table, {root})) - _never(table)
|
|
355
|
+
starts = {pid: table[pid][1] for pid in targets}
|
|
356
|
+
for pid in targets:
|
|
357
|
+
try:
|
|
358
|
+
os.kill(pid, signal.SIGTERM)
|
|
359
|
+
except OSError:
|
|
360
|
+
pass
|
|
361
|
+
deadline = time.monotonic() + wait
|
|
362
|
+
left = set(targets)
|
|
363
|
+
while left and time.monotonic() < deadline:
|
|
364
|
+
time.sleep(0.2)
|
|
365
|
+
now = ps_table() or {}
|
|
366
|
+
left = {pid for pid in left if pid in now and now[pid][1] == starts[pid]}
|
|
367
|
+
for pid in left:
|
|
368
|
+
try:
|
|
369
|
+
os.kill(pid, signal.SIGKILL)
|
|
370
|
+
except OSError:
|
|
371
|
+
pass
|
|
372
|
+
print(len(targets))
|
|
373
|
+
return 0
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
def reap(pgid: int, orphans_file: str, tracked: str | None = None) -> int:
|
|
377
|
+
count = _reap_group(pgid, orphans_file)
|
|
378
|
+
extra = _reap_tracked(tracked, pgid) if tracked else []
|
|
379
|
+
_write_orphans(orphans_file, extra, append=count > 0)
|
|
380
|
+
print(count + len(extra))
|
|
171
381
|
return 0
|
|
172
382
|
|
|
173
383
|
|
|
@@ -270,6 +480,8 @@ def stop(record: str) -> int:
|
|
|
270
480
|
count = _stop_live(pid)
|
|
271
481
|
else:
|
|
272
482
|
count = _reap_group(pid, None)
|
|
483
|
+
if record.endswith('.harness'):
|
|
484
|
+
count += len(_reap_tracked(record[:-len('.harness')] + '.tracked', None))
|
|
273
485
|
try:
|
|
274
486
|
os.unlink(record)
|
|
275
487
|
except OSError:
|
|
@@ -355,8 +567,10 @@ def promises(path: str, tail_bytes: int = 3000) -> int:
|
|
|
355
567
|
# --- cli ----------------------------------------------------------------------
|
|
356
568
|
def main(argv: list[str]) -> int:
|
|
357
569
|
if not argv:
|
|
358
|
-
print('usage: forge-guard.py ping | session -- CMD... | reap <pgid> <orphans-file> | '
|
|
359
|
-
'
|
|
570
|
+
print('usage: forge-guard.py ping | session -- CMD... | reap <pgid> <orphans-file> [--tracked FILE] | '
|
|
571
|
+
'track <pid> <file> [--interval S] | stop-tree <pid> [--wait S] | identity <pid> | '
|
|
572
|
+
'stop <record-file> | '
|
|
573
|
+
'promises <file> [--tail-bytes N]', file=sys.stderr)
|
|
360
574
|
return 2
|
|
361
575
|
command, rest = argv[0], argv[1:]
|
|
362
576
|
try:
|
|
@@ -368,10 +582,35 @@ def main(argv: list[str]) -> int:
|
|
|
368
582
|
rest = rest[1:]
|
|
369
583
|
return session(rest)
|
|
370
584
|
if command == 'reap':
|
|
585
|
+
tracked = None
|
|
586
|
+
if '--tracked' in rest:
|
|
587
|
+
index = rest.index('--tracked')
|
|
588
|
+
tracked = rest[index + 1]
|
|
589
|
+
rest = rest[:index] + rest[index + 2:]
|
|
590
|
+
if len(rest) != 2:
|
|
591
|
+
print('usage: forge-guard.py reap <pgid> <orphans-file> [--tracked FILE]', file=sys.stderr)
|
|
592
|
+
return 2
|
|
593
|
+
return reap(int(rest[0]), rest[1], tracked)
|
|
594
|
+
if command == 'stop-tree':
|
|
595
|
+
wait = 20.0
|
|
596
|
+
if '--wait' in rest:
|
|
597
|
+
index = rest.index('--wait')
|
|
598
|
+
wait = float(rest[index + 1])
|
|
599
|
+
rest = rest[:index] + rest[index + 2:]
|
|
600
|
+
if len(rest) != 1:
|
|
601
|
+
print('usage: forge-guard.py stop-tree <pid> [--wait S]', file=sys.stderr)
|
|
602
|
+
return 2
|
|
603
|
+
return stop_tree(int(rest[0]), max(0.0, wait))
|
|
604
|
+
if command == 'track':
|
|
605
|
+
interval = TRACK_INTERVAL_S
|
|
606
|
+
if '--interval' in rest:
|
|
607
|
+
index = rest.index('--interval')
|
|
608
|
+
interval = float(rest[index + 1])
|
|
609
|
+
rest = rest[:index] + rest[index + 2:]
|
|
371
610
|
if len(rest) != 2:
|
|
372
|
-
print('usage: forge-guard.py
|
|
611
|
+
print('usage: forge-guard.py track <pid> <file> [--interval S]', file=sys.stderr)
|
|
373
612
|
return 2
|
|
374
|
-
return
|
|
613
|
+
return track(int(rest[0]), rest[1], max(0.1, interval))
|
|
375
614
|
if command == 'identity':
|
|
376
615
|
if len(rest) != 1:
|
|
377
616
|
print('usage: forge-guard.py identity <pid>', file=sys.stderr)
|
package/scripts/forge-issues.py
CHANGED
|
@@ -566,6 +566,18 @@ def collect_plan(plan_dir: Path, include_plausible):
|
|
|
566
566
|
if review:
|
|
567
567
|
items, _ = task_findings(review, plan_dir, include_plausible, {}, review=True)
|
|
568
568
|
found += [{**f, "task": None} for f in items]
|
|
569
|
+
# What an adopted range kept (`adopt`), read as an accepted task's are: its known_issues.md holds what fell
|
|
570
|
+
# below the threshold and, under `--approved`, the findings a person kept. Its review never goes stale.
|
|
571
|
+
for row in read(plan_dir / "adoptions.tsv").splitlines() if (plan_dir / "adoptions.tsv").is_file() else []:
|
|
572
|
+
cols = row.split("\t")
|
|
573
|
+
adopted = plan_dir / cols[6] if len(cols) > 6 and cols[6] else None
|
|
574
|
+
if adopted and adopted.is_dir():
|
|
575
|
+
meta = {"task": adopted.name, "commit": cols[2], "reviewer": cols[5],
|
|
576
|
+
"threshold": effective_threshold(adopted, plan_dir)}
|
|
577
|
+
found += known_findings(read(adopted / "known_issues.md"), adopted, meta)
|
|
578
|
+
if include_plausible:
|
|
579
|
+
found += [{**f, **meta, "origin": "plausible", "review": None}
|
|
580
|
+
for f in parse_findings(read(adopted / "qa.last")) if f["confidence"] == "PLAUSIBLE"]
|
|
569
581
|
for f in found:
|
|
570
582
|
f["plan"], f["plan_dir"] = plan_dir.name, str(plan_dir)
|
|
571
583
|
return found, notes
|