Skip to content

Conversation

@jsibbison-square
Copy link
Contributor

@jsibbison-square jsibbison-square commented Jun 27, 2025

This pull request introduces a new "Porcelain mode" feature to the goose-cli crate run command, which redirects all CLI output to stderr while only outputting the final text message to stdout.

This enables us to extract final goose output in scripts as well as pipe or chain to other commands.

Only outputting the final text message to stdout is moderately useful but this will become more useful when we add structured outputs to recipes.

Key Changes

  • upgrade bat dependency for printer so we can write to a string before printing
  • Add --porcelain option to run cli command. When present only the final txt output goes to stdout, everything else to stderr
  • Pass porcelain flag around to print statements
  • Use a new cli_println! macro to encapsulate the conditional statement directing output to stderr or stdout

Examples

Supports pipes

🐚 ~/Development/goose/porcelain jsibbison-20250627-porcelain ./target/release/goose run --porcelain -t "repeat this: Hello" | head -1 > out.txt
starting session | provider: databricks model: databricks-claude-3-7-sonnet
    logging to /.../.local/share/goose/sessions/20250630_093030.jsonl
    working directory: /.../Development/goose/porcelain
I'll repeat what you asked me to repeat:

Hello
🐚 ~/Development/goose/porcelain jsibbison-20250627-porcelain cat out.txt
I'll repeat what you asked me to repeat:

Supports tools and tool approval messages

🐚 ~/Development/goose/porcelain jsibbison-20250627-porcelain ./target/release/goose run --porcelain -t "count how many files are in this directory"  > out.txt
starting session | provider: databricks model: databricks-claude-3-7-sonnet
    logging to /.../.local/share/goose/sessions/20250630_092457.jsonl
    working directory: /.../Development/goose/porcelain
I'll count how many files are in the current directory. Let me run a command to check that for you.
─── shell | developer ──────────────────────────
command: ls -la | wc -l

◇  Goose would like to call the above tool, do you allow?
│  Allow


The output shows that there are 40 entries in the current directory. However, this count includes the "." and ".." directory entries, as well as any hidden files.

Let me get a more accurate count of just the files (excluding directories):
─── shell | developer ──────────────────────────
command: find . -maxdepth 1 -type f | wc -l

◇  Goose would like to call the above tool, do you allow?
│  Allow


There are 22 files in the current directory.

Let me also show you what these files are:
─── shell | developer ──────────────────────────
command: ls -la

◇  Goose would like to call the above tool, do you allow?
│  Allow


In summary:
- There are 22 regular files in the current directory
- There are also 17 directories (including "." and "..")
- Total entries: 39 (the output shows 40, but that might include a hidden file not shown in the listing)

The files include various configuration files (like Cargo.toml, .gitignore), documentation (README.md, CONTRIBUTING.md), and scripts.

🐚 ~/Development/goose/porcelain jsibbison-20250627-porcelain cat out.txt
In summary:
- There are 22 regular files in the current directory
- There are also 17 directories (including "." and "..")
- Total entries: 39 (the output shows 40, but that might include a hidden file not shown in the listing)

The files include various configuration files (like Cargo.toml, .gitignore), documentation (README.md, CONTRIBUTING.md), and scripts.

Chaining gooses Easier done using variables and scripts but its doable.

🐚 ~/Development/goose/porcelain jsibbison-20250627-porcelain ./target/release/goose run --porcelain -t "output only the number 3" | sed '1s/^/Double the number and output only it from the following text:\n/' | ./target/release/goose run --porcelain -i - > out.txt
starting session | provider: databricks model: databricks-claude-3-7-sonnet
    logging to /.../.local/share/goose/sessions/20250630_094944.jsonl
    working directory: /.../Development/goose/porcelain
# Number Output

3
starting session | provider: databricks model: databricks-claude-3-7-sonnet
    logging to /.../.local/share/goose/sessions/20250630_094949.jsonl
    working directory: /.../Development/goose/porcelain
I'll extract the number from the text and double it.
─── text_editor | developer ──────────────────────────
path: ~/Development/goose/porcelain
command: view



I see that I need to work directly with the text you provided rather than looking for a file. From your input, I can see:

`
# Number Output

3
`

The number is 3, and doubling it gives us:

6
🐚 ~/Development/goose/porcelain jsibbison-20250627-porcelain cat out.txt
I see that I need to work directly with the text you provided rather than looking for a file. From your input, I can see:

`
# Number Output

3
`

The number is 3, and doubling it gives us:

6

@github-actions
Copy link
Contributor

github-actions bot commented Jun 27, 2025

PR Preview Action v1.6.0

🚀 View preview at
https://block.github.io/goose/pr-preview/pr-3106/

Built to branch gh-pages at 2025-06-30 00:01 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

…rcelain

* origin/main: (26 commits)
  docs: add more instructions about resuming a session for cli users (#3146)
  add claude 4 models (#3143)
  docs: cross reference recipe docs (#3141)
  docs: add recipes tutorial (#3132)
  Docs: recipe landing page (#3122)
  Run cargo fmt (#3135)
  Update Recipe Cookbook Submission Flow (#3064)
  chore(release): release version 1.0.30 (#3126)
  blog: everyday tasks for ai (#3103)
  fix windows session paths (#3130)
  update the path regex (#3129)
  wider support for cron schedules (#3123)
  feat: add optional view_range to text editor tool and text editor insert tool (#3093)
  Added announcement modal (#3098)
  build: Add `just` to Hermit, correct ui/desktop's README (#3116)
  fix: Make the entire toolcall argument row clickable to expand (#3118)
  Fix clippy + test errors (#3120)
  Update goose help to include cli (#3095)
  add scheduler type  setting (#3119)
  Add a reference for recipes (#3099)
  ...
…rcelain

* origin/main:
  return missign npx/uvx (#3148)
@jsibbison-square jsibbison-square marked this pull request as ready for review June 30, 2025 00:31
@jsibbison-square jsibbison-square changed the title WIP: Adds run --porcelain cli option to output the final text message to stdout Adds run --porcelain cli option to output only the final text message to stdout Jun 30, 2025
@jsibbison-square jsibbison-square changed the title Adds run --porcelain cli option to output only the final text message to stdout feat: Adds run --porcelain cli option to output only the final text message to stdout Jun 30, 2025
Copy link
Collaborator

@DOsinga DOsinga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned in the slack, I don't really understand why we need this rather than just make sure that all things that are logging really go to the stderr and all things returned from the llm go to stdout. for structured output we should just make sure it is always the last line and a full json doc

@jsibbison-square
Copy link
Contributor Author

@DOsinga I've implemented the structured output as final message tool in #3188 . If that one works we can close this for now.

@jsibbison-square
Copy link
Contributor Author

Closing this for now as we've merged #3188

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.

4 participants