🔧 update (cli): add --docker flag for container environments#55
🔧 update (cli): add --docker flag for container environments#55youhanasheriff wants to merge 2 commits intowarengonzaga:devfrom
Conversation
|
Hey @warengonzaga, this PR is rebased on the latest Changes from original #40:
This supersedes #40 which was auto-closed after the rebase force-push. Sorry about that! |
Add container environment detection and --docker flag to route setup to the web-based flow, preventing CLI prompts from hanging in non-TTY container environments. Changes: - Add isRunningInContainer() in detect-container.ts (shared utility) - Auto-detect Docker/CI via env vars, .dockerenv, and cgroup - Add --docker flag as alias for --web in container contexts - Show container warning in interactive setup with escape hatch - Update help text with --docker documentation
1a1fbd6 to
554d031
Compare
|
It is indeed clean! The ones that you are seeing is that bot has no access to my keys. Looks like the action here does not use the latest action from main. |
There was a problem hiding this comment.
Pull request overview
This PR adds a --docker CLI flag plus container auto-detection to route tinyclaw setup into the existing web-based setup flow, avoiding interactive prompt hangs in container/non-TTY environments.
Changes:
- Introduces
isRunningInContainer()(env vars +/.dockerenv+/proc/1/cgroup) and reuses it across CLI entry + setup command. - Adds
--dockerflag and updates CLI help text to document Docker/container behavior. - Adds unit tests for container detection logic via Bun module mocking.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/cli/src/index.ts |
Adds --docker flag + container auto-detection and routes setup to “web mode” path. |
src/cli/src/detect-container.ts |
New shared container detection helper (isRunningInContainer). |
src/cli/src/commands/setup.ts |
Adds an interactive warning/confirmation when a container environment is detected. |
src/cli/tests/detect-container.test.ts |
New unit tests covering env, /.dockerenv, and cgroup detection behaviors. |
Comments suppressed due to low confidence (1)
src/cli/src/index.ts:79
- The new
--dockerflag and container auto-detection path in the router aren’t covered by the existing CLI router tests (which already cover--help/--version/unknown command). Adding coverage fortinyclaw setup --dockerand for auto-detect (by setting env/fixtures) would help prevent regressions in this routing logic.
case 'setup': {
// Detect Docker/container environment and auto-route to web mode
const isDocker = args.includes('--docker') || isRunningInContainer();
const isWeb = args.includes('--web') || isDocker;
if (isWeb) {
// Web setup goes through supervisor so the restart mechanism works
const { supervisedStart } = await import('./supervisor.js');
await supervisedStart();
break;
}
const { setupCommand } = await import('./commands/setup.js');
await setupCommand();
break;
}
You can also share your feedback on Copilot code review. Take the survey.
|
|
||
| if (isWeb) { | ||
| // Web setup goes through supervisor so the restart mechanism works | ||
| const { supervisedStart } = await import('./supervisor.js'); |
| if (isRunningInContainer()) { | ||
| p.note( | ||
| theme.warn('Container Environment Detected') + | ||
| '\n\n' + | ||
| 'Interactive CLI setup may not work properly in Docker/containers.\n' + | ||
| 'If prompts freeze or fail, cancel and run:\n\n' + | ||
| ' ' + | ||
| theme.cmd('tinyclaw setup --docker') + | ||
| '\n\n' + | ||
| 'Or use ' + | ||
| theme.cmd('--web') + | ||
| ' for browser-based setup.', |
| // Restore original environment | ||
| process.env = { ...originalEnv }; |
|
Hey @youhanasheriff thank you for your patience for me to review this. |
warengonzaga
left a comment
There was a problem hiding this comment.
@youhanasheriff kindly check the review from copilot to see if it fits your changes.
Summary
--dockerflag that routes to web-based setup (same as--web)CI,CONTAINER,DOCKER_CONTAINERenv vars,/.dockerenvfile, and/proc/1/cgroupcontainer indicatorsisRunningInContainer()intodetect-container.ts--dockerdocumentationTesting
isRunningInContainer()returnsfalseon local macOSisRunningInContainer()returnstruewithCI=trueisRunningInContainer()returnstruewithCONTAINER=1isRunningInContainer()returnstruewithDOCKER_CONTAINER=1--dockerflag routes to web/supervisor mode--webflag still works--dockerdocumentationtinyclaw setup --dockerin a container environmentRelated Issue
Closes #12
Checklist