magehand 0.76.3__tar.gz → 0.76.4__tar.gz
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.
- {magehand-0.76.3 → magehand-0.76.4}/PKG-INFO +2 -2
- {magehand-0.76.3 → magehand-0.76.4}/README.md +1 -1
- {magehand-0.76.3 → magehand-0.76.4}/pyproject.toml +1 -1
- {magehand-0.76.3 → magehand-0.76.4}/src/magehand/cli.py +45 -8
- {magehand-0.76.3 → magehand-0.76.4}/tests/test_cli.py +57 -0
- {magehand-0.76.3 → magehand-0.76.4}/.gitignore +0 -0
- {magehand-0.76.3 → magehand-0.76.4}/LICENSE +0 -0
- {magehand-0.76.3 → magehand-0.76.4}/assets/README.md +0 -0
- {magehand-0.76.3 → magehand-0.76.4}/src/magehand/__init__.py +0 -0
- {magehand-0.76.3 → magehand-0.76.4}/src/magehand/__main__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: magehand
|
|
3
|
-
Version: 0.76.
|
|
3
|
+
Version: 0.76.4
|
|
4
4
|
Summary: The developer CLI for building apps on davidlarrimore's homelab
|
|
5
5
|
Project-URL: Source, https://github.com/davidlarrimore/magehand
|
|
6
6
|
License-Expression: MIT
|
|
@@ -157,7 +157,7 @@ has it as `"next"`. Only commands whose output is the result itself (`guide`,
|
|
|
157
157
|
| Command | What it does |
|
|
158
158
|
| --- | --- |
|
|
159
159
|
| `magehand spec check N / spec verify N` | Ask OpenClaw whether an issue's spec is buildable, or whether a PR meets it |
|
|
160
|
-
| `magehand pr ready [N] / pr watch [N]` | Mark a green PR ready and request OpenClaw's review, then follow it until it needs you or is done (findings, a failed check, or a verify verdict for its head that isn't `met`) |
|
|
160
|
+
| `magehand pr ready [N] / pr watch [N]` | Mark a green PR ready and request OpenClaw's review, then follow it until it needs you or is done (findings, a failed or cancelled check, or a verify verdict for its head that isn't `met`); a check counts by its latest run on the head, as `gh pr checks` shows it |
|
|
161
161
|
| `magehand pr answer [N] [K]` | List the findings of OpenClaw's latest review (answered ones marked), or answer finding K with a PR comment (`-m TEXT`, `--body-file FILE`): the condition of the review's bar it fails and the fact that shows it, or the issue it's parked in. Then `pr ready` again: OpenClaw judges the answers on the same head, with no push and no CI run |
|
|
162
162
|
| `magehand release [APP]` | Cut the app's production release (the next `vX.Y.Z`), only when the owner asks |
|
|
163
163
|
| `magehand job add / rm / ls` | Add, remove and list the app's scheduled jobs (CronJobs) |
|
|
@@ -142,7 +142,7 @@ has it as `"next"`. Only commands whose output is the result itself (`guide`,
|
|
|
142
142
|
| Command | What it does |
|
|
143
143
|
| --- | --- |
|
|
144
144
|
| `magehand spec check N / spec verify N` | Ask OpenClaw whether an issue's spec is buildable, or whether a PR meets it |
|
|
145
|
-
| `magehand pr ready [N] / pr watch [N]` | Mark a green PR ready and request OpenClaw's review, then follow it until it needs you or is done (findings, a failed check, or a verify verdict for its head that isn't `met`) |
|
|
145
|
+
| `magehand pr ready [N] / pr watch [N]` | Mark a green PR ready and request OpenClaw's review, then follow it until it needs you or is done (findings, a failed or cancelled check, or a verify verdict for its head that isn't `met`); a check counts by its latest run on the head, as `gh pr checks` shows it |
|
|
146
146
|
| `magehand pr answer [N] [K]` | List the findings of OpenClaw's latest review (answered ones marked), or answer finding K with a PR comment (`-m TEXT`, `--body-file FILE`): the condition of the review's bar it fails and the fact that shows it, or the issue it's parked in. Then `pr ready` again: OpenClaw judges the answers on the same head, with no push and no CI run |
|
|
147
147
|
| `magehand release [APP]` | Cut the app's production release (the next `vX.Y.Z`), only when the owner asks |
|
|
148
148
|
| `magehand job add / rm / ls` | Add, remove and list the app's scheduled jobs (CronJobs) |
|
|
@@ -938,6 +938,21 @@ def agent_token():
|
|
|
938
938
|
return (token, left) if isinstance(token, str) and token and left > 0 else (None, 0)
|
|
939
939
|
|
|
940
940
|
|
|
941
|
+
def agent_token_problem():
|
|
942
|
+
"""Why there is no agent token, never quoting MAGEHAND_AGENT_TOKEN: it names a file, and a mistake that puts the
|
|
943
|
+
token itself there would otherwise print a credential (#160)."""
|
|
944
|
+
value = AGENT_TOKEN.strip()
|
|
945
|
+
# A JWT (base64url JSON, so 'eyJ', in three parts) or a long opaque string with no path in it.
|
|
946
|
+
if (value.startswith('eyJ') and value.count('.') == 2) or (os.sep not in value and len(value) > 64):
|
|
947
|
+
return ('MAGEHAND_AGENT_TOKEN holds what looks like a token itself: it must name the token file the lab '
|
|
948
|
+
'renews (in an agent\'s VM, /run/homelab-agents/<agent>.json), never the token')
|
|
949
|
+
if not os.path.isfile(value):
|
|
950
|
+
return ("the agent's dev token file (the file MAGEHAND_AGENT_TOKEN names) isn't there: the lab writes it every "
|
|
951
|
+
'5 minutes (homelab-agent-token.timer in its VM); if it stays missing, tell the owner')
|
|
952
|
+
return ("the agent's dev token is unreadable or expired: the lab replaces it every 5 minutes "
|
|
953
|
+
'(homelab-agent-token.timer in its VM); if it stays that way, tell the owner')
|
|
954
|
+
|
|
955
|
+
|
|
941
956
|
def agent_refuses(command, what):
|
|
942
957
|
"""An agent's command that is the owner's alone: exit before anything is sent."""
|
|
943
958
|
if AGENT_TOKEN:
|
|
@@ -1041,8 +1056,7 @@ def api_session_token(below=API_RENEW_BELOW, need=0, failed=None):
|
|
|
1041
1056
|
if AGENT_TOKEN:
|
|
1042
1057
|
token, left = agent_token()
|
|
1043
1058
|
if not token:
|
|
1044
|
-
die(
|
|
1045
|
-
'(homelab-agent-token.timer in its VM); if it stays missing, tell the owner')
|
|
1059
|
+
die(agent_token_problem())
|
|
1046
1060
|
if left < need:
|
|
1047
1061
|
die(f"the agent's dev token has only {minutes(left)} left: the lab replaces it (homelab-agent-token.timer); "
|
|
1048
1062
|
'try again shortly, and if it stays short, tell the owner')
|
|
@@ -1535,11 +1549,28 @@ def failing_checks(rollup):
|
|
|
1535
1549
|
GREEN_CONCLUSIONS = ('SUCCESS', 'NEUTRAL', 'SKIPPED')
|
|
1536
1550
|
|
|
1537
1551
|
|
|
1552
|
+
def latest_checks(rollup):
|
|
1553
|
+
"""A PR's statusCheckRollup with only the latest run of each check, as `gh pr checks` shows it (#161). The
|
|
1554
|
+
rollup keeps every run on the head: a run a newer one superseded (cancelled when a draft was readied, or re-run)
|
|
1555
|
+
is history, not the check's result. A check is its workflow and name (a StatusContext: its context); the latest
|
|
1556
|
+
is the one started last, and one not started yet (no time) is newer than any that has."""
|
|
1557
|
+
latest = {}
|
|
1558
|
+
for i, c in enumerate(rollup or []):
|
|
1559
|
+
key = (c.get('__typename'), c.get('workflowName'), c.get('name') or c.get('context') or '?')
|
|
1560
|
+
when = c.get('startedAt') or c.get('createdAt')
|
|
1561
|
+
rank = (when is None and c.get('status') not in (None, 'COMPLETED'), when or '', -i)
|
|
1562
|
+
if key not in latest or rank > latest[key][0]:
|
|
1563
|
+
latest[key] = (rank, c)
|
|
1564
|
+
keep = {id(c) for _, c in latest.values()}
|
|
1565
|
+
return [c for c in rollup or [] if id(c) in keep]
|
|
1566
|
+
|
|
1567
|
+
|
|
1538
1568
|
def not_green_checks(rollup):
|
|
1539
1569
|
"""'name (result)' for each finished entry of a PR's statusCheckRollup that isn't a pass: a CheckRun whose
|
|
1540
|
-
conclusion isn't in GREEN_CONCLUSIONS, a StatusContext in FAILURE or ERROR.
|
|
1570
|
+
conclusion isn't in GREEN_CONCLUSIONS, a StatusContext in FAILURE or ERROR. Only each check's latest run
|
|
1571
|
+
counts (latest_checks)."""
|
|
1541
1572
|
out = []
|
|
1542
|
-
for c in rollup
|
|
1573
|
+
for c in latest_checks(rollup):
|
|
1543
1574
|
name = c.get('name') or c.get('context') or '?'
|
|
1544
1575
|
if c.get('state') in ('FAILURE', 'ERROR'):
|
|
1545
1576
|
out.append(f'{name} ({c["state"].lower()})')
|
|
@@ -1551,7 +1582,7 @@ def not_green_checks(rollup):
|
|
|
1551
1582
|
def pending_checks(rollup):
|
|
1552
1583
|
"""Names of the entries of a PR's statusCheckRollup that haven't finished: CheckRuns not COMPLETED and
|
|
1553
1584
|
StatusContexts still PENDING or EXPECTED."""
|
|
1554
|
-
return [c.get('name') or c.get('context') or '?' for c in rollup
|
|
1585
|
+
return [c.get('name') or c.get('context') or '?' for c in latest_checks(rollup)
|
|
1555
1586
|
if (c.get('status') and c.get('status') != 'COMPLETED') or c.get('state') in ('PENDING', 'EXPECTED')]
|
|
1556
1587
|
|
|
1557
1588
|
|
|
@@ -2594,8 +2625,8 @@ GITHUB_API = 'https://api.github.com/'
|
|
|
2594
2625
|
# The `gh pr list --json` fields magehand reads, as GraphQL: the same names and shapes gh returns.
|
|
2595
2626
|
PR_LIST_FIELDS = {'number': 'number', 'state': 'state', 'mergedAt': 'mergedAt', 'title': 'title', 'body': 'body',
|
|
2596
2627
|
'statusCheckRollup': 'commits(last: 1) { nodes { commit { statusCheckRollup { contexts(first: 100) '
|
|
2597
|
-
'{ nodes { __typename ... on CheckRun { name status conclusion } '
|
|
2598
|
-
'... on StatusContext { context state } } } } } } }'}
|
|
2628
|
+
'{ nodes { __typename ... on CheckRun { name status conclusion startedAt } '
|
|
2629
|
+
'... on StatusContext { context state createdAt } } } } } } }'}
|
|
2599
2630
|
|
|
2600
2631
|
|
|
2601
2632
|
def github_request(method, path, body=None, accept='application/vnd.github+json'):
|
|
@@ -9227,7 +9258,7 @@ def cmd_pr(a):
|
|
|
9227
9258
|
# needs the agent or the PR is done, then prints what happened and the next step and exits, so an agent that
|
|
9228
9259
|
# runs it in the background (Claude Code wakes when it exits) or in the foreground (Codex) picks the work up.
|
|
9229
9260
|
# Exit 0: done (`result` merged, held, green, reviewed); 1: something to do, `next:` says what (findings,
|
|
9230
|
-
# failed, closed, stalled, unrequested, live-test, timeout). Usage errors exit 2, as everywhere.
|
|
9261
|
+
# failed, cancelled, closed, stalled, unrequested, live-test, timeout). Usage errors exit 2, as everywhere.
|
|
9231
9262
|
|
|
9232
9263
|
WATCH_FIELDS = PR_FIELDS + ',reviews,assignees,labels,files,comments'
|
|
9233
9264
|
# The Requirements Owner's verdict on a head (homelab#742): OpenClaw's comment carries this mark, and a PR that closes
|
|
@@ -9334,6 +9365,12 @@ def watch_step(pr, memory, now, open_threads=lambda: []):
|
|
|
9334
9365
|
return 'merged', 'merged', None
|
|
9335
9366
|
if pr.get('state') == 'CLOSED':
|
|
9336
9367
|
return 'closed', 'closed without merging', 'ask the owner why, if you did not close it'
|
|
9368
|
+
if failing and all(f.endswith(' (cancelled)') for f in failing):
|
|
9369
|
+
# Nothing failed: a run was stopped (a runner went away, someone cancelled it). Re-running it costs no push,
|
|
9370
|
+
# so the head, its review and its live test stay (#161).
|
|
9371
|
+
return 'cancelled', f'checks cancelled on {head[:7]}: {", ".join(failing)}', \
|
|
9372
|
+
(f're-run them (`gh pr checks {n}` links each run; `gh run rerun RUN_ID --failed`), no push needed, '
|
|
9373
|
+
f'then `magehand pr watch {n}`')
|
|
9337
9374
|
if failing:
|
|
9338
9375
|
undo = '' if pr.get('isDraft') else f'`gh pr ready {n} --undo`, '
|
|
9339
9376
|
return 'failed', f'checks failed on {head[:7]}: {", ".join(failing)}', \
|
|
@@ -1623,6 +1623,23 @@ class AgentIdentity(unittest.TestCase):
|
|
|
1623
1623
|
magehand.api_session_token()
|
|
1624
1624
|
self.assertIn('homelab-agent-token', str(caught.exception))
|
|
1625
1625
|
|
|
1626
|
+
def test_a_token_put_in_the_variable_itself_is_never_printed(self):
|
|
1627
|
+
"""#160: MAGEHAND_AGENT_TOKEN names a file. Set to the token by mistake, the error says so without the value."""
|
|
1628
|
+
jwt = 'eyJhbGciOiJSUzI1NiJ9.' + 'eyJzdWIiOiJ0ZXN0In0' * 4 + '.' + 'c2lnbmF0dXJl' * 8
|
|
1629
|
+
for value in (jwt, 'x' * 80):
|
|
1630
|
+
with mock.patch.object(magehand, 'AGENT_TOKEN', value), self.assertRaises(SystemExit) as caught:
|
|
1631
|
+
magehand.api_session_token()
|
|
1632
|
+
self.assertNotIn(value, str(caught.exception))
|
|
1633
|
+
self.assertIn('must name the token file', str(caught.exception))
|
|
1634
|
+
# Missing, expired or unreadable: the value isn't printed either, and the message names the lab's timer.
|
|
1635
|
+
for prepare in (lambda: None, lambda: self.token(left=-5)):
|
|
1636
|
+
self.path.unlink(missing_ok=True)
|
|
1637
|
+
prepare()
|
|
1638
|
+
with self.assertRaises(SystemExit) as caught:
|
|
1639
|
+
magehand.api_session_token()
|
|
1640
|
+
self.assertNotIn(str(self.path), str(caught.exception))
|
|
1641
|
+
self.assertIn('homelab-agent-token', str(caught.exception))
|
|
1642
|
+
|
|
1626
1643
|
def test_dev_requests_carry_the_agents_token(self):
|
|
1627
1644
|
self.token('agent-tok')
|
|
1628
1645
|
calls = []
|
|
@@ -4720,6 +4737,46 @@ class PrWatch(unittest.TestCase):
|
|
|
4720
4737
|
self.assertIn('--undo', self.step(self.pr(checks=self.FAILED))[2])
|
|
4721
4738
|
self.assertNotIn('--undo', self.step(self.pr(checks=self.FAILED, draft=True))[2])
|
|
4722
4739
|
|
|
4740
|
+
def test_only_each_checks_latest_run_counts(self):
|
|
4741
|
+
"""#161 (homelab#895, 2026-11-30): readying the draft started a new run and the workflow's concurrency
|
|
4742
|
+
cancelled the one in progress. The rollup keeps both; only the latest run of each check is its result."""
|
|
4743
|
+
def run(name, started, status='COMPLETED', conclusion=None):
|
|
4744
|
+
return {'__typename': 'CheckRun', 'workflowName': 'Validate homelab', 'name': name, 'status': status,
|
|
4745
|
+
'conclusion': conclusion, 'startedAt': started}
|
|
4746
|
+
superseded = [run('checks / pre-commit', '2026-11-30T21:46:36Z', conclusion='CANCELLED'),
|
|
4747
|
+
run('validate', '2026-11-30T21:47:46Z', conclusion='SUCCESS'),
|
|
4748
|
+
run('checks / pre-commit', '2026-11-30T21:50:39Z', status='QUEUED'),
|
|
4749
|
+
run('validate', '2026-11-30T21:51:14Z', status='IN_PROGRESS')]
|
|
4750
|
+
self.assertEqual(magehand.not_green_checks(superseded), [])
|
|
4751
|
+
self.assertEqual(sorted(magehand.pending_checks(superseded)), ['checks / pre-commit', 'validate'])
|
|
4752
|
+
got, what, _ = self.step(self.pr(checks=superseded, review=[('APPROVED', self.HEAD)]))
|
|
4753
|
+
self.assertIsNone(got, what) # still running, not failed
|
|
4754
|
+
done = superseded[:2] + [run('checks / pre-commit', '2026-11-30T21:50:39Z', conclusion='SUCCESS'),
|
|
4755
|
+
run('validate', '2026-11-30T21:51:14Z', conclusion='SUCCESS')]
|
|
4756
|
+
self.assertEqual(magehand.not_green_checks(done), [])
|
|
4757
|
+
# A newer failure still fails, whatever the older run said; a queued run with no time yet is the newest.
|
|
4758
|
+
self.assertEqual(magehand.failing_checks([run('validate', '2026-11-30T21:00:00Z', conclusion='SUCCESS'),
|
|
4759
|
+
run('validate', '2026-11-30T22:00:00Z', conclusion='FAILURE')]),
|
|
4760
|
+
['validate'])
|
|
4761
|
+
self.assertEqual(magehand.pending_checks([run('validate', '2026-11-30T21:00:00Z', conclusion='CANCELLED'),
|
|
4762
|
+
run('validate', None, status='QUEUED')]), ['validate'])
|
|
4763
|
+
# The same name in another workflow is another check.
|
|
4764
|
+
other = {**run('validate', '2026-11-30T22:00:00Z', conclusion='FAILURE'), 'workflowName': 'Other'}
|
|
4765
|
+
self.assertEqual(magehand.failing_checks(done + [other]), ['validate'])
|
|
4766
|
+
# Rollups without times (older callers): every entry still counts once.
|
|
4767
|
+
self.assertEqual(magehand.failing_checks(self.FAILED), ['tests'])
|
|
4768
|
+
|
|
4769
|
+
def test_a_cancelled_latest_run_is_re_run_not_fixed(self):
|
|
4770
|
+
cancelled = [{'name': 'tests', 'status': 'COMPLETED', 'conclusion': 'CANCELLED'}]
|
|
4771
|
+
got, what, step = self.step(self.pr(checks=cancelled, labels=['live-tested']))
|
|
4772
|
+
self.assertEqual(got, 'cancelled', what)
|
|
4773
|
+
self.assertIn('gh run rerun', step)
|
|
4774
|
+
for wrong in ('--undo', 'push until green', 'remove-label'):
|
|
4775
|
+
self.assertNotIn(wrong, step)
|
|
4776
|
+
# A real failure beside a cancelled run is a failure.
|
|
4777
|
+
mixed = cancelled + [{'name': 'lint', 'status': 'COMPLETED', 'conclusion': 'FAILURE'}]
|
|
4778
|
+
self.assertEqual(self.step(self.pr(checks=mixed))[0], 'failed')
|
|
4779
|
+
|
|
4723
4780
|
def test_a_verify_verdict_that_isnt_met_is_findings(self):
|
|
4724
4781
|
# homelab#742: OpenClaw merges a PR that closes an issue only once its head's latest verdict is `met`.
|
|
4725
4782
|
H = self.HEAD
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|