feat(cli): add examples to ao preview --help (#388)

* feat(cli): add examples to ao preview --help (#387)

Update the preview command help to include a concise Examples section
covering the four common workflows:

  ao preview
  ao preview file:///home/aoagent/ReverbCode/index.html
  ao preview http://localhost:5173
  ao preview clear

Replace the workspace-relative path (./dist/index.html) in the Long
description with the absolute file:// URL pattern agents actually use.

Command syntax and behavior are unchanged.

Closes #387

* fix(cli): clarify no-arg preview fallback behavior in help text

Address review feedback on #388: the no-argument description now
reflects the daemon's actual behavior — autodetect the workspace
entry point, fall back to the session's existing preview target
when none exists.

---------

Co-authored-by: AO Bot <ao-bot@composio.dev>
This commit is contained in:
i-trytoohard 2026-06-23 01:28:06 +05:30 committed by GitHub
parent a6ebabda68
commit 82d69ce120
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 3 deletions

View File

@ -23,9 +23,14 @@ func newPreviewCommand(ctx *commandContext) *cobra.Command {
Use: "preview [url]",
Short: "Open a URL (or the workspace's index.html) in the desktop browser panel for the current session",
Long: "Open a URL in the desktop browser panel for the current session.\n\n" +
"With no argument it opens the workspace's index.html. A workspace-relative path\n" +
"(e.g. ./dist/index.html) is served as a local file. Use `ao preview\n" +
"clear` to empty the panel.",
"With no argument it opens the workspace's static entry point, falling\n" +
"back to this session's existing preview target when no entry point exists.\n" +
"A local file can be opened by its absolute file:// URL\n" +
"(e.g. file:///home/me/proj/index.html). Use `ao preview clear` to empty the panel.",
Example: ` ao preview
ao preview file://$(pwd)/index.html
ao preview http://localhost:5173
ao preview clear`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var target string

View File

@ -154,6 +154,24 @@ func TestPreview_MissingSessionIDIsUsageError(t *testing.T) {
}
}
func TestPreview_HelpIncludesExamples(t *testing.T) {
out, _, err := executeCLI(t, Deps{}, "preview", "--help")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// Examples section present.
if !strings.Contains(out, "EXAMPLES") && !strings.Contains(out, "Examples") {
t.Errorf("help output missing Examples section:\n%s", out)
}
// file:// URL example (not a relative path).
if !strings.Contains(out, "file://$(pwd)/index.html") {
t.Errorf("help output missing file:// example:\n%s", out)
}
if strings.Contains(out, "./dist/index.html") {
t.Errorf("help output still references relative ./dist/index.html:\n%s", out)
}
}
func TestPreview_BlankSessionIDIsUsageError(t *testing.T) {
t.Setenv("AO_SESSION_ID", " \t ")
cfg := setConfigEnv(t)