From c10dcefd929065c6346d6a1b14985234876381f3 Mon Sep 17 00:00:00 2001 From: kuntal1461 Date: Sat, 3 Oct 2026 03:57:36 +0530 Subject: [PATCH 1/3] feat: add global --non-interactive flag and agent env var auto-detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #1451 (prompt hang in pseudo-TTY environments) and #1354 (phantom --confirm flags). P0 — global --non-interactive flag: - New `src/lib/nonInteractiveMode.ts`: single source of truth with `isNonInteractive()`, `setNonInteractiveFlag()`, and `resetNonInteractiveFlag()` - Registered `--non-interactive` in `_buildParseArgsOption()` alongside `--help` and `--user-agent`; env var `APIFY_CLI_NON_INTERACTIVE=1` is equivalent - Activated early in `runCLI()` before version-check middleware; reset+re-applied at the start of every `_run()` for test isolation - All three divergent interactivity decision points now converge on `isNonInteractive()`: `_stdinCheckWrapper`, `create.ts`, and `detectIsInteractive()` in telemetry - Skipped prompt with no programmatic answer exits non-zero with an actionable message naming the exact flag to pass (fixes phantom `--confirm/--no-confirm` bug #1354) - Added GLOBAL OPTIONS section to main `--help` output - Added actionable `errorMessageForStdin` to previously unguarded prompts in `useActorConfig.ts` and `auth/login.ts` P1 — agent env var auto-detection and skill update: - `AGENT_ENV_VARS` (9 known agent runtimes) moved to `nonInteractiveMode.ts` and exported; `isNonInteractive()` returns true when any agent env var is set - `detectEnvironment.ts` refactored to import `AGENT_ENV_VARS` from the single source (no duplication, no circular import) - `skills/apify/SKILL.md`: added required "always pass --non-interactive" line - `test/setup.ts` + `vitest.config.ts`: global Vitest setup clears agent env vars before each test file so host environment (e.g. CLAUDECODE) does not leak into tests Co-Authored-By: Claude Sonnet 4.6 --- .gitignore | 1 + skills/apify/SKILL.md | 2 + src/commands/auth/login.ts | 6 +- src/commands/create.ts | 8 +- src/entrypoints/_shared.ts | 5 + src/lib/command-framework/apify-command.ts | 12 +++ src/lib/command-framework/help.ts | 9 ++ src/lib/hooks/telemetry/detectEnvironment.ts | 16 +--- src/lib/hooks/useActorConfig.ts | 4 + .../user-confirmations/_stdinCheckWrapper.ts | 8 +- src/lib/nonInteractiveMode.ts | 33 +++++++ test/local/lib/nonInteractive.test.ts | 91 +++++++++++++++++++ test/setup.ts | 6 ++ vitest.config.ts | 1 + 14 files changed, 180 insertions(+), 22 deletions(-) create mode 100644 src/lib/nonInteractiveMode.ts create mode 100644 test/local/lib/nonInteractive.test.ts create mode 100644 test/setup.ts diff --git a/.gitignore b/.gitignore index ae58d5467..c9bd1e449 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ package-lock.json scripts/temporary-reference.md bundles/* +docs/dev-notes/ diff --git a/skills/apify/SKILL.md b/skills/apify/SKILL.md index ffe0688ab..ae02f58ed 100644 --- a/skills/apify/SKILL.md +++ b/skills/apify/SKILL.md @@ -9,6 +9,8 @@ Run `apify -h` first to see the available commands and global options, then `api ## Non-interactive use +Always pass `--non-interactive` (or set `APIFY_CLI_NON_INTERACTIVE=1`) when driving `apify` from an agent — it forces every prompt onto the skip path regardless of terminal detection and exits non-zero when a required answer has no flag equivalent. + Many commands prompt when run interactively. To run without prompts, pass every required argument and flag explicitly: - `apify create --template