Skip to content

feat(cli): host entry for a tool that carries the CLI - #7420

Merged
josephfarina merged 81 commits into
mainfrom
metaforge/cli-package-set-runtime
Oct 21, 2026
Merged

josephfarina merged 81 commits into
mainfrom
metaforge/cli-package-set-runtime

Conversation

@josephfarina

@josephfarina josephfarina commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

User need

A tool that carries the Astryx CLI for its own users, such as a company's own command-line tool that runs it as acme astryx …, needs to start the CLI with explicit inputs. It needs two results. First, the commands the CLI prints must name the tool's command. Second, a project CLI that the tool chose not to run must never run anyway. Today there is no supported entry. Such a tool runs the astryx bin, which prints package-runner commands (npx astryx …) that its users may not have, and which hands a project's run to a project CLI that the tool skipped.

Problem and solution fit

  • @astryxdesign/cli/host exports runHostedCli, the host entry that spec:AST-081 FR1 defines. A run behaves as the astryx bin does with the same arguments in the same folder, once per process.
  • cliCommand is the name the door's users type. Printed commands start with it, unless the integrations the run loads declare their own cliCommand (FR5).
  • declinedProjectCli is the reason, in the host's words, that the host found the project's own CLI and did not run it. The run is then never handed to that CLI (FR2, FR9). When this copy is that CLI's release, it answers in that CLI's place: meta.answeredBy.copy stays project, and in text mode one line names that CLI's release and the reason. A package set whose CLI is that release answers the same way through its host entry. Otherwise this copy answers with FR2's fallback warning, which names the reason.
  • roots are the host's package sets, in its order of preference. A hosted run installs nothing (INV30, FR2). A release other than this copy comes from the first set whose CLI and Core are that release and that holds what the project would install for each @astryxdesign/* package it leaves uninstalled: the lockfile's version, else a published version in the declared range, never an unrequested prerelease. A package that ships an integration manifest is never filled inside a project. When that set's CLI ships a host entry, the entry runs in this process with the same inputs, discover sources included, and the call settles with its result; otherwise its bin takes the run. With no such set, this copy answers with FR2's fallback warning. A declined project CLI's release is served only through a set's host entry, so the declined CLI never runs.
  • integrations are the integrations the host approves for use outside a project. Each loads by name from the set that holds this CLI, with FR12's checks, beside what FR12 finds there.
  • discoverSources are the host's own discover sources. Discover calls them after every integration's source, before the official list, and reports each as the host (spec:AST-051 FR6). Their saved copies are kept per host, by the root that holds its CLI, so two tools on one computer never answer with each other's (FR8).
  • The result names each package the run resolved (the CLI, its Core, its integrations), with its version and whether it came from the project or a package set (INV30). What the project found or loaded is the project's: the Core it resolves and the integrations its load brings in, also when a workspace hoists them, and every package when the host's CLI is installed in the project.
  • A hosted copy runs none of the global copy's background work, and its carried Core comes only from beside it.

Current specification

  • spec:AST-081 (current): FR1 (the host entry, its inputs, one call per process), FR2 (a declined project CLI; a hosted run installs nothing), FR5 (the door step of the command-name picker), FR9 (no hand-off to a declined project CLI).
  • architecture:cli-surface (current): INV30 (a host's package sets), INV2 (meta.answeredBy), INV22.

Public delta and caller burden

  • New export ./host (host/index.mjs, host/index.d.ts) and the host folder in the package's files.
Option Default Meaning
argv none The arguments after astryx.
cwd the process's working folder The folder the run works in. It must exist.
cliCommand none (the package manager's name) The command the tool's users type. A non-blank single line of at most 120 characters, with no surrounding spaces, the same rules as the manifest's cliCommand.
declinedProjectCli none Why the tool did not run the project's own CLI, as a non-blank single line of at most 120 characters.
roots none The tool's package sets, in its order of preference. Each must be a folder.
integrations none Package names the tool approves for use outside a project.
discoverSources none Discover source functions, reported as the host's.
  • It resolves with {status, packages}, where packages lists each package the run resolved as {name, version, source} and source is project or package-set. When another package set's host entry answers, the call settles with that entry's result. As the bin does, a run ends the process with its status instead when it prints help or the version, rejects the command line, reports an error it stops on (every error in --json mode included), meets an unexpected error, or hands the run to another CLI's bin; the README, host/index.d.ts, and the guide list these. It rejects with a TypeError, before anything runs, for an unknown option or an invalid value. It rejects with an Error, before anything runs, when a run already started in the process.
  • The bin's run moves into clients/cli/run.mjs, which the bin calls after its Node version gate. The bin behaves as before.
  • Consumer guide: astryx docs cli/host-entry, under the CLI's guides and linked from astryx docs cli/api, with the options, the result, the errors, and the process-ending paths.
  • Changeset: @astryxdesign/cli patch [feat].

Before, a tool spawns the bin, and search prints command: npx astryx component Calendar. After:

import {runHostedCli} from '@astryxdesign/cli/host';

const {status} = await runHostedCli({
  argv: process.argv.slice(2),
  cwd: process.cwd(),
  cliCommand: 'acme astryx',
});
process.exitCode = status;

Search then prints command: acme astryx component Calendar.

Design and alternatives

  • Unknown options are rejected, so a misspelled input never silently does nothing, and a newer host that runs an older CLI fails before anything runs.
  • The declined reason is free text, because FR1 leaves the reasons to the host.
  • Update notices print as the process exits, outside the door's scope, so the run re-enters that scope for them.
  • A run that another package set serves goes through that set's own host entry, in this process, so every input reaches it, discover sources included, and the call settles with its result. The one-call mark passes to that entry, whose modules are its own. A set without a host entry serves only through its bin, and never a declined project CLI's release, because a bin cannot learn that the host declined the project's CLI.
  • Help, version, and error exits still end the process, as the bin's do. Changing them only for hosted runs would make the two doors behave differently (FR1).
  • foundation/runtime holds the active hosted run and the provenance record (package-root.mjs), matching a project to a set (package-set.mjs), and the versions a project would install (locked-versions.mjs), as INV30's owning code lists. It reuses the release choice's lockfile reader and semver helpers instead of carrying its own.
  • Rejected: an environment variable or a flag for the door's inputs (FR1 forbids both). Rejected: passing the door's name to a copy that a run is handed to (FR9 adds nothing to a hand-off). Rejected: another set's host entry in a child process, with its result and the discover calls sent over a pipe; that needs a protocol between releases for what one process does directly.

Evidence

  • host/index.test.mjs: every invalid input is rejected before anything runs. A second call in one process fails while the first run completes. A hosted run gives the same exit status, standard output, and standard error as the bin for --version, an error, and docs --json. Help names the host's command. For each declined reason, the project's CLI never runs, and the fallback line names the reason (meta.answeredBy.copy is fallback). A declined CLI of this copy's own release, with a Core of another release, is answered in its place: copy is project, core is the project's, and one line names the release and the reason. Each of these tests fails when its feature is removed.
  • foundation/runtime/package-set.test.mjs (INV30 evidence): the first set whose CLI and Core match serves; a set with a mismatched or missing Core is skipped; the lockfile's version is required, else a version in the declared range; a path or protocol declaration needs the lockfile; a prerelease needs a range that names it; integrations and installed packages are never filled; a root never reads past its own node_modules; approved integrations load from the set with FR12's checks, and never from a folder above it; the provenance record names the project's packages as the project's, also when the host's CLI is installed in the project or a workspace hoists them, and a package set inside the project folder as a package set.
  • foundation/runtime/hosted-runtime.test.mjs (INV30 evidence), through the host entry in a host process: a project whose own CLI cannot start is served by the first matching set; its host entry, when it has one, runs in the same process with the same inputs, discover sources included, and the call settles with its result; with no matching set, or one whose CLI starts through neither its host entry nor a bin, this copy answers with the fallback warning and nothing is installed; a declined project CLI is served through a set's host entry and never run, and without one this copy answers naming the reason; the host's discover source is called and reported as the host, and in a project it comes after the astryx.config source and an integration's source, before the official list; the result names the CLI and Core from the package set and a project's integration as the project's.
  • api/discover/_adapter.test.mjs: a host's saved discover copies are kept per host; another host's failing source gets none of them.
  • host/door-conformance.test.mjs (FR1 door conformance): every command example runs through the bin and through the host entry, in an empty folder, a project on the current minor, and a project on the previous minor, each run with its own folder, home folder, and per-user cache; exit status, standard output, standard error, and file changes are the same through both doors.
  • Each of these tests fails when its feature is removed (checked one mutation at a time), every review fix included.
  • The CLI node suite gives the same results as main on the same machine.

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm vitest run --project node packages/cli/host packages/cli/foundation/runtime packages/cli/api/discover/_adapter.test.mjs
  • pnpm vitest run --project node packages/cli
  • pnpm -F @astryxdesign/cli typecheck:strict, pnpm check:cli-structure, pnpm -F @astryxdesign/cli readme:check, pnpm check:changesets, eslint, and Prettier on the changed files

Branch history

Define the in-process package-set seam, project authority, exact pin matching, caller working-directory behavior, and integration provenance for hosts that run Astryx without a project install.
@vercel

vercel Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Oct 21, 2026 4:25pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 13, 2026
@astracat-bot

astracat-bot Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟡 Reviewed (for maintainers only) Oct 21, 2026, 4:28 PM UTC

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

40 of 486 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 754,077
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,188
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
RichTextEditor Markdown parity: side by side probe dark 94,866
RichTextEditor Markdown parity: side by side probe light 89,762
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
Markdown Default neutral dark 7,573
Markdown Default neutral light 7,566

and 20 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR needs a maintainer spec decision before it can be approved. The hosted package-set contract it implements (cli-surface INV30) is not on main yet, and as written its undocumented, process-wide host seam conflicts with current spec:AST-017 FR14 and FR18 and with cli-surface INV12 and INV14, so a maintainer needs to either land INV30 with matching amendments to those records or ask for a documented, invocation-scoped programmatic API instead. Whatever that decision, these changes are needed:

  • Split the change, which is about 4,150 authored lines, so that the lockfile and range readers, the host discover handler, and the runtime planner land separately.
  • Keep findCoreDir unchanged when no package set is active, or move its new unbounded walk, package-name check, and Yarn PnP fallback into their own PR; as written, it breaks two existing tests in agent-docs.test.mjs.
  • Fix the package-set.test.mjs case "names what each root carries…", which fails under pnpm vitest because its fixture has no lockfile and the install hint falls back to the runner.
  • Tag the changeset [feat] instead of [fix] (spec:AST-017 FR7).

[Automated review]

Comment thread packages/cli/foundation/fs/paths.mjs Outdated
if (fs.existsSync(nodeModules)) {
return nodeModules;
}
for (;;) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With no package set active, this now walks to the filesystem root (the base lookup stopped after five directories), skips a packages/core whose name is not @astryxdesign/core, and falls back to Yarn PnP at line 58. Ordinary runs change: a working directory seven levels below an installed Core now finds it, an unrelated packages/core is no longer returned, and two existing tests in foundation/agent-docs/agent-docs.test.mjs fail, because their Core fixtures have no name. Keep the base lookup when no set is active, or move this change into its own PR with updated fixtures and a disclosing changeset.

"astryx: this project's Astryx package versions are unavailable:",
' @acme/ui: project pinned 1.0.0 (package.json); available: 2.0.0 (set 1), 1.0.0 (set 2)',
' @acme/extra: project pinned 1.0.0 (package.json); available: 1.0.0 (set 1), none (set 2)',
"Install the project's dependencies (npm install) to use its own versions.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixture has no lockfile or packageManager, so installCommand falls back to npm_config_user_agent. Under pnpm (pnpm exec vitest run; CI runs pnpm vitest run --project node), the report says pnpm install and this assertion fails; under plain node it passes. Write a package-lock.json into the fixture, or assert only the pin lines.

Comment thread .changeset/cli-package-set-hosting.md Outdated
'@astryxdesign/cli': patch
---

[fix] Let a host run the unchanged Astryx CLI from a compatible package set while the caller's project keeps authority over its installed versions, configuration, working directory, files, and integration provenance. The in-process seam adds no command, flag, environment variable, or package export.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec:AST-017 FR7 tags compatible capabilities [feat]; [fix] is for corrections. If the Core-discovery change for runs without a host stays in this PR, the changeset should also say so.

*/

/** @type {ActivePackageSet | null} */
let active = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec:AST-017 FR18 requires a programmatic control to be an explicit API input that does not depend on ambient mutable process state, so that concurrent calls can choose different values. This module-level set qualifies as that kind of state: it is activated for the rest of the process, swapped by withoutPackageSet, and paired with the process.chdir/process.argv changes in runHostedCli. Resolving that needs either a spec amendment or an invocation-scoped design, and the decision is with maintainers.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR needs a maintainer spec decision before it can be approved. The hosting contract it implements (cli-surface INV30) is not on main, and as written the hosted runtime conflicts with current spec:AST-017 FR14 and FR18, cli-surface INV12 and INV14, and spec:AST-051 FR6, so a maintainer needs to provide the governing spec by landing INV30 with matching amendments to those records, or ask for a documented, invocation-scoped programmatic API instead. Whatever that decision, these changes are needed:

  • Split the change, which is about 4,200 authored lines, so that the lockfile and range readers, the host discover handler, and the runtime planner land separately.
  • Keep findCoreDir unchanged when no package set is active, or move its unbounded walk, name check, and Yarn PnP fallback into their own PR, because two existing tests in agent-docs.test.mjs fail with it.
  • Make the package-set.test.mjs case "names what each root carries…" pass under pnpm vitest, where its fixture's missing lockfile turns the install hint into pnpm install.
  • Tag the changeset [feat] instead of [fix] (spec:AST-017 FR7).
  • Apply host discover handlers only to integrations served from the package set, and let a project plan load a configured integration the project installed, as an installed CLI does.

[Automated review]

Comment thread packages/cli/foundation/fs/paths.mjs Outdated
if (fs.existsSync(nodeModules)) {
return nodeModules;
}
for (;;) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With no package set active, this now walks to the filesystem root (the base lookup stopped after five directories), skips a packages/core or installed Core whose name is not @astryxdesign/core (lines 48 and 51), and falls back to Yarn PnP at line 58. Every run without a host changes, and two existing tests in foundation/agent-docs/agent-docs.test.mjs, a file listed in cli-surface verified_by, fail because their Core fixtures carry no name. Keep the base lookup when no set is active, or move this change into its own PR with updated fixtures and a changeset that discloses it.

"astryx: this project's Astryx package versions are unavailable:",
' @acme/ui: project pinned 1.0.0 (package.json); available: 2.0.0 (set 1), 1.0.0 (set 2)',
' @acme/extra: project pinned 1.0.0 (package.json); available: 1.0.0 (set 1), none (set 2)',
"Install the project's dependencies (npm install) to use its own versions.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixture has no lockfile or packageManager, so installCommand takes the package manager from the runner's user agent. Under pnpm vitest run --project node (CI's command) the report says pnpm install and this assertion fails; under plain node it passes. Write a package-lock.json into the fixture, or assert only the pin lines.

Comment thread .changeset/cli-package-set-hosting.md Outdated
'@astryxdesign/cli': patch
---

[fix] Let a host run the unchanged Astryx CLI from a compatible package set while the caller's project keeps authority over its installed versions, configuration, working directory, files, and integration provenance. The in-process seam adds no command, flag, environment variable, or package export.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec:AST-017 FR7 tags compatible capabilities [feat]; [fix] is for corrections. If the Core-discovery change for runs without a host stays in this PR, the changeset should describe it too.

*/

/** @type {ActivePackageSet | null} */
let active = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec:AST-017 FR18 requires a programmatic control to be an explicit API input that does not depend on ambient mutable process state, so that concurrent calls can choose different values. This module-level set is that kind of state: two overlapping withPackageSet calls see each other's set, lose their own, and leave a stale set active afterwards, and withoutPackageSet swaps it while an async doctor run is awaited. Resolving that needs either a spec amendment or an invocation-scoped design, and the decision is with maintainers.

// discover source itself (foundation/runtime/package-root.mjs). The
// replacement is validated like the export it replaces, and the
// integration keeps its own name, so results still name this package.
const hostDiscover = packageSetHandler(pkg.name ?? spec, 'discover');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This consults the host handler for every loaded integration, including one the project installed itself: in a project plan whose provenance records @acme/catalog as the project's, discover reports the host's source as @acme/catalog's. That breaks the project-authority promise this runtime makes, and a host-provided source is also outside current spec:AST-051 FR6 ("Sources are functions a project or integration provides"). At minimum, apply handlers only to integrations the plan serves from the package set, and test the project-installed case.

entry.dir != null &&
sameDirectory(entry.dir, dir),
);
if (plannedProjectPackage || projectDeclaresPackage(cwd, packageName)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A project plan records only declared pins, so a configured integration the project installed but did not declare (for example, hoisted as a dependency of a declared package) is refused here, although the installed CLI loads it and doctor, which runs with no set, reports it healthy. That contradicts the project contract in package-set.mjs lines 21–23 ("as an installed CLI would"). When the plan has no root, admit an installed configured package as the installed CLI does, or correct that contract and have INV30 state the divergence.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR needs a maintainer spec decision before it can be approved: the hosting contract it implements (cli-surface INV30) is not on main, and as written the hosted runtime conflicts with current spec:AST-017 FR14 and FR18, cli-surface INV12 and INV14, and spec:AST-051 FR6. A maintainer needs to provide the governing spec, either by landing INV30 on main with matching amendments to those claims or by asking for a documented, invocation-scoped programmatic API instead. The latest commit resolves the earlier test, changeset, Core-lookup, and provenance findings; whatever the spec decision, two changes are still needed:

  • Split the change, about 4,400 authored lines, starting with the host discover handler and the stricter integration-name check for every run, neither of which version planning needs.
  • Make project plans and hosted doctor runs do what the runtime says, or document what they do: a project plan drops undeclared legacy packages that the installed CLI lists, and doctor integration components checks against the package set's Core.

[Automated review]

Comment thread packages/cli/foundation/fs/paths.mjs Outdated
scanDir(nodeModulesDir);
// A plan enumerates only the project package directories it recorded. Never
// scan the caller's whole node_modules while a hosted set is active.
for (const entry of set.packages) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a project plan this reads only the packages the plan recorded, so an installed but undeclared legacy package that the installed CLI lists disappears (for example a hoisted dependency with an astryx.docs field). package-set.mjs lines 21–23 say a project plan resolves "as an installed CLI would". Either scan as the installed CLI does when set.mode === 'project', or state the narrower behavior there, in the PR description, and in INV30.

Comment thread packages/cli/api/doctor/doctor.mjs Outdated
*/
export async function runChecks(options = {}) {
export function runChecks(options = {}) {
return withoutPackageSet(() => runProjectChecks(options));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the health report is isolated here. doctor integration components calls findCoreDir directly (api/integration/authoring-checks.mjs line 245), so under a hosted plan it checks against the package set's Core while this report says Core is not installed. Run the doctor integration subcommands inside withoutPackageSet too, or narrow the statement that doctor always runs with no package set active.

*/

/** @type {ActivePackageSet | null} */
let active = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec:AST-017 FR18 requires a programmatic control to be an explicit API input that does not depend on ambient mutable process state, so that concurrent calls can choose different values. This module-level set is that kind of state: two overlapping withPackageSet calls see each other's set and can leave a stale set active, and withoutPackageSet blanks it for any other invocation while doctor runs. Resolving that needs either a spec amendment or an invocation-scoped design, and the decision is with maintainers.

integrations,
projectCliAlreadyHandled,
});
for (const warning of plan.warnings) stderr.write(`${warning}\n`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cli-surface INV12 makes humanLog and humanWarn the only chatter primitives, and both are silent under --json; this writes every plan warning to stderr in every mode, including --json runs (package-set.test.mjs lines 414–454). Whether a host wrapper is held to INV12 is part of the pending spec decision.

@josephfarina
josephfarina force-pushed the metaforge/cli-package-set-architecture branch from 12c63ae to f06b2e9 Compare October 13, 2026 09:55
@josephfarina
josephfarina force-pushed the metaforge/cli-package-set-runtime branch from 28c3e51 to 2f7f9fc Compare October 13, 2026 09:55

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR needs a maintainer spec decision before it can be approved: the hosting contract it implements (cli-surface INV30) is not on main, and as built the runtime departs from current cli-surface INV14, spec:AST-051 FR6 and spec:AST-017 FR18, so a maintainer needs to provide the governing spec, either by landing INV30 on main with matching amendments to those claims or by asking for a redesign. This revision resolves the earlier JSON-chatter, project-plan, doctor and overlapping-set findings; whatever the spec decision, these changes are still needed:

  • Split the change (5,573 authored lines), starting with the formatter-only reflow, the Core-keyed cache changes, and the host discover handler.
  • Document @astryxdesign/cli/host for consumers (defaults, error behavior including the rejected overlapping call, and an example) as spec:AST-017 FR14 requires, and correct the PR description, which says no export is added.
  • Read Yarn Berry lockfile keys that list several descriptors in one quoted string; today such a pin is lost and a matched plan can serve a different version.
  • Stop truncating delegated output over 1 MiB when the host passes its own streams, and fix the other-CLI refusal, which names the selected root's CLI as the running one.

[Automated review]

if (!/^\s/.test(line)) {
current = [];
if (!line.endsWith(':')) continue;
for (const raw of line.slice(0, -1).split(',')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yarn Berry writes several descriptors as one quoted key, for example "@acme/ui@npm:^1.0.0, @acme/ui@npm:^1.0.2":. Splitting on , before unquoting yields the name "@acme/ui and the range npm:^1.0.2", so when the package has another resolution neither the exact match nor the single-version fallback answers and the planner falls back to the declared range. With a lockfile resolving 1.0.4, a matched plan served 1.0.0 from the first root even though a root carrying 1.0.4 was offered. Unquote the whole key first, then split on , , and add a Berry multi-descriptor case to locked-versions.test.mjs.

}
const ownStdout = stdout === process.stdout;
const ownStderr = stderr === process.stderr;
const child = spawnSync(process.execPath, [cli.bin, ...argv], {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With host-supplied streams the child's stdout and stderr are piped through spawnSync, which keeps Node's default 1 MiB maxBuffer. A project CLI that prints more is killed with ENOBUFS; the truncated output is written to the host's stdout and then followed by an ERR_VERSIONS_UNAVAILABLE envelope, so --json output is no longer one envelope and the code describes a version problem that did not happen. Stream the child asynchronously (or raise maxBuffer), and report a spawn failure without appending an envelope to partial output.

) {
const cli = /** @type {PlannedCli} */ (plan.cli);
return refuse(
`astryx: cannot run because this command uses ${CLI_PACKAGE}${cli.version ? ` ${cli.version}` : ''}, but the selected packages require another CLI.`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cli here is plan.cli, the selected root's CLI, so with CLI 0.7.0 running and a root carrying 0.5.0 this prints "this command uses @astryxdesign/cli 0.5.0, but the selected packages require another CLI", which reverses the two. Name the running CLI's version and the selected root's version, and tell the host to call that CLI's own entry (plan.cli.runtime).

Comment thread packages/cli/package.json
"types": "./api/index.d.mts",
"import": "./api/index.mjs"
},
"./host": {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds a public, typed package export, but nothing a consumer reads documents it: spec:AST-017 FR14 asks supported behavior to be documented and discoverable, with accepted values, defaults (such as integrations defaulting to the newest root's dependencies), error behavior (the rejected overlapping call, the other-CLI refusal and the plan.cli.runtime handoff) and a representative invocation, linked from a discovery surface. The PR description also says the change adds no export; please correct its public-delta section.

argv,
{cwd = process.cwd(), stdout = process.stdout, stderr = process.stderr} = {},
) {
if (running) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec:AST-017 FR18 asks that a programmatic control not depend on ambient mutable process state and that concurrent calls can select different values independently. Package state is now scoped per call, but this runner still switches the process's working directory, argv, stdio and exit handling for each call and rejects an overlapping one. Whether a single-flight host entry is acceptable is part of the pending maintainer spec decision, so this is recorded for that decision rather than as a required change.

… npm

G22 failed on devservers: envOf kept http_proxy/https_proxy/all_proxy, so
the background check's npm request for the 127.0.0.1 test registry went to
the proxy; and the runs' search path held only a node link, so where npm is
not beside Node the check could not start it. envOf now drops the proxy
variables, and the private computer's node folder links the runner's npm
entry file too. With the proxies set, the old test fails and this one
passes.
…s why it failed

- npmCommand also takes an npm beside the running Node, or on the search
  path, that links to npm's entry file, as distribution packages install it
  (/usr/bin/npm to /usr/lib/node_modules_22/npm/bin/npm-cli.js).
- resolveLatestRelease names why it returned nothing: npm-missing,
  npm-failed: <npm's error code>, or bad-reply. The check records it in
  state.json's checkFailed (diagnosis only, not a contract), and a check
  that reaches the registry clears it.
- doctor's newest-release check says when the last check did not reach the
  registry and why, noting that npm's registry and proxy settings decide
  where it asks.
Tests: npm found through a link on the search path and beside Node, and
npm started directly when there is none; each failure reason; the record
and its clearing.
@josephfarina
josephfarina changed the base branch from josephfarina/cli-command-name to main October 21, 2026 12:02
@josephfarina
josephfarina marked this pull request as ready for review October 21, 2026 12:30

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs changes before approval. The host entry's inputs, the one-call rule and the package-set matching follow the current spec:AST-081 FR1 and architecture:cli-surface INV30, but a few things are missing or wrong.

  • Split the 2,219 authored lines along the branch's own two feature commits: the host entry first, then the package sets, approved integrations, discover sources and provenance record.
  • When another package set's host entry serves a run, settle runHostedCli with the child's {status, packages} and carry the host's discover sources across, instead of exiting the host process (foundation/release/handoff.mjs), as INV30 and spec:AST-051 FR6 require.
  • List every path that ends the process in the README and host/index.d.ts, because --help and --version never settle today.
  • Give the declined-CLI case its own who-answered line, key the host's saved discover copy per host, and link the entry from astryx docs cli/api.

[Automated review]

Comment on lines +427 to +440
const options = {
argv,
cwd: process.cwd(),
roots: [root],
integrations: [...(hosted?.integrations ?? [])],
...(door ? {cliCommand: door} : {}),
...(declinedProjectCli ? {declinedProjectCli} : {}),
};
const script = [
`const {runHostedCli} = await import(${JSON.stringify(pathToFileURL(hostEntry).href)});`,
`const {status} = await runHostedCli(${JSON.stringify(options)});`,
'process.exitCode = status;',
].join('\n');
return handOff(null, argv, choice, json, () => {}, [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When another package set's host entry serves the run, the child gets no discoverSources, because they are functions and never leave this process. The generated script discards the child's {status, packages}, and handOff then exits this process (line 511), so runHostedCli never settles. architecture:cli-surface INV30 says the host entry returns the provenance record with the run's result, and spec:AST-081 FR1 and spec:AST-051 FR6 say discover calls the door's sources. One way to conform: keep the parent waiting, have the child send its result back over an extra pipe, proxy the source calls over the same channel, and resolve with the child's result.

Comment thread packages/cli/host/index.d.ts Outdated
Comment on lines +89 to +91
* The run owns the process's working folder, arguments, standard streams,
* and exit: a run handed to another release, and some failures, end the
* process with the run's exit status instead of returning.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--help, --version and --version --json also end the process, through handleCommanderError and handleVersionJsonPreflight, so the call never settles for them either. A host that awaits the result to log packages or clean up never gets there. Please list every path that ends the process here and in the README's Host entry section, or make those paths settle with status 0 in a hosted run.

Comment on lines +234 to +241
if (choice.version === self.version) {
choice = {
...choice,
copy: 'matched',
answer: 'self',
bin: null,
unavailable: null,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the project's CLI is this copy's release but its Core is another, for example CLI 0.7.2 with Core 0.7.0, this relabels the run as matched. The run then prints astryx: answered by CLI 0.7.2 with Core 0.7.0, the release that matches this project's Core, which is not true here, and JSON reports copy: matched, which spec:AST-081 FR5 defines as the release matched to the project's Core. A line of its own for the declined-CLI case, naming the project CLI's release, would avoid the misleading claim.

}

/** Where a discover source a host passed comes from (spec AST-081 FR1). */
const DOOR_SOURCE = 'the host';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saved discover copies are keyed by the source's from label, so every tool on one computer that carries the CLI shares the same the host saved copy in the per-user cache. When one tool's source fails, discover serves another tool's saved catalog as this host's. spec:AST-051 FR8 keeps saved answers per source. Could a door's key include something host-specific, such as the starting root?

…CLI's release

- When another package set's release answers a hosted run through its own
  host entry, that entry runs in this process with the same inputs,
  discover sources included, and runHostedCli settles with its result
  (architecture:cli-surface INV30, spec:AST-051 FR6) instead of a child
  process that ended the host's.
- A declined project CLI answered by this copy, its release, reports
  copy `project` and prints a line of its own naming that CLI's release
  and the reason, not the matched-release line.
- A host's discover sources keep their saved copies per host, keyed by the
  root that holds its CLI (spec:AST-051 FR8).
- The README, host/index.d.ts, and a new consumer guide
  (`astryx docs cli/host-entry`, linked from `astryx docs cli/api`) list
  every path on which a run ends the process instead of settling.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval waits on a maintainer decision: spec:AST-081 FR5 does not say which meta.answeredBy.copy value or which standard-error line a hosted run reports when it answers in place of a declined project CLI of its own release, and this PR reports copy: project with a new in-place line, so a maintainer needs to provide or identify that FR5 position. Whatever that decision is, two changes are needed:

  • Split the 2,523 authored lines along the branch's own two feature commits (the entry with its provenance record first, then package sets, approved integrations and discover sources), and drop the formatting-only reflow.
  • Report a project's own packages as project in packages when the host's CLI is installed inside the project; resolvedPackages currently labels everything under the starting root package-set (foundation/runtime/package-root.mjs).

FR1's verification row also asks for host-door tests in a project, and for a discover case with project and integration sources beside the host's.

[Automated review]

return [...resolved.values()].map(({name, version, dir}) => ({
name,
version,
source: inPackageSet(dir) ? 'package-set' : 'project',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the host's CLI is installed inside the project (a tool the project depends on, which npm hoists into the project's node_modules), startingRoot is the project itself, so every package the project installed comes back as package-set. A probe with discover --json reported the project's declared integration acme-widgets as package-set, and the same project with the host's CLI elsewhere reported it as project. architecture:cli-surface INV30 says "A project's installed packages always resolve from the project". Could a package inside the project the run answers be labelled project before the package sets are checked?

Comment on lines +351 to +352
else if (!json && inPlace)
console.error(inPlaceOfProjectLine(choice.version, inPlace));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec:AST-081 FR2 has the declined CLI's release answer in its place, but FR5 defines neither a meta.answeredBy.copy value nor a standard-error line for this case. Its project value and line rule cover only the project's own CLI answering, or a hand-off to it. A maintainer is deciding whether FR5 takes copy: project and this line.

});

describe("the host's discover sources", () => {
it("are called after every other source, and reported as the host's", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case runs in an empty folder, so no project or integration source sits beside the host's. spec:AST-081's verification row for FR1 asks for "a door source beside project and integration sources" and fails when "a door's source is called out of order". Adding an astryx.config discover and an integration's discover would cover that order.

… sources in a project

- The provenance record names what the project found or loaded as the
  project's: the Core it resolves, the integrations its load brings in,
  and, when the host's CLI is installed in the project, every package
  there. A package set inside the project folder is still a package set.
- Approved integrations come from the package set's own node_modules,
  without moving the existing scan's lines.
- An end-to-end test in a project with an astryx.config source and an
  integration's source checks that the host's sources come after both,
  before the official list.
@josephfarina

Copy link
Copy Markdown
Contributor Author

Maintainer decision on AST-081 FR5: when a host declines a project's own CLI and the copy that answers is that CLI's release, meta.answeredBy.copy is project. The value names the release the project chose, and that release answered, so the result reports the project's own choice (INV28). The standard-error line FR5 requires when the project's own CLI did not answer says it was skipped and why: astryx: answered by CLI <v>, the release of this project's CLI, in its place (project CLI skipped: <reason>).

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are needed before approval. The host entry, its inputs and the package-set rules follow spec:AST-081 FR1 and FR2 and architecture:cli-surface INV30, and the in-place line for a declined project CLI now follows the maintainer's FR5 decision; what remains:

  • Split the 2,708 authored lines along the branch's own two feature commits (the entry with its provenance record first, then package sets, approved integrations and discover sources), and drop the formatting-only reflow in api/discover/_adapter.mjs and the bin.
  • Keep a hosted run from installing anything when a qualifying package set's host entry cannot load and the set has no bin, where startRun currently reaches ensureRelease (foundation/release/handoff.mjs), against INV30's “A hosted run installs nothing”.
  • Correct the declinedProjectCli note in host/index.d.ts, which leaves out the package set's host entry that serves another release.
  • Add FR1's per-example door comparison through the host entry, including projects on the current and previous minor.

[Automated review]

});
if (answered) return answered;
}
bin = served.bin;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the served set's host entry cannot load (answerInPackageSet returns null) and the set has no astryx bin, which qualifyingRoot allows (foundation/runtime/package-set.mjs line 118), bin stays null here and the run falls into ensureRelease below, which starts npm. A probe with such a set printed astryx: installing CLI release 0.7.0 into the per-user cache (once)... and left releases/.failed-0.7.0.json in the per-user cache. architecture:cli-surface INV30 says “A hosted run installs nothing”. Falling back here when served.bin is null (or keeping ensureRelease out of hosted runs), with a hosted-runtime.test.mjs case for a set whose entry cannot load, would close it.

Comment thread packages/cli/host/index.d.ts Outdated
Comment on lines +33 to +35
* run is then never handed to that CLI: this copy answers when it is that
* CLI's release, and otherwise answers with one warning line naming the
* reason and `meta.answeredBy.copy` set to `fallback`. Default: none; a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this copy is not the declined CLI's release, a qualifying package set's host entry of that release answers first (foundation/release/handoff.mjs lines 258–273), as the README's declinedProjectCli row says; only without one does this copy answer with the fallback warning and copy: fallback. Could this sentence name the package-set case too?

it('gives the same exit status, output, and standard-error line', () => {
const empty = tempDir('empty');
const env = cleanEnv();
for (const args of [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec:AST-081's verification row for FR1 asks for every command example run through each door, in a project on the current minor and one on the previous minor as well as an empty folder. This loop covers three invocations in an empty folder. Running every CommandDoc example through the bin and the host entry in those folders, comparing status, stdout and stderr apart from FR5's names and lines, would supply that evidence.

…h both doors

- A hosted run whose matching package set's CLI starts through neither its
  host entry nor a bin is answered by this copy, announced, and installs
  nothing (architecture:cli-surface INV30), instead of installing that
  release.
- host/index.d.ts says a package set's host entry of the declined CLI's
  release answers in its place, as the README does.
- A door conformance test runs every command example through the bin and
  through the host entry, in an empty folder, a project on the current
  minor, and one on the previous minor, and compares exit status, output,
  and file changes (spec:AST-081 FR1).
- The discover adapter and the bin keep the formatting of the lines this
  change does not touch.
The gh tool writes a random device id when swizzle asks it whether it is
signed in, and npm keeps a cache and logs; both now live outside the
folders the conformance runs compare.
astracat-bot[bot]
astracat-bot Bot previously requested changes Oct 21, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are needed before approval. The host entry, its inputs and the package-set rules follow spec:AST-081 FR1 and FR2 and architecture:cli-surface INV30, the declined-CLI line follows the maintainer's FR5 decision, and last round's install path, type note and per-example door comparison are fixed. What remains is scope: please split the 2,970 authored lines along the branch's own two feature commits, landing the entry with its provenance record and the door-conformance test first, then the package sets, approved integrations and discover sources.

[Automated review]

@josephfarina

Copy link
Copy Markdown
Contributor Author

Maintainer decision: this repository has no PR size limit; one PR per piece of work. This PR is one piece: the supported host entry AST-081 FR1 and cli-surface INV30 describe. Its parts are not independently useful. A host entry without package sets, approved integrations or discover sources would ship a partial contract that hosts can't use. The size is accepted; please review the content.

@josephfarina
josephfarina dismissed astracat-bot[bot]’s stale review October 21, 2026 16:30

Maintainer decision: one PR (see the decision comment). Every other review item is resolved on 817efac.

@josephfarina
josephfarina merged commit 2e9add0 into main Oct 21, 2026
59 checks passed
@github-actions
github-actions Bot deleted the metaforge/cli-package-set-runtime branch October 22, 2026 06:22

This branch was successfully deployed

1 active deployment
Preview — 817efac1 Deployed Oct 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant