Repository navigation
feat(exec): add --json for machine-readable results - #237
KhaiTrang1995 wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
`colab exec` exits 0 after a kernel error and prints an ANSI-coloured traceback, so a script or AI agent driving the CLI can only detect a failed run by scraping text. `colab exec --json` prints one JSON object per executed cell on stdout (NDJSON) with `status`, `stdout`, `stderr`, `data`, `images` and `error`. Tracebacks are plain text without ANSI escapes, images are saved to disk and reported by path instead of inlined as base64, `[colab]` progress lines go to stderr, and the exit status is 1 when any cell failed. The flag is opt-in: without it, output and exit status are unchanged.
b6696b6 to
c1ebb60
Compare
|
@googlebot I signed it! |
|
Hi maintainers, the CLA is signed and the check is green now. I know CONTRIBUTING.md says external PRs aren't being accepted at the moment, so no pressure to review this. I opened it mainly to show a concrete proposal: If you'd rather discuss this in Discussions first, or want a different shape (e.g. only the non-zero exit code), I'm happy to move it there or rework it. Feel free to close this if it doesn't fit your plans. One caveat: I have not run the end-to-end check on a live Colab session yet; only the unit tests. |
Summary
Add
colab exec --json, which prints one JSON object per executed cell soscripts and AI agents can tell whether code succeeded without scraping text.
Problem
colab execexits 0 after a kernel error and prints an ANSI-colouredtraceback. A caller driving the CLI cannot detect a failed run from the exit
status, and has to parse coloured text to find the error.
Solution
With
--json:cell_index,cell_id,status,stdout,stderr,data,images,error.error.tracebackis plain text with ANSI escapes removed.--output-image) and reported by path,never inlined as base64.
[colab]progress lines go to stderr.Example:
Compatibility
Opt-in. Without
--json, output and exit status are unchanged (covered bytest_exec_without_json_still_exits_zero_on_kernel_error). No newdependencies.
Changes
commands/execution.py:--jsonoption,build_json_record.utils.py: splitsave_imageout ofhandle_image(no behaviour change).tests/test_exec_json.py: 7 new tests, written first.docs/02_execution_and_interactive.md,skills/colab-operator/SKILL.md.Testing
pytest: new tests pass; no new failures in the existing suiteruff checkandruff format.py,.ipynb, a failingcell, a plot)
Out of scope
--jsonforstatus/sessions, and live streaming of partial output.