Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Harness OS: the CLI built into the OS carries the newest published CLI it contains (#1519)

Bubu-Dudu-52hz68d964580243
diff --git a/os/tests/build-update-fixture.py b/os/tests/build-update-fixture.py
index bbcd7b0ac..04eb0f5b0 100644
--- a/os/tests/build-update-fixture.py
+++ b/os/tests/build-update-fixture.py
@@ -136,8 +136,9 @@ def main(argv=None):
parser.error('Node must match the native Linux build architecture.')
started = time.time()
commit = clean_source(ROOT)
+ # As build-runtime.sh names them: the CLI as the newest published one this source contains.
versions = {'hn': tomllib.loads((ROOT / 'tui/Cargo.toml').read_text())['package']['version'],
- 'cli': json.loads((ROOT / 'cli/package.json').read_text())['version']}
+ 'cli': command(sys.executable, ROOT / 'os/tools/runtime-baseline.py', '--cli-version')}
baselines = json.loads(command(sys.executable, ROOT / 'os/tools/runtime-baseline.py'))
baseline = baselines.get('cli', {}).get('version')
if not isinstance(baseline, str) or not re.fullmatch(r'\d+\.\d+\.\d+', baseline):
diff --git a/os/tests/test_runtime_baseline.py b/os/tests/test_runtime_baseline.py
index 79ec5c482..be7d0520c 100644
--- a/os/tests/test_runtime_baseline.py
+++ b/os/tests/test_runtime_baseline.py
@@ -35,7 +35,19 @@ class RuntimeBaseline(unittest.TestCase):
'cli': {'version': '0.3.57', 'commit': published},
'hn': {'version': '0.1.12', 'commit': published},
})
+ # The CLI built for the OS calls itself the newest published one it contains.
+ self.assertEqual(baseline.cli_version(root), '0.3.57')
# An incomplete checkout must fail instead of silently allowing a downgrade.
(root / '.git/shallow').write_text(git('rev-parse', 'HEAD') + '\n')
with self.assertRaisesRegex(ValueError, 'full Git history'):
baseline.baselines(root)
+
+ def test_with_no_published_cli_the_development_version(self):
+ with tempfile.TemporaryDirectory() as temporary:
+ root = Path(temporary)
+ subprocess.run(['git', '-C', str(root), 'init', '-b', 'main'], check=True, capture_output=True)
+ subprocess.run(['git', '-C', str(root), '-c', 'user.name=Fixture', '-c', '[email protected]',
+ 'commit', '--allow-empty', '-m', 'first'], check=True, capture_output=True)
+ (root / 'cli').mkdir()
+ (root / 'cli/package.json').write_text(json.dumps({'version': '0.0.1'}))
+ self.assertEqual(baseline.cli_version(root), '0.0.1')
diff --git a/os/tools/build-runtime.sh b/os/tools/build-runtime.sh
index 4f52e84ba..e10cd89ef 100644
--- a/os/tools/build-runtime.sh
+++ b/os/tools/build-runtime.sh
@@ -14,14 +14,18 @@ runtime_output=${HARNESS_OS_RUNTIME_DIR:-os/work/runtime}
# Check ancestry before the expensive build. A source bundle can contain fixes
# newer than the public CLI even while package.json retains its development version.
python3 os/tools/runtime-baseline.py >/dev/null
+# The CLI calls itself the newest published CLI this source contains, not package.json's
+# development 0.0.1 (runtime-baseline.py cli_version): what the phone, `harness version` and the
+# account show. Updates still take only a CLI newer than that.
+cli_version=$(python3 os/tools/runtime-baseline.py --cli-version)
npm ci --prefix cli --no-audit --no-fund
-(cd cli && node build-bundle.mjs)
+(cd cli && ADAPTER_VERSION="$cli_version" node build-bundle.mjs)
cargo build --manifest-path tui/Cargo.toml --locked --release --target "$runtime_target"
runtime_stage=$(mktemp -d "${TMPDIR:-/tmp}/harness-runtime.XXXXXX")
trap 'rm -rf -- "$runtime_stage"' EXIT
cp "tui/target/$runtime_target/release/harness-tui" "$runtime_stage/"
cp cli/dist/cli.js cli/dist/notify.mjs "$runtime_stage/"
-HARNESS_RUNTIME_STAGE="$runtime_stage" HARNESS_RUNTIME_ARCH="$runtime_arch" python3 - <<'PY'
+HARNESS_RUNTIME_STAGE="$runtime_stage" HARNESS_RUNTIME_ARCH="$runtime_arch" HARNESS_CLI_VERSION="$cli_version" python3 - <<'PY'
import hashlib, json, os, pathlib, subprocess, tomllib
def output(*args):
return subprocess.check_output(args, text=True).strip()
@@ -38,7 +42,7 @@ data = {'source_commit': output('git', 'rev-parse', 'HEAD'),
'architecture': architecture, 'target': architecture + '-unknown-linux-musl'}
assert not data['dirty'], 'Commit source changes before building a traceable runtime'
expected_hn = tomllib.loads(pathlib.Path('tui/Cargo.toml').read_text())['package']['version']
-expected_cli = json.loads(pathlib.Path('cli/package.json').read_text())['version']
+expected_cli = os.environ['HARNESS_CLI_VERSION']
assert output(str(folder / 'harness-tui'), '--version').startswith('hn ' + expected_hn + ' ')
assert output('node', str(folder / 'cli.js'), 'version') == expected_cli
data['versions'] = {'hn': expected_hn, 'cli': expected_cli}
diff --git a/os/tools/runtime-baseline.py b/os/tools/runtime-baseline.py
index 5d33bbbcd..fb55c9b80 100644
--- a/os/tools/runtime-baseline.py
+++ b/os/tools/runtime-baseline.py
@@ -4,6 +4,7 @@ import json
from pathlib import Path
import re
import subprocess
+import sys
def baselines(source):
@@ -25,5 +26,21 @@ def baselines(source):
return result
+def cli_version(source):
+ """What the CLI built from this source calls itself: the newest published CLI it contains.
+
+ package.json keeps a development version (0.0.1) and a release takes its number from its tag,
+ so a CLI built for the OS from the same source said 0.0.1 everywhere — the phone, `harness
+ version`, the account — while it carries every release up to that one. With none published
+ yet (a fork, a test repository), the development version.
+ """
+ published = baselines(source).get('cli', {}).get('version')
+ return published or json.loads((Path(source) / 'cli/package.json').read_text())['version']
+
+
if __name__ == '__main__':
- print(json.dumps(baselines(Path(__file__).resolve().parents[2])))
+ root = Path(__file__).resolve().parents[2]
+ if sys.argv[1:] == ['--cli-version']:
+ print(cli_version(root))
+ else:
+ print(json.dumps(baselines(root)))