Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changes/3209.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: added

On synthetic fixtures, `install download --early` adds an opt-in `early` channel that authenticates through `gh` for `openwizpro/WizPro` prereleases and follows the newest early or public release by semver.
9 changes: 9 additions & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ The agent runs each command itself and reads its JSON. `<root>` is the install f

Then it proves the build: `<root>/current/openwiz --build-identity` prints the version (`0.1.1`) and the source commit. The `openwiz` program lives there, not on your `PATH`: typing `openwiz` alone says "command not found".

**Early builds (OpenWiz Pro, opt-in):** with no extra flag, `install download` reads only public releases from `openwizdev/OpenWiz` and installs on the `packaged` channel. OpenWiz Pro members can opt into the `early` channel by passing `--early` to `install download`:

```sh
python3 -I "$openwiz"/tools/install/install download --early --target <target> --dir <new private folder>
python3 -I "$openwiz"/tools/install/install install --assets <that folder> --target <target> --root <root>
```

`download --early` uses your existing `gh` login (without storing or logging any token) to check prereleases tagged `v<version>-rc.<n>` in the private `openwizpro/WizPro` repository alongside public releases, picks whichever is newer by semver, and verifies `SHA256SUMS`, the manifest and the archive the same way. Installing writes `{"schema":"openwiz.update-channel.v1","channel":"early"}` to `<root>/channel.json`, and later updates follow the newest early or public release by semver so you are never left behind a public release. If `gh` is missing or not logged in, it refuses and tells you to run `gh auth login`; if your account does not have access to `openwizpro/WizPro` (HTTP 404), it refuses and links to [openwiz.dev/pro](https://openwiz.dev/pro/). `install remove` removes an `early` `channel.json` the same as `packaged`.

3. **Setup and logins.** Nothing opens in a browser by itself: the agent reads each connection with one check, run from the installed build, and reruns it after each change.

```sh
Expand Down
94 changes: 68 additions & 26 deletions tools/install/install
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ DESCRIPTION = """OpenWiz's install entry (#1109): the commands the install skill
Reads this machine only: Python, the supported target, free disk space,
on Linux the glibc version (from ldd --version; 2.34 or later), and
whether room-cli, gh and git are on PATH. It runs none of those three.
install download --target TARGET --dir PRIVATE_DIR [--version vX.Y.Z]
install download --target TARGET --dir PRIVATE_DIR [--version vX.Y.Z] [--early]
Fetches a release's checksum file, manifest and archive from
github.com/openwizdev/OpenWiz/releases into a new private folder, within
their declared sizes, and checks the manifest against the checksum.
Without --version it takes the latest release; when latest is a 404 (the
newest release is a pre-release), the newest tag in the releases feed.
With --early it also checks prereleases tagged v<version>-rc.<n> from
openwizpro/WizPro through gh and picks whichever is newer by semver.
A refusal names the failure, such as "release asset 404 at URL".
install install --assets PRIVATE_DIR --target TARGET --root ROOT [--state-root STATE]
install install --assets PRIVATE_DIR --target TARGET --root ROOT [--state-root STATE] [--early]
Installs those downloaded files with the verified offline installer
(install.py, contracts/install.v1.md) and selects the build only when
every file matched. A refusal keeps the last good build selected. A
Expand Down Expand Up @@ -83,6 +85,7 @@ TOOLS = (('room-cli', 'Optional: CloudRoom is needed only if you pick it as the
('gh', 'Install the GitHub CLI and run gh auth login.'),
('git', 'Install git.'))
ARCHIVE_NAME = re.compile(r'openwiz-0\.[0-9]+\.[0-9]+-[a-z0-9_]+-[a-z0-9_-]+\.tar\.gz')
EARLY_ARCHIVE_NAME = re.compile(r'openwiz-0\.[0-9]+\.[0-9]+(?:-rc\.[0-9]+)?-[a-z0-9_]+-[a-z0-9_-]+\.tar\.gz')


class Usage(Exception):
Expand Down Expand Up @@ -159,16 +162,27 @@ def write_private(path, data):
handle.write(data)


def download(target, folder, fetch, version=None):
def download(target, folder, fetch, version=None, early=False, which=shutil.which):
name = 'openwiz-' + target
sums, raw, manifest, _ = pull.published(target, fetch, version)
installer.require(ARCHIVE_NAME.fullmatch(manifest['archive']), 'invalid published archive name')
prefix = pull.BASE + 'download/v' + manifest['version'] + '/'
archive = fetch(prefix + manifest['archive'], manifest['archive_bytes'])
if early:
found, origin, asset_fetch = pull.published_early(target, fetch=fetch, version=version, which=which)
sums, raw, manifest, _ = found
installer.require(EARLY_ARCHIVE_NAME.fullmatch(manifest['archive']), 'invalid published archive name')
prefix = '' if origin == 'early' else pull.BASE + 'download/v' + manifest['version'] + '/'
location = (pull.PRO_REPO + '/v' + manifest['version'] + '/' + manifest['archive']
if origin == 'early' else prefix + manifest['archive'])
else:
origin = 'public'
asset_fetch = fetch
sums, raw, manifest, _ = pull.published(target, fetch, version)
installer.require(ARCHIVE_NAME.fullmatch(manifest['archive']), 'invalid published archive name')
prefix = pull.BASE + 'download/v' + manifest['version'] + '/'
location = prefix + manifest['archive']
archive = asset_fetch(prefix + manifest['archive'], manifest['archive_bytes'])
installer.require(len(archive) == manifest['archive_bytes'], 'incomplete archive download')
installer.require(installer.sha(archive) == manifest['archive_sha256'], 'archive checksum mismatch at '
+ prefix + manifest['archive'])
listed = release_sums(fetch(prefix + 'SHA256SUMS', 64 * 1024))
+ location)
listed = release_sums(asset_fetch(prefix + 'SHA256SUMS', 64 * 1024))
for file, data in (('openwiz-%s-%s.manifest.json' % (manifest['version'], target), raw),
(manifest['archive'], archive)):
installer.require(file in listed, 'SHA256SUMS does not list ' + file)
Expand All @@ -177,9 +191,15 @@ def download(target, folder, fetch, version=None):
write_private(folder / (name + '.sha256'), sums)
write_private(folder / (name + '.manifest.json'), raw)
write_private(folder / manifest['archive'], archive)
return {'schema': 'openwiz.download.v1', 'outcome': 'downloaded', 'version': manifest['version'],
'source': manifest['source'], 'target': target, 'dir': str(folder),
'reason': 'Downloaded and checked every file against its published checksums; nothing is installed yet.'}
if early:
write_private(folder / 'channel.json', installer.CHANNELS['early'])
result = {'schema': 'openwiz.download.v1', 'outcome': 'downloaded', 'version': manifest['version'],
'source': manifest['source'], 'target': target, 'dir': str(folder),
'reason': 'Downloaded and checked every file against its published checksums; nothing is installed yet.'}
if early:
result['channel'] = 'early'
result['origin'] = origin
return result


def release_sums(data):
Expand All @@ -191,10 +211,12 @@ def release_sums(data):
return listed


def release_version(value):
match = re.fullmatch(r'v?(0\.[0-9]+\.[0-9]+)', value)
def release_version(value, early=False):
pattern = r'v?(0\.[0-9]+\.[0-9]+(?:-rc\.[0-9]+)?)' if early else r'v?(0\.[0-9]+\.[0-9]+)'
match = re.fullmatch(pattern, value)
if not match:
raise argparse.ArgumentTypeError('expected a release tag such as v0.1.0')
raise Usage('argument --version: expected a release tag such as '
+ ('v0.1.0-rc.1' if early else 'v0.1.0'))
return match[1]


Expand Down Expand Up @@ -223,20 +245,31 @@ def prepare_parent(root):
'an install parent folder is a link or not yours')


def install(assets, target, root, state_root):
def install(assets, target, root, state_root, early=False):
assets = Path(assets)
installer.require(target in installer.TARGETS, 'unsupported package target')
name = 'openwiz-' + target
installer.private(assets)
channel_file = assets / 'channel.json'
if channel_file.exists() or channel_file.is_symlink():
installer.private(channel_file, False)
raw_channel = channel_file.read_bytes()
installer.require(raw_channel in installer.CHANNELS.values(), 'invalid downloaded channel metadata')
downloaded_channel = 'early' if raw_channel == installer.CHANNELS['early'] else 'packaged'
else:
downloaded_channel = 'packaged'
channel = 'early' if early else downloaded_channel
sums = (assets / (name + '.sha256')).read_bytes()
match = re.fullmatch(rb'([0-9a-f]{64}) ' + re.escape((name + '.manifest.json').encode()) + rb'\n', sums)
installer.require(match, 'invalid published manifest checksum')
manifest_file = assets / (name + '.manifest.json')
manifest = installer.manifest_at(manifest_file, match[1].decode('ascii'), target)[0]
installer.require(ARCHIVE_NAME.fullmatch(manifest['archive']), 'invalid published archive name')
manifest = installer.manifest_at(manifest_file, match[1].decode('ascii'), target,
allow_prerelease=(channel == 'early'))[0]
archive_re = EARLY_ARCHIVE_NAME if channel == 'early' else ARCHIVE_NAME
installer.require(archive_re.fullmatch(manifest['archive']), 'invalid published archive name')
prepare_parent(root)
result = installer.install(manifest_file, assets / manifest['archive'], match[1].decode('ascii'),
Path(root), target, state_root=state_root)
Path(root), target, state_root=state_root, channel=channel)
program, path, state = link_state(root)
where = 'openwiz is at %s' % program
return dict(result, outcome='installed', openwiz=str(program), next=(
Expand Down Expand Up @@ -306,9 +339,14 @@ def selected(root, state_root=None):
installer.require(value['source'] == build.name, 'the selected build is not its own source')
installer.verify_installed(build, assets, raw)
channel = root / 'channel.json'
known = (channel.exists() and not channel.is_symlink()
and channel.read_bytes() == b'{"schema":"openwiz.update-channel.v1","channel":"packaged"}\n')
return build, state, value, ('packaged' if known else 'unknown')
channel_name = 'unknown'
if channel.exists() and not channel.is_symlink():
raw_channel = channel.read_bytes()
for cname, expected in installer.CHANNELS.items():
if raw_channel == expected:
channel_name = cname
break
return build, state, value, channel_name


def status(root, state_root):
Expand Down Expand Up @@ -409,7 +447,7 @@ def remove_unlocked(root, state, state_root, yes, home, codex_home, made=None):
delete = [path for path, kind in ((link, stat.S_ISLNK), (root / 'install.lock', stat.S_ISREG))
if owned(path, kind)]
channel = root / 'channel.json'
if owned(channel, stat.S_ISREG) and channel.read_bytes() == CHANNEL:
if owned(channel, stat.S_ISREG) and channel.read_bytes() in installer.CHANNELS.values():
delete.append(channel)
delete += [root / 'skills' / name for name in marked_skills(root / 'skills')]
delete += [builds / name for name in installer.entries(builds) if verified_build(builds / name)]
Expand Down Expand Up @@ -460,12 +498,14 @@ def main(argv=None, fetch=pull.fetch_bytes, host=None, stdout=None):
d = commands.add_parser('download')
d.add_argument('--target', required=True)
d.add_argument('--dir', required=True)
d.add_argument('--version', type=release_version)
d.add_argument('--version')
d.add_argument('--early', action='store_true')
i = commands.add_parser('install')
i.add_argument('--assets', required=True)
i.add_argument('--target', required=True)
i.add_argument('--root', required=True)
i.add_argument('--state-root')
i.add_argument('--early', action='store_true')
n = commands.add_parser('link')
n.add_argument('--root', required=True)
n.add_argument('--state-root')
Expand All @@ -482,6 +522,8 @@ def main(argv=None, fetch=pull.fetch_bytes, host=None, stdout=None):
k.add_argument('--state-root')
try:
args = parser.parse_args(sys.argv[1:] if argv is None else argv)
if args.command == 'download' and args.version is not None:
args.version = release_version(args.version, early=args.early)
except Usage as usage:
print(json.dumps({'schema': 'openwiz.install-error.v1', 'outcome': 'usage', 'reason': str(usage)}), file=out)
return 2
Expand All @@ -494,9 +536,9 @@ def main(argv=None, fetch=pull.fetch_bytes, host=None, stdout=None):
return None
value, code = preflight(host or (platform.system(), platform.machine()), shutil.which, disk)
elif args.command == 'download':
value, code = download(args.target, args.dir, fetch, args.version), 0
value, code = download(args.target, args.dir, fetch, args.version, early=args.early), 0
elif args.command == 'install':
value, code = install(args.assets, args.target, args.root, args.state_root), 0
value, code = install(args.assets, args.target, args.root, args.state_root, early=args.early), 0
elif args.command == 'skills':
build, _, manifest, _ = selected(args.root, args.state_root)
value, code = harness.install_skills(build, manifest, args.root, Path.home(),
Expand Down
34 changes: 22 additions & 12 deletions tools/install/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"""

TARGETS = ('aarch64-apple-darwin', 'x86_64-apple-darwin', 'x86_64-unknown-linux-gnu')
VERSION_RE = re.compile(r'0\.[0-9]+\.[0-9]+')
EARLY_VERSION_RE = re.compile(r'0\.[0-9]+\.[0-9]+(?:-rc\.[0-9]+)?')
CHANNELS = {
'packaged': b'{"schema":"openwiz.update-channel.v1","channel":"packaged"}\n',
'early': b'{"schema":"openwiz.update-channel.v1","channel":"early"}\n',
}
PROGRAMS = {'openwiz'}
REQUIRED = PROGRAMS | {'runtime/openwiz-build.txt', 'runtime/install.py', 'runtime/pull.py',
'runtime/skills/setup/SKILL.md', 'runtime/skills/grill/SKILL.md',
Expand Down Expand Up @@ -77,13 +83,14 @@ def safe(path, legacy=False):
return path


def manifest_at(path, checksum, target, selected=False):
def manifest_at(path, checksum, target, selected=False, allow_prerelease=False):
data = path.read_bytes()
require(len(data) <= 4 * 1024 * 1024 and sha(data) == checksum, 'manifest checksum mismatch')
value = json.loads(data, object_pairs_hook=unique)
shape(value, 'schema version source target setup_api archive archive_sha256 archive_bytes assets')
require(value['schema'] == 'openwiz.install.v1', 'unsupported manifest schema')
require(isinstance(value['version'], str) and re.fullmatch(r'0\.[0-9]+\.[0-9]+', value['version']), 'invalid version')
version_re = EARLY_VERSION_RE if (allow_prerelease or selected) else VERSION_RE
require(isinstance(value['version'], str) and version_re.fullmatch(value['version']), 'invalid version')
require(digest(value['source'], 40), 'invalid source identity')
require(target in TARGETS and value['target'] == target, 'unsupported or mismatched target')
require(type(value['setup_api']) is int and value['setup_api'] == 1, 'incompatible setup API')
Expand Down Expand Up @@ -258,9 +265,11 @@ def activate_link(build, root):


def install(manifest, archive, manifest_sha256, root, target, state_root=None,
free_bytes=lambda path: shutil.disk_usage(path).free, activate=activate_link, stage_only=False):
free_bytes=lambda path: shutil.disk_usage(path).free, activate=activate_link, stage_only=False,
channel='packaged'):
require(channel in CHANNELS, 'unsupported update channel')
manifest, archive, root = Path(manifest), Path(archive), Path(root)
value, assets, raw = manifest_at(manifest, manifest_sha256, target)
value, assets, raw = manifest_at(manifest, manifest_sha256, target, allow_prerelease=(channel == 'early'))
require(archive.stat().st_size == value['archive_bytes'], 'archive size mismatch')
hasher = hashlib.sha256()
with archive.open('rb') as stream:
Expand Down Expand Up @@ -291,12 +300,12 @@ def install(manifest, archive, manifest_sha256, root, target, state_root=None,
require(selected.is_absolute() and selected.parent == builds and digest(selected.name, 40), 'foreign current selection')
if selected != builds / value['source']:
private(selected)
channel = root / 'channel.json'
require(channel.exists() or not link.is_symlink(), 'source installation requires an explicit channel migration')
channel_bytes = b'{"schema":"openwiz.update-channel.v1","channel":"packaged"}\n'
if channel.exists() or channel.is_symlink():
private(channel, False)
require(channel.read_bytes() == channel_bytes, 'existing update channel requires explicit migration')
channel_file = root / 'channel.json'
require(channel_file.exists() or not link.is_symlink(), 'source installation requires an explicit channel migration')
channel_bytes = CHANNELS[channel]
if channel_file.exists() or channel_file.is_symlink():
private(channel_file, False)
require(channel_file.read_bytes() == channel_bytes, 'existing update channel requires explicit migration')
build = builds / value['source']
with tarfile.open(archive, 'r:gz') as tar:
members = []
Expand Down Expand Up @@ -363,8 +372,8 @@ def install(manifest, archive, manifest_sha256, root, target, state_root=None,
os.chmod(build, stat.S_IMODE(damaged_meta.st_mode))
raise
if not stage_only:
if not channel.exists():
write(channel, channel_bytes)
if not channel_file.exists():
write(channel_file, channel_bytes)
sync(root)
activate(build, root)
return {'schema': 'openwiz.install-result.v1', 'version': value['version'], 'source': value['source'],
Expand All @@ -378,6 +387,7 @@ def main():
parser.add_argument('--' + flag, required=True)
parser.add_argument('--state-root')
parser.add_argument('--stage-only', action='store_true')
parser.add_argument('--channel', choices=tuple(CHANNELS), default='packaged')
args = vars(parser.parse_args())
try:
result = install(**args)
Expand Down
Loading
Loading