Skip to content

feat: add apify agent status and agent uninstall commands (P1) - #1475

Open
kuntal1461 wants to merge 3 commits into
apify:masterfrom
kuntal1461:feat/agent-p1
Open

kuntal1461 wants to merge 3 commits into
apify:masterfrom
kuntal1461:feat/agent-p1

Conversation

@kuntal1461

Copy link
Copy Markdown
Contributor

Summary

  • Adds apify agent status — reads agent-state.json and shows each configured client with its tier and install date; supports --client filter and --json output
  • Adds apify agent uninstall — removes Apify MCP config from one or all configured clients, updates state file; supports --client, --yes, --json, and confirmation prompt
  • Adds removeServerEntry() to file-config.ts — JSONC-safe atomic removal counterpart to mergeServerEntry()
  • Implements uninstall handlers for all 7 clients (file-based: cursor, kiro, antigravity; CLI-based: claude-code, vscode, vscode-insiders, codex)

Stacks on top of #1471 — depends on the state/catalog infrastructure added there. Once #1471 merges, this can be rebased onto master.

Key design decisions

  • Partial-failure contract: if one client fails (e.g. binary not on PATH), it stays in state and RunFailed is set; successful clients are removed from state
  • State safety: writeAgentState is wrapped in try/catch — disk-full or permission errors produce a clear recovery message instead of silent data loss
  • Unknown clients: state entries with unrecognised client names (from a future version or hand-edited file) are skipped with an error message rather than crashing
  • Security: bearer tokens never appear in output or remain on disk after uninstall; child process stderr is captured, not inherited

Test plan

  • 45 new tests: 18 for status, 27 for uninstall
  • Covers: no-state, empty-state, --client filter, --json shape, confirmation prompt behaviour, partial failure, config file absent, security (no token leakage)
  • All 796 local tests pass

Related issues

Related to #1445

🤖 Generated with Claude Code

kuntal1461 and others added 3 commits October 5, 2026 18:08
Fixes apify#1451 (prompt hang in pseudo-TTY environments) and apify#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 apify#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 <noreply@anthropic.com>
Adds apify agent setup -- auto-detects installed AI coding agents (Claude Code, Cursor, VS Code, Kiro, Codex, Antigravity) by env var and home-path heuristics, then configures them via MCP. Includes tier ladder, idempotency via state file, --client override, --json output, and 89 tests covering unit, integration, security, and edge cases.
Implements the two remaining agent commands:
- apify agent status: reads agent-state.json, shows configured clients
  with tier and install date; supports --client filter and --json output
- apify agent uninstall: removes MCP config per client, updates state
  file; supports --client, --yes, --json; confirms before removing

New infrastructure:
- removeServerEntry() in file-config.ts: JSONC-safe atomic removal of
  a key from any mcp.json (symmetric to mergeServerEntry)
- Uninstall handlers for all 7 clients (file-based and CLI-based)
- isSupportedClient guard on state-sourced targets
- writeAgentState wrapped in try/catch for disk-full/permission errors
- Partial-failure contract: failed clients kept in state, RunFailed exit

45 tests across status (18) and uninstall (27), including security proofs,
partial-failure multi-client coverage, and empty-state edge cases.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants