Skip to content

feat(create): machine-readable --json output and hidden --origin flag - #1280

Open
l2ysho wants to merge 5 commits into
masterfrom
1238-apify-create-machine-readable-json-origin
Open

feat(create): machine-readable --json output and hidden --origin flag#1280
l2ysho wants to merge 5 commits into
masterfrom
1238-apify-create-machine-readable-json-origin

Conversation

@l2ysho

@l2ysho l2ysho commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Closes #1238. Stacked on #1278 — rebase onto master after that merges.

Makes apify create machine-readable for agents and the Console "Clone locally" handoff.

What changed

  • --json is strictly non-interactive. A missing name or --template fails before mkdir, naming the flag to pass. Gated on the flag rather than isTTY, so it errors deterministically instead of hanging on a prompt under a pty.
  • Hidden --origin console|cli (default cli) → recorded in create telemetry for the funnel.
  • stdout hygiene. apify create --json | jq used to fail on any call that didn't pass both --skip-git-init and --skip-dependency-install — i.e. the bare call agents and Console actually make. Two causes:
    • child processes inherited our stdout, putting git init and the whole installer transcript ahead of the payload. keepStdoutClean() routes child stdout to stderr, latched by the command framework for every command with enableJsonFlag.
    • @inquirer/core writes to process.stdout unless handed a context. All five prompt wrappers now render on stderr — correct independent of --json.
  • --template accepts the manifest id as well as name. 19 of 43 templates have id !== name, and the --json payload reports id, so the value the contract emitted was rejected on round-trip. The --help example was broken for the same reason.

🤖 Generated with Claude Code

@l2ysho l2ysho self-assigned this Jul 28, 2026
Base automatically changed from 1236-guided-apify-create-wizard-use-case-language-best-match-template to master August 3, 2026 09:50
l2ysho and others added 4 commits August 3, 2026 12:27
- Enable --json on `apify create`: prints { dir, actorJsonPath, template,
  source, nextSteps }. Progress/logs stay on stderr.
- Add hidden --origin console|cli flag for funnel telemetry (default cli).
- Extract buildNextSteps(), shared by the --json output and success message.
- templates ls: render the language label ("JavaScript") not the raw category.

Refs #1238

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Child process output was inherited onto the CLI's own stdout, so `git init`
and the dependency installer transcript landed ahead of the JSON payload.
`apify create --json | jq` failed on every invocation that did not pass both
--skip-git-init and --skip-dependency-install, including the bare --json call
that agents and the Console "Clone locally" handoff actually make.

Add keepStdoutClean() to route child stdout to stderr, latched by the command
framework whenever --json is set, so it covers every command with
enableJsonFlag rather than just this one call site.

Also include postCreate in the payload: 9 templates set it and two
(python-playwright, python-selenium) document hard prerequisites, so an agent
following nextSteps alone ended up with a broken Actor. Add
gitRepositoryInitialized so a failed git init is visible to machine callers.

The tests searched for the JSON among other stdout lines, which tolerated the
pollution; they now require stdout to be exactly the payload. --origin is
asserted through telemetry instead of a duplicated payload check.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@inquirer/core pipes to process.stdout unless handed a context, so every
prompt wrote its UI escape sequences and the persisted answer line to stdout.
That corrupts the payload of any command invoked with --json — reachable from
`apify create` whenever the Actor name or template is omitted, and
unconditionally when the target directory already exists.

Prompts are UI, not command output, so route all five wrappers to stderr.

Also give useSelectFromList its own errorMessageForStdin: it inherited the
confirmation default and told users to pass --confirm/--no-confirm, flags that
do not exist on any of the commands that use it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`--template` matched only the manifest `name`, but the new `--json` payload
reports the template `id` — and 19 of 43 templates have `id !== name`, so the
value the machine-readable output emits was rejected on round-trip. The
`--help` example `--template js-crawlee-cheerio` was broken for the same
reason. Resolve against either field.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@l2ysho
l2ysho force-pushed the 1238-apify-create-machine-readable-json-origin branch from eda7653 to bbf12e8 Compare August 3, 2026 10:37
@github-actions github-actions Bot added this to the 146th sprint - Tooling team milestone Aug 3, 2026
@github-actions github-actions Bot added t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics. labels Aug 3, 2026
`--json` still fell through to the interactive wizard. In a non-interactive
shell the run died late, after mkdir had already created the target directory,
with a message that named no flag: "Please provide the selection using the
command options." Under a pty — which some agent harnesses allocate — it hung
on a prompt instead, waiting for input that never arrives.

Treat --json as machine mode: a caller parsing stdout cannot answer a prompt,
so reject a missing name or template up front, above the mkdir, with a message
that names what to pass. Gating on the flag rather than on isTTY keeps the
failure deterministic regardless of how the caller was spawned.

The existing-directory branch reprompted for a new name, which emitted a
second, redundant error under --json; it now throws the first one.

This closes all four prompts in the create path — use-case and language are
filters, unreachable once --template is required. Interactive behavior is
unchanged; both gates are conditional on the flag. --json on create is
unreleased, so no consumer can break.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@l2ysho
l2ysho marked this pull request as ready for review August 4, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apify create machine-readable output (--json, --origin)

2 participants