Skip to content
Merged
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
9 changes: 5 additions & 4 deletions .agents/skills/mops-cli/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,19 @@ mops toolchain use lintoko 0.11.0 # pin specific version
mops toolchain use pocket-ic 15.0.0 # pin for replica tests / benchmarks / --check-deploy
mops toolchain use wasm-opt 131 # Binaryen for [optimize] (or `latest`)
mops toolchain use mo-fmt 0.5.0 # standalone formatter used by `mops format`
mops toolchain update moc # update to latest (requires existing [toolchain] entry)
mops toolchain update # update all tools to latest
mops toolchain update moc # newest compatible version, same major (requires existing [toolchain] entry)
mops toolchain update # update all tools within their caret range
mops toolchain update moc --major # cross the major version (same as `use moc latest`)
mops toolchain info <tool> # show release info (latest, pinned, history)
mops toolchain info <tool> --versions # list recent releases, newest first
mops toolchain info <tool> --versions # list recent releases, highest version first
mops toolchain info <tool> --versions --all # full release history (cache warming)
mops toolchain info <tool> --versions --prerelease # include prereleases
mops toolchain bin moc # print path to binary
```

**`pocket-ic` versions**: pin anything from `9.0.0` up, `latest` included — mops keeps no list of blessed versions. Pins below `9.0.0` error with a migration message (they ran on the legacy client that mops 3.0.0 removed). With no pin, replica tests / `mops bench` / `--check-deploy` / `mops toolchain bin pocket-ic` error naming `mops toolchain use pocket-ic 15.0.0`. That version is a hint, not a fallback.

**Agent note**: `toolchain use <tool>` without a version opens an interactive picker — do not use in scripts or agents. Always pass a version or `latest`. The picker, `latest`, and `--versions` all default to stable releases; pass `--prerelease` to include prereleases. `toolchain update` only works when the tool already has a `[toolchain]` entry. `toolchain info <tool> --versions` works without `mops.toml` (first GitHub page by default; pass `--all` for full history).
**Agent note**: `toolchain use <tool>` without a version opens an interactive picker — do not use in scripts or agents. Always pass a version or `latest`. The picker, `latest`, and `--versions` all default to stable releases, highest version first (`latest` is the highest version, not the newest publish); pass `--prerelease` to include prereleases. `toolchain update` only works when the tool already has a `[toolchain]` entry, and stays within the caret range of the pin unless you pass `--major`. `toolchain info <tool> --versions` works without `mops.toml` (first GitHub page by default; pass `--all` for full history).

### Enhanced migrations

Expand Down
3 changes: 3 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Mops CLI Changelog

## Next
- **Behaviour change**: `mops toolchain update` stays within the caret range of each pin, as `mops update` does for packages: the same major version, or the same minor version for `0.x.y`. A project pinned to `moc` 1.16.1 now gets the newest 1.x release instead of jumping to 2.x. When a newer release is out of range, the command names it. To cross the bound, pass the new `--major` flag. A pin that is not a semantic version, such as `wasm-opt` `133`, changes only with `--major`. A pin to a local file is always skipped, as `mops update` skips path dependencies; before, `update` replaced it with the latest release.
- **Behaviour change**: `mops toolchain use <tool> latest`, `mops toolchain update --major` and the `latest` line of `mops toolchain info` resolve to the stable release with the highest version, as Cargo does. A tag with a semver prerelease suffix, such as `2.3.0-rc.1`, counts as a prerelease even when GitHub does not flag it. They took the most recently published release, so a bugfix on an older line, such as `moc` 1.16.2 published after 2.0, became `latest`. The interactive `mops toolchain use <tool>` picker also lists releases highest version first, so it no longer preselects that bugfix.
- `wasm-opt` release lists, such as `mops toolchain info wasm-opt --versions` and the picker, show only Binaryen's `version_N` releases, highest first. They also listed the repo's old `1.38.x` tags, which `mops` cannot install, and put `99` above `131`.

## 3.7.1
- Rebuilding a release now gives the same `cli.tgz` every time, so its published SHA256 can be verified. `wasm-bindgen` is updated to 0.2.130: 0.2.106 ordered the type section of the CLI's wasm differently from run to run.
Expand Down
12 changes: 8 additions & 4 deletions cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1031,17 +1031,21 @@ toolchainCommand
toolchainCommand
.command("update")
.description(
"Update specified tool or all tools to the latest version and update mops.toml",
"Update specified tool or all tools to the newest compatible version and update mops.toml",
)
.addArgument(
new Argument(
"[tool]",
"tool to update (defaults to all configured tools)",
).choices(TOOLCHAINS),
)
.action(async (tool?: Tool) => {
.option(
"--major",
"Allow updates that cross the caret bound (major versions, or for 0.x.y tools, minor versions)",
)
.action(async (tool: Tool | undefined, options: { major?: boolean }) => {
checkConfigFile();
await toolchain.update(tool);
await toolchain.update(tool, options);
});

toolchainCommand
Expand All @@ -1052,7 +1056,7 @@ toolchainCommand
)
.option(
"--versions",
"List release versions, one per line (newest first; first GitHub page by default)",
"List release versions, one per line (highest version first; first GitHub page by default)",
)
.option(
"--all",
Expand Down
84 changes: 66 additions & 18 deletions cli/commands/toolchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import { FILE_PATH_REGEX } from "../../constants.js";
import { cliError } from "../../error.js";
import { getPocketIcUrl } from "../../helpers/pocket-ic-startup.js";
import { RECOMMENDED_POCKET_IC_VERSION } from "./pocket-ic-versions.js";
import type { ReleaseInfo } from "./release-tags.js";
import semver from "semver";
import {
latestCompatible,
sortReleaseTags,
type ReleaseInfo,
} from "./release-tags.js";

function label(text: string): string {
return chalk.bold(text.padEnd(16));
Expand Down Expand Up @@ -208,35 +213,78 @@ async function use(tool: Tool, version?: string, { prerelease = false } = {}) {
}
}

// download latest binary and set version in mops.toml
async function update(tool?: Tool) {
// The newest version `update` may move a pin to, and the overall latest when
// that is out of range. Mirrors `mops update`: stays within the caret range of
// the pin unless `major` is set.
async function resolveUpdate(
tool: Tool,
pinned: string,
major: boolean,
): Promise<{ version: string; latest: string }> {
let toolUtils = getToolUtils(tool);
let res = await toolUtils.getReleaseTags();
let { tags, truncated } = res;
// Page 1 nearly always has a stable release. Only when it does not is
// another request worth it.
let latest = res.latest ?? (await toolUtils.getLatestReleaseTag());
// `--major` never moves a prerelease pin back to an older stable line.
let pinnedIsNewer =
pinned !== latest && sortReleaseTags([pinned, latest])[1] === pinned;
if (major) {
return { version: pinnedIsNewer ? pinned : latest, latest };
}
let version = latestCompatible(pinned, tags);
// A newer release on the pinned line is almost always on page 1. Only an
// old pin with nothing there needs the full history.
if (version === undefined && truncated && semver.valid(pinned)) {
({ tags } = await toolUtils.getReleaseTags({ all: true }));
version = latestCompatible(pinned, tags);
}
return { version: version ?? pinned, latest };
}

// download the newest compatible binary and set version in mops.toml
async function update(tool?: Tool, { major = false } = {}) {
let config = readConfig();
config.toolchain = config.toolchain || {};

let tools = tool ? [tool] : (Object.keys(config.toolchain) as Tool[]);

for (let tool of tools) {
if (!config.toolchain[tool]) {
let pinned = config.toolchain[tool];
if (!pinned) {
cliError(
`Tool '${tool}' is not defined in [toolchain] section in mops.toml`,
);
}

let toolUtils = getToolUtils(tool);
let version = await toolUtils.getLatestReleaseTag();

await download(tool, version);
// As `mops update` never touches path dependencies, `--major` included.
if (pinned.match(FILE_PATH_REGEX)) {
console.log(`${tool} is pinned to a local file, skipping`);
continue;
}

let oldVersion = config.toolchain[tool];
config.toolchain[tool] = version;
writeConfig(config);
let { version, latest } = await resolveUpdate(tool, pinned, major);

await checkRequirements();
await download(tool, version);

if (oldVersion === version) {
console.log(`Latest ${tool} ${version} is already installed`);
} else {
if (version !== pinned) {
config.toolchain[tool] = version;
writeConfig(config);
await checkRequirements();
console.log(chalk.green(`Installed ${tool} ${version}`));
} else {
console.log(`${tool} ${pinned} is already the latest compatible version`);
}

let outOfRange =
latest !== version && sortReleaseTags([version, latest])[1] === latest;
if (outOfRange) {
console.log(
chalk.gray(
`${tool} ${latest} is available. To update to it, run ${chalk.green(`mops toolchain update ${tool} --major`)}`,
),
);
}
}
}
Expand Down Expand Up @@ -264,7 +312,7 @@ async function info(tool: Tool, options: ToolchainInfoOptions = {}) {
}

// Capped: a short history plus the `latest` line.
let { tags, truncated, publishedLatest } = await toolUtils.getReleaseTags({
let { tags, truncated, latest } = await toolUtils.getReleaseTags({
prerelease,
});

Expand All @@ -276,8 +324,8 @@ async function info(tool: Tool, options: ToolchainInfoOptions = {}) {
console.log("");
console.log(chalk.green.bold(tool));

if (publishedLatest) {
console.log(chalk.yellow(`latest: ${publishedLatest}`));
if (latest) {
console.log(chalk.yellow(`latest: ${latest}`));
}

if (pinned) {
Expand Down
57 changes: 47 additions & 10 deletions cli/commands/toolchain/release-tags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SemVer } from "semver";
import semver, { SemVer } from "semver";

export type ReleaseInfo = {
tag_name: string;
Expand All @@ -13,16 +13,37 @@ export type ReleaseFilter = {
exclude?: string[];
};

let parseSemVer = (tag: string): SemVer | undefined => {
try {
return new SemVer(tag);
} catch {
return undefined;
}
};

// Any version outranks a non-version tag, so a stray tag such as `dev` can
// never become `latest`. Non-version tags compare numerically, so Binaryen's
// `version_99` sorts below `version_131`.
export let sortReleaseTags = (tags: string[]): string[] => {
return [...tags].sort((a, b) => {
try {
return new SemVer(a).compare(new SemVer(b));
} catch {
return a.localeCompare(b);
let va = parseSemVer(a);
let vb = parseSemVer(b);
if (va && vb) {
return va.compare(vb);
}
if (va || vb) {
return va ? 1 : -1;
}
return a.localeCompare(b, "en", { numeric: true });
});
};

// A semver prerelease such as `2.3.0-rc.1` counts even when GitHub does not
// flag it, or it would outrank the stable `2.2.x` line as `latest`.
let isPrerelease = (release: ReleaseInfo): boolean =>
release.prerelease ||
(parseSemVer(release.tag_name)?.prerelease.length ?? 0) > 0;

// Drafts are excluded unconditionally: GitHub never exposes them to anyone but
// the repo's own maintainers. Callers only choose whether prereleases show.
let filterReleases = (
Expand All @@ -32,12 +53,12 @@ let filterReleases = (
return releases.filter(
(release) =>
!release.draft &&
(prerelease || !release.prerelease) &&
(prerelease || !isPrerelease(release)) &&
!exclude?.includes(release.tag_name),
);
};

/** Tags matching what `mops toolchain update` would resolve to, newest first. */
/** Tags matching what `mops toolchain use <tool> latest` resolves to, highest first. */
export let releaseTags = (
releases: ReleaseInfo[],
options?: ReleaseFilter,
Expand All @@ -47,11 +68,27 @@ export let releaseTags = (
).reverse();
};

/** Tags in GitHub publish order, for display. */
/** Rows in `releaseTags` order, for display with their dates. */
export let releaseRows = (
releases: ReleaseInfo[],
options?: ReleaseFilter,
): ReleaseInfo[] => {
let kept = new Set(filterReleases(releases, options).map((r) => r.tag_name));
return releases.filter((release) => kept.has(release.tag_name));
let kept = filterReleases(releases, options);
let byTag = new Map(kept.map((release) => [release.tag_name, release]));
return releaseTags(kept, options).map((tag) => byTag.get(tag)!);
};

/**
* Highest of `tags` within Cargo's caret range of `pinned`: same major, or
* same minor for `0.x`, as `mops update` picks for packages. `undefined` when `pinned`
* is not a version (a Binaryen `133`, a local file) or no tag fits the range.
*/
export let latestCompatible = (
pinned: string,
tags: string[],
): string | undefined => {
if (!semver.valid(pinned)) {
return undefined;
}
return semver.maxSatisfying(tags, `^${pinned}`) ?? undefined;
};
Loading
Loading