Skip to content

Self-improving AI Employees for everyone

feat(cli): make version sync write every version file; bring the stale ones to 0.1.1

trohitg22d0a3171a42
diff --git a/cli/__init__.py b/cli/__init__.py
index 4e9fa9f5..aa649e63 100644
--- a/cli/__init__.py
+++ b/cli/__init__.py
@@ -1,3 +1,3 @@
"""OpenCompany project supervisor CLI."""
-__version__ = "0.1.0"
+__version__ = "0.1.1"
diff --git a/cli/cli.py b/cli/cli.py
index b3c43a10..a7303832 100644
--- a/cli/cli.py
+++ b/cli/cli.py
@@ -288,7 +288,7 @@ version_app = typer.Typer(
@version_app.command(
"sync",
- help="Sync package.json versions from latest git tag.",
+ help="Sync every version file from a git tag (default: the latest).",
)
def _version_sync(
tag: str | None = typer.Argument(
diff --git a/cli/commands/version.py b/cli/commands/version.py
index a3acd31f..7ca671a2 100644
--- a/cli/commands/version.py
+++ b/cli/commands/version.py
@@ -1,8 +1,26 @@
"""``company version sync`` -- replaces ``scripts/sync-version.js``.
-Reads the latest git tag (or one supplied on the command line), strips
-the ``v`` prefix, and writes the resulting semver into both
-``package.json`` files (root + client).
+Reads the latest git tag (or one supplied on the command line), strips the
+``v`` prefix, and writes the resulting semver into every file that carries
+the package version -- see ``targets()``:
+
+- ``package.json``: the single source of truth at runtime. The backend's
+ ``/health`` and OpenAPI document, the client's persisted-query buster and
+ workflow-export stamp, and ``company --version`` all read it.
+- ``client/package.json``: workspace member.
+- ``desktop/package.json``: electron-builder artifact names and the
+ electron-updater feed. CI copies the root version into it as well
+ (``bun run sync-version``), but the tag-triggered desktop build ships
+ whatever the release commit left here and refuses to build when that
+ differs from the tag, so the commit must carry it.
+- ``pyproject.toml``: the ``opencompany-cli`` Python package.
+- ``cli/__init__.py``: ``__version__``.
+
+``server/pyproject.toml`` is deliberately left alone: ``server/uv.lock``
+records that project's version, so a bump fails ``uv lock --check`` until
+the lock is regenerated and changes the desktop provisioning stamp on every
+release, for a version nothing reads (the server is a virtual project, never
+installed as a package).
"""
from __future__ import annotations
@@ -10,6 +28,7 @@ from __future__ import annotations
import json
import re
from pathlib import Path
+from typing import Callable
import typer
@@ -27,6 +46,12 @@ app = typer.Typer(
_VALID_VERSION = re.compile(r"^\d+\.\d+\.\d+")
+# First `version = "..."` assignment in a pyproject: the [project] table
+# leads the file, so tool tables further down are never touched.
+_PYPROJECT_VERSION = re.compile(r'^(version\s*=\s*")([^"]*)(")', re.MULTILINE)
+_DUNDER_VERSION = re.compile(r'^(__version__\s*=\s*")([^"]*)(")', re.MULTILINE)
+
+Writer = Callable[[Path, str], bool]
def _git_describe(root: Path) -> str | None:
@@ -59,7 +84,44 @@ def _update_package_json(path: Path, new_version: str) -> bool:
return True
[email protected]("sync", help="Sync package.json versions from latest git tag.")
+def _update_assignment(path: Path, pattern: re.Pattern[str], new_version: str) -> bool:
+ """Rewrite the value of a ``version = "..."``-style assignment in place."""
+ text = path.read_text(encoding="utf-8")
+ match = pattern.search(text)
+ if match is None:
+ raise ValueError(f"no version assignment found in {path}")
+ old = match.group(2)
+ if old == new_version:
+ console.print(f" {path}: already at {new_version}")
+ return False
+ path.write_text(
+ text[: match.start(2)] + new_version + text[match.end(2) :],
+ encoding="utf-8",
+ )
+ console.print(f" {path}: {old} -> {new_version}")
+ return True
+
+
+def _update_pyproject(path: Path, new_version: str) -> bool:
+ return _update_assignment(path, _PYPROJECT_VERSION, new_version)
+
+
+def _update_python_dunder(path: Path, new_version: str) -> bool:
+ return _update_assignment(path, _DUNDER_VERSION, new_version)
+
+
+def targets(root: Path) -> list[tuple[Path, Writer]]:
+ """Every file ``sync`` writes, paired with the writer for its format."""
+ return [
+ (root / "package.json", _update_package_json),
+ (root / "client" / "package.json", _update_package_json),
+ (root / "desktop" / "package.json", _update_package_json),
+ (root / "pyproject.toml", _update_pyproject),
+ (root / "cli" / "__init__.py", _update_python_dunder),
+ ]
+
+
[email protected]("sync", help="Sync every version file from a git tag (default: the latest).")
def sync(
tag: str | None = typer.Argument(None, help="Git tag to use (defaults to latest)."),
) -> None:
@@ -80,15 +142,15 @@ def sync(
console.print(f"Syncing version from tag: {resolved_tag} -> {version}\n")
updated = 0
- for pkg_path in (root / "package.json", root / "client" / "package.json"):
+ for path, write in targets(root):
try:
- if _update_package_json(pkg_path, version):
+ if write(path, version):
updated += 1
- except (OSError, json.JSONDecodeError) as exc:
- console.print(f"[red] Error updating {pkg_path}: {exc}[/]")
+ except (OSError, json.JSONDecodeError, ValueError) as exc:
+ console.print(f"[red] Error updating {path}: {exc}[/]")
console.print()
if updated:
console.print(f"Updated {updated} file(s). Don't forget to commit the changes.")
else:
- console.print("All package.json files already at correct version.")
+ console.print("All version files already at the correct version.")
diff --git a/cli/tests/test_version.py b/cli/tests/test_version.py
index d3e41c50..ce68d341 100644
--- a/cli/tests/test_version.py
+++ b/cli/tests/test_version.py
@@ -1,4 +1,4 @@
-"""Smoke tests for ``cli.commands.version``."""
+"""Tests for ``cli.commands.version``."""
from __future__ import annotations
@@ -6,6 +6,7 @@ import json
from pathlib import Path
from unittest.mock import patch
+import pytest
from cli.commands import version
@@ -39,3 +40,67 @@ def test_update_package_json_preserves_trailing_newline(tmp_path: Path):
def test_git_describe_returns_none_without_git():
with patch.object(version, "capture", return_value=None):
assert version._git_describe(Path(".")) is None
+
+
+def test_update_pyproject_rewrites_only_the_project_version(tmp_path: Path):
+ py = tmp_path / "pyproject.toml"
+ py.write_text(
+ '[project]\nname = "x"\nversion = "0.1.0"\n\n[tool.other]\nversion = "9.9.9"\n',
+ encoding="utf-8",
+ )
+ assert version._update_pyproject(py, "0.2.0") is True
+ text = py.read_text(encoding="utf-8")
+ assert text.startswith('[project]\nname = "x"\nversion = "0.2.0"\n')
+ assert 'version = "9.9.9"' in text
+
+
+def test_update_pyproject_no_op_when_already_correct(tmp_path: Path):
+ py = tmp_path / "pyproject.toml"
+ py.write_text('[project]\nversion = "1.0.0"\n', encoding="utf-8")
+ assert version._update_pyproject(py, "1.0.0") is False
+
+
+def test_update_python_dunder_rewrites_the_assignment(tmp_path: Path):
+ init = tmp_path / "__init__.py"
+ init.write_text('"""Doc."""\n\n__version__ = "0.1.0"\n', encoding="utf-8")
+ assert version._update_python_dunder(init, "0.2.0") is True
+ assert init.read_text(encoding="utf-8") == '"""Doc."""\n\n__version__ = "0.2.0"\n'
+
+
+def test_assignment_writer_refuses_a_file_without_a_version(tmp_path: Path):
+ py = tmp_path / "pyproject.toml"
+ py.write_text('[project]\nname = "x"\n', encoding="utf-8")
+ with pytest.raises(ValueError):
+ version._update_pyproject(py, "0.2.0")
+
+
+def test_targets_cover_every_version_file_but_the_server_pyproject(tmp_path: Path):
+ """``server/pyproject.toml`` is recorded in ``server/uv.lock``: bumping it
+ would fail ``uv lock --check`` and re-provision every desktop install for
+ a version nothing reads."""
+ relative = {
+ path.relative_to(tmp_path).as_posix() for path, _ in version.targets(tmp_path)
+ }
+ assert relative == {
+ "package.json",
+ "client/package.json",
+ "desktop/package.json",
+ "pyproject.toml",
+ "cli/__init__.py",
+ }
+
+
+def test_checked_in_version_files_agree(root: Path):
+ """A release commit must bump every file ``sync`` writes: the desktop
+ build ships the committed desktop version, so one straggler ships the
+ previous release's number."""
+ seen: dict[str, str] = {}
+ for path, writer in version.targets(root):
+ text = path.read_text(encoding="utf-8")
+ if writer is version._update_package_json:
+ seen[path.name] = json.loads(text)["version"]
+ elif writer is version._update_pyproject:
+ seen[path.name] = version._PYPROJECT_VERSION.search(text).group(2)
+ else:
+ seen[path.name] = version._DUNDER_VERSION.search(text).group(2)
+ assert len(set(seen.values())) == 1, seen
diff --git a/docs-internal/SCRIPTS.md b/docs-internal/SCRIPTS.md
index b172866e..b4690915 100644
--- a/docs-internal/SCRIPTS.md
+++ b/docs-internal/SCRIPTS.md
@@ -38,7 +38,7 @@ deprecation warning; kept for upgrade compatibility).
| `company clean` | Stop services, then remove build artifacts, node_modules, `.venv`, repo-local state (preserves `.opencompany/{workflows,deploy,packages}`) |
| `company deploy up/status/destroy` | Self-deploy a login-gated VM (gcloud preflight + Terraform; see `cli/commands/deploy/`) |
| `company daemon start/stop/status/restart` | Detached backend management (PID file under user data dir) |
-| `company version sync [tag]` | Write the latest git tag's version into the package.json files (defaults to the latest tag) |
+| `company version sync [tag]` | Write a git tag's version (default: the latest) into every version file: root / client / desktop `package.json`, `pyproject.toml`, `cli/__init__.py`. Never `server/pyproject.toml`, which `server/uv.lock` records. The release procedure is in [ci_cd.md -> Cutting a release](./ci_cd.md#cutting-a-release) |
| `company docs nodes [--check]` | Regenerate (or verify) the `docs-internal/node-logic-flows/` index |
There is no `help` verb: `company` with no arguments, `company --help`, and
diff --git a/pyproject.toml b/pyproject.toml
index 79044d28..622a79f8 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[project]
name = "opencompany-cli"
-version = "0.1.0"
+version = "0.1.1"
description = "OpenCompany project supervisor CLI (company)."
requires-python = ">=3.12"
dependencies = [
diff --git a/server/main.py b/server/main.py
index 505379bb..94cb7c1b 100644
--- a/server/main.py
+++ b/server/main.py
@@ -516,7 +516,7 @@ _expose_docs = (
# Create FastAPI app
app = FastAPI(
title="OpenCompany API",
- version="3.0.0",
+ # version: set from package.json below, once _app_version() exists.
description="OpenCompany workflow automation backend",
lifespan=lifespan,
docs_url="/docs" if _expose_docs else None,
@@ -667,6 +667,11 @@ def _app_version() -> str:
return "0.0.0"
+# The OpenAPI document (/docs, /openapi.json) carries the package version
+# too; the FastAPI constructor runs before this helper exists.
+app.version = _app_version()
+
+
@app.get("/health")
async def health_check():
"""Detailed health check with resource monitoring."""