arkaos 2.42.0 → 2.43.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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.42.0
1
+ 2.43.0
@@ -0,0 +1 @@
1
+ """Release pipeline tooling — preflight gate, version helpers."""
@@ -0,0 +1,225 @@
1
+ """Release preflight gate (PR21 v2.43.0).
2
+
3
+ Runs BEFORE the irreversible tag/push/publish steps of the release
4
+ pipeline. Catches expired tokens, version misalignment, and dirty
5
+ git state at minute 0 instead of minute 60.
6
+
7
+ Closes a real-world debt: v2.40.0 release took ~1h because the npm
8
+ token had expired silently and the failure was only discovered
9
+ after merge, tag, GH release. A 2-second check up front would have
10
+ turned that into an immediate STOP-and-rotate.
11
+
12
+ All shell-outs use ``subprocess.run(check=False, capture_output=True,
13
+ timeout=10)`` with argv as a list — no ``shell=True``, no string
14
+ interpolation of user input.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import re
20
+ import shutil
21
+ import subprocess
22
+ from dataclasses import dataclass, field
23
+ from pathlib import Path
24
+
25
+ _DEFAULT_REPO_ROOT = Path.cwd()
26
+ _SUBPROCESS_TIMEOUT = 10
27
+ _NPM_PACKAGE_VERSION_RE = re.compile(r'"version"\s*:\s*"([^"]+)"')
28
+ _PYPROJECT_VERSION_RE = re.compile(r'^version\s*=\s*"([^"]+)"', re.MULTILINE)
29
+
30
+
31
+ @dataclass(frozen=True)
32
+ class CheckResult:
33
+ """Single preflight check outcome."""
34
+ name: str
35
+ passed: bool
36
+ reason: str
37
+ remediation: str | None = None
38
+ severity: str = "blocking"
39
+
40
+
41
+ @dataclass(frozen=True)
42
+ class PreflightReport:
43
+ """Aggregated preflight verdict."""
44
+ all_passed: bool
45
+ results: list[CheckResult] = field(default_factory=list)
46
+ blocking_failures: list[CheckResult] = field(default_factory=list)
47
+ warnings: list[CheckResult] = field(default_factory=list)
48
+
49
+
50
+ def run_preflight(
51
+ *,
52
+ repo_root: Path | None = None,
53
+ expected_npm_user: str | None = None,
54
+ ) -> PreflightReport:
55
+ """Run every preflight check and return an aggregated report."""
56
+ root = repo_root or _DEFAULT_REPO_ROOT
57
+ results = [
58
+ check_version_alignment(repo_root=root),
59
+ check_npm_auth(expected_user=expected_npm_user),
60
+ check_npm_publish_capability(),
61
+ check_gh_auth(),
62
+ check_git_remote(),
63
+ check_git_clean(),
64
+ ]
65
+ return _aggregate(results)
66
+
67
+
68
+ def _load_repo_versions(
69
+ root: Path,
70
+ ) -> tuple[str | None, str | None, str | None] | None:
71
+ """Read VERSION, package.json, pyproject.toml. None if any unreadable."""
72
+ try:
73
+ v = (root / "VERSION").read_text(encoding="utf-8").strip()
74
+ pkg_match = _NPM_PACKAGE_VERSION_RE.search(
75
+ (root / "package.json").read_text(encoding="utf-8"),
76
+ )
77
+ py_match = _PYPROJECT_VERSION_RE.search(
78
+ (root / "pyproject.toml").read_text(encoding="utf-8"),
79
+ )
80
+ except (OSError, AttributeError):
81
+ return None
82
+ pkg_v = pkg_match.group(1) if pkg_match else None
83
+ py_v = py_match.group(1) if py_match else None
84
+ return v, pkg_v, py_v
85
+
86
+
87
+ def check_version_alignment(*, repo_root: Path | None = None) -> CheckResult:
88
+ """Verify VERSION, package.json, pyproject.toml all carry the same version."""
89
+ root = repo_root or _DEFAULT_REPO_ROOT
90
+ versions = _load_repo_versions(root)
91
+ if versions is None:
92
+ return CheckResult(
93
+ name="version-alignment", passed=False,
94
+ reason="could not read one of VERSION / package.json / pyproject.toml",
95
+ remediation="ensure all three files exist at repo root",
96
+ )
97
+ v, pkg_v, py_v = versions
98
+ if v and pkg_v == v and py_v == v:
99
+ return CheckResult(
100
+ name="version-alignment", passed=True,
101
+ reason=f"all three at {v}",
102
+ )
103
+ return CheckResult(
104
+ name="version-alignment", passed=False,
105
+ reason=f"mismatch: VERSION={v} package.json={pkg_v} pyproject={py_v}",
106
+ remediation="align all three files to the same version, then re-run",
107
+ )
108
+
109
+
110
+ def check_npm_auth(*, expected_user: str | None = None) -> CheckResult:
111
+ """Verify `npm whoami` returns a valid user (and matches expected, if set)."""
112
+ out = _run(["npm", "whoami"])
113
+ if out is None:
114
+ return CheckResult(
115
+ name="npm-auth", passed=False,
116
+ reason="npm command not found or timed out",
117
+ remediation="install Node.js / npm and retry",
118
+ )
119
+ if out.returncode != 0:
120
+ return CheckResult(
121
+ name="npm-auth", passed=False,
122
+ reason=f"npm whoami failed: {out.stderr.strip() or 'unknown'}",
123
+ remediation="run `npm login` or rotate token in ~/.npmrc",
124
+ )
125
+ user = out.stdout.strip()
126
+ if expected_user and user != expected_user:
127
+ return CheckResult(
128
+ name="npm-auth", passed=False,
129
+ reason=f"npm authenticated as {user}, expected {expected_user}",
130
+ remediation=f"switch token to {expected_user} or update expected user",
131
+ )
132
+ return CheckResult(
133
+ name="npm-auth", passed=True,
134
+ reason=f"authenticated as {user}",
135
+ )
136
+
137
+
138
+ def check_npm_publish_capability() -> CheckResult:
139
+ """Verify `npm pack --dry-run` succeeds — proves write scope on the package."""
140
+ out = _run(["npm", "pack", "--dry-run"])
141
+ if out is None or out.returncode != 0:
142
+ msg = (out.stderr.strip() if out else "command unavailable") or "unknown"
143
+ return CheckResult(
144
+ name="npm-publish-capability", passed=False,
145
+ reason=f"pack dry-run failed: {msg}",
146
+ remediation="check granular token has 'read and write' on this package",
147
+ )
148
+ return CheckResult(
149
+ name="npm-publish-capability", passed=True,
150
+ reason="pack dry-run OK",
151
+ )
152
+
153
+
154
+ def check_gh_auth() -> CheckResult:
155
+ """Verify `gh auth status` reports a logged-in session."""
156
+ out = _run(["gh", "auth", "status"])
157
+ if out is None:
158
+ return CheckResult(
159
+ name="gh-auth", passed=False,
160
+ reason="gh command not found or timed out",
161
+ remediation="install the GitHub CLI and run `gh auth login`",
162
+ )
163
+ if out.returncode != 0:
164
+ return CheckResult(
165
+ name="gh-auth", passed=False,
166
+ reason="gh not authenticated",
167
+ remediation="run `gh auth login`",
168
+ )
169
+ return CheckResult(name="gh-auth", passed=True, reason="authenticated")
170
+
171
+
172
+ def check_git_remote() -> CheckResult:
173
+ """Verify `git remote get-url origin` returns a real remote URL."""
174
+ out = _run(["git", "remote", "get-url", "origin"])
175
+ if out is None or out.returncode != 0:
176
+ return CheckResult(
177
+ name="git-remote", passed=False,
178
+ reason="no `origin` remote configured",
179
+ remediation="set up the remote with `git remote add origin <url>`",
180
+ )
181
+ return CheckResult(
182
+ name="git-remote", passed=True,
183
+ reason=out.stdout.strip(),
184
+ )
185
+
186
+
187
+ def check_git_clean() -> CheckResult:
188
+ """Flag uncommitted changes as a WARNING (not blocking)."""
189
+ out = _run(["git", "status", "--porcelain"])
190
+ if out is None:
191
+ return CheckResult(
192
+ name="git-clean", passed=False, severity="warning",
193
+ reason="git not available",
194
+ )
195
+ dirty = out.stdout.strip()
196
+ if not dirty:
197
+ return CheckResult(name="git-clean", passed=True, reason="working tree clean")
198
+ file_count = len([line for line in dirty.splitlines() if line.strip()])
199
+ return CheckResult(
200
+ name="git-clean", passed=False, severity="warning",
201
+ reason=f"{file_count} uncommitted file(s)",
202
+ remediation="commit, stash, or proceed deliberately",
203
+ )
204
+
205
+
206
+ def _run(cmd: list[str]) -> subprocess.CompletedProcess | None:
207
+ """subprocess.run with our defaults; returns None on missing exe / timeout."""
208
+ try:
209
+ return subprocess.run(
210
+ cmd, capture_output=True, text=True,
211
+ timeout=_SUBPROCESS_TIMEOUT, check=False,
212
+ )
213
+ except (FileNotFoundError, subprocess.TimeoutExpired):
214
+ return None
215
+
216
+
217
+ def _aggregate(results: list[CheckResult]) -> PreflightReport:
218
+ blocking = [r for r in results if not r.passed and r.severity == "blocking"]
219
+ warnings = [r for r in results if not r.passed and r.severity == "warning"]
220
+ return PreflightReport(
221
+ all_passed=not blocking,
222
+ results=results,
223
+ blocking_failures=blocking,
224
+ warnings=warnings,
225
+ )
@@ -0,0 +1,74 @@
1
+ """CLI entry for the release preflight gate (PR21 v2.43.0).
2
+
3
+ Usage:
4
+ python -m core.release.preflight_cli [--expected-npm-user USER]
5
+
6
+ Exit code: 0 if all blocking checks pass, 1 otherwise. Warnings never
7
+ gate the exit code. Output is markdown so it renders cleanly in both
8
+ terminal and PR comments.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import argparse
14
+ import sys
15
+ from datetime import datetime, timezone
16
+
17
+ from core.release.preflight import (
18
+ CheckResult,
19
+ PreflightReport,
20
+ run_preflight,
21
+ )
22
+
23
+
24
+ def _glyph(result: CheckResult) -> str:
25
+ if result.passed:
26
+ return "PASS"
27
+ if result.severity == "warning":
28
+ return "WARN"
29
+ return "FAIL"
30
+
31
+
32
+ def _render(report: PreflightReport) -> str:
33
+ today = datetime.now(timezone.utc).strftime("%Y-%m-%d")
34
+ lines = [
35
+ f"# Release Preflight — {today}",
36
+ "",
37
+ "| Check | Status | Notes |",
38
+ "|---|---|---|",
39
+ ]
40
+ for r in report.results:
41
+ notes = r.reason or ""
42
+ if r.remediation and not r.passed:
43
+ notes = f"{notes} | remediation: {r.remediation}"
44
+ lines.append(f"| {r.name} | {_glyph(r)} | {notes} |")
45
+ lines.append("")
46
+ if report.blocking_failures:
47
+ lines.append(f"**BLOCKED — {len(report.blocking_failures)} failure(s).** "
48
+ "Fix each remediation and rerun before tagging/publishing.")
49
+ elif report.warnings:
50
+ lines.append(f"All blocking checks passed ({len(report.warnings)} "
51
+ "warning(s) noted, non-blocking).")
52
+ else:
53
+ lines.append("All checks green. Safe to proceed to tag → release → publish.")
54
+ return "\n".join(lines)
55
+
56
+
57
+ def main(argv: list[str]) -> int:
58
+ parser = argparse.ArgumentParser(
59
+ prog="arkaos-preflight",
60
+ description="Run release preflight checks. Exit 1 on any blocking failure.",
61
+ )
62
+ parser.add_argument(
63
+ "--expected-npm-user", default=None,
64
+ help="Assert that `npm whoami` returns this user (e.g. wizardingcode).",
65
+ )
66
+ args = parser.parse_args(argv[1:])
67
+
68
+ report = run_preflight(expected_npm_user=args.expected_npm_user)
69
+ print(_render(report))
70
+ return 0 if report.all_passed else 1
71
+
72
+
73
+ if __name__ == "__main__":
74
+ raise SystemExit(main(sys.argv))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkaos",
3
- "version": "2.42.0",
3
+ "version": "2.43.0",
4
4
  "description": "The Operating System for AI Agent Teams",
5
5
  "type": "module",
6
6
  "bin": {
package/pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "arkaos-core"
3
- version = "2.42.0"
3
+ version = "2.43.0"
4
4
  description = "Core engine for ArkaOS — The Operating System for AI Agent Teams"
5
5
  readme = "README.md"
6
6
  license = {text = "MIT"}