Skip to content

fix(cli): route skills list output to stdout when --json is active - #60914

Merged
altaywtf merged 4 commits into
openclaw:mainfrom
altaywtf:restore/pr-57611-json-stdout
Apr 4, 2026
Merged

altaywtf merged 4 commits into
openclaw:mainfrom
altaywtf:restore/pr-57611-json-stdout

Conversation

@altaywtf

@altaywtf altaywtf commented Apr 4, 2026

Copy link
Copy Markdown
Member

Summary

Replacement for closed PR #57611.

openclaw skills list --json (and skills info --json, skills check --json) was writing JSON output to stderr instead of stdout, breaking tooling that captures stdout.

This branch includes:

  • the original runtime fix: runSkillsAction() now uses defaultRuntime.writeStdout(...)
  • added regression coverage in src/cli/skills-cli.commands.test.ts for:
    • skills list --json
    • skills info <name> --json
    • skills check --json
    • a non-JSON skills list path

Fixes #57599.

Validation

  • pnpm exec vitest run --config vitest.config.ts src/cli/skills-cli.commands.test.ts
  • live repro on the working branch showed skills list --json writing the JSON payload to stdout

Notes

PR #57611 was closed after its fork branch head was accidentally moved to the wrong commit. This PR is the clean replacement from the corrected rebased branch.

Aftabbs and others added 2 commits April 4, 2026 17:42
runSkillsAction used defaultRuntime.log() which goes through console.log.
The --json preAction hook calls routeLogsToStderr(), redirecting console.log
to stderr. Switch to defaultRuntime.writeStdout() which writes directly to
process.stdout, consistent with how other --json commands (e.g. skills search)
already emit their output.

Fixes #57599
Copilot AI review requested due to automatic review settings April 4, 2026 14:53
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S maintainer Maintainer-authored PR labels Apr 4, 2026
@greptile-apps

greptile-apps Bot commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes openclaw skills list/info/check --json (and the non-JSON variants) to write output through process.stdout.write (defaultRuntime.writeStdout) instead of console.log (defaultRuntime.log), ensuring the output is reliably capturable by tooling that intercepts the stdout stream at the process level.

The production-code change is a single line in runSkillsAction in src/cli/skills-cli.ts. The test file is expanded to add a vi.mock for ../agents/skills-status.js, wire up buildWorkspaceSkillStatusMock, and add four new test cases covering the JSON output path for list, info, and check, as well as the human-readable list path.

  • Fix (src/cli/skills-cli.ts): defaultRuntime.log(render(report)) → defaultRuntime.writeStdout(render(report)) — minimal and correct.
  • Tests (src/cli/skills-cli.commands.test.ts): Good coverage of the new routing; the runtimeStdout / runtimeLogs split in the mock makes it possible to assert which channel each output goes through. The only style concern is that the skill fixture object is defined twice — once as a createSkillStatusReport() factory inside vi.hoisted() (which is never reachable during tests because mockReset() + mockReturnValue() in beforeEach replaces the initial implementation before any test body runs) and once inline in beforeEach.

Confidence Score: 5/5

Safe to merge — a minimal, well-tested stdout routing fix with no behavior changes to non-JSON output paths.

The production change is a single-line swap of defaultRuntime.log → defaultRuntime.writeStdout in runSkillsAction. Both methods ultimately write to stdout; the distinction is console.log vs process.stdout.write, which matters for tools that capture the stream directly. The fix is self-consistent with how skills search --json already uses writeJson (which delegates to writeStdout). Regression tests are added and they correctly distinguish the two output channels via runtimeStdout vs runtimeLogs. The only finding is a duplicated fixture object that is dead code — a style issue with no runtime impact.

No files require special attention beyond the style note on the test fixture duplication in src/cli/skills-cli.commands.test.ts.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/cli/skills-cli.commands.test.ts
Line: 10-67

Comment:
**Dead factory function — skill fixture duplicated twice**

`createSkillStatusReport()` is defined inside `vi.hoisted()` and wired into `buildWorkspaceSkillStatusMock`'s initial `vi.fn()` implementation, but every test immediately calls `buildWorkspaceSkillStatusMock.mockReset()` followed by `buildWorkspaceSkillStatusMock.mockReturnValue({...})` in `beforeEach`, which completely replaces the implementation before any test body runs. As a result, the factory is never actually invoked during the test suite — its body is dead code.

The same fixture data is then written out a second time inline inside the `beforeEach` block (lines 158–193), doubling the maintenance surface.

Consider removing `createSkillStatusReport` and hoisting the shared fixture to a module-level constant instead:

```ts
// top of file, outside vi.hoisted
const CALENDAR_SKILL_FIXTURE = {
  name: "calendar",
  description: "Calendar helpers",
  // … rest of the object
};

const SKILL_STATUS_REPORT_FIXTURE = {
  workspaceDir: "/tmp/workspace",
  managedSkillsDir: "/tmp/workspace/skills",
  skills: [CALENDAR_SKILL_FIXTURE],
};
```

Then both the initial `vi.fn()` implementation and the `beforeEach` `.mockReturnValue(...)` can reference the same constant.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "test(cli): add skills JSON stdout regres..." | Re-trigger Greptile

Comment thread src/cli/skills-cli.commands.test.ts Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a CLI regression where openclaw skills <action> --json emitted its JSON payload via console.log (and therefore stderr when --json routing is active), by switching the shared runSkillsAction() output path to write directly to stdout. It also adds regression tests to ensure the skills JSON output is routed via stdout.

Changes:

  • Update runSkillsAction() to emit rendered output using defaultRuntime.writeStdout(...) instead of defaultRuntime.log(...).
  • Add regression coverage for skills list/info/check --json and a non-JSON skills list path, including stdout-vs-log expectations.
  • Extend the test runtime capture to separately track stdout output.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/cli/skills-cli.ts Routes skills command output through writeStdout to avoid stderr redirection in --json mode.
src/cli/skills-cli.commands.test.ts Adds regression tests and a stdout capture path to validate JSON output is emitted via stdout.

Comment thread src/cli/skills-cli.commands.test.ts Resolved
Comment thread src/cli/skills-cli.commands.test.ts Resolved
@altaywtf
altaywtf merged commit 5012b52 into openclaw:main Apr 4, 2026
8 checks passed
@Aftabbs

Aftabbs commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

@altaywtf noting that #56520 addresses the same Feishu re-registration symptom with a plugin-level guard. This PR fixes the root cause (schema loads should never activate the plugin registry), which prevents the issue for all channel plugins, not just Feishu. Happy to rebase or address any concerns.

@altaywtf
altaywtf deleted the restore/pr-57611-json-stdout branch April 4, 2026 18:02
@altaywtf

altaywtf commented Apr 4, 2026

Copy link
Copy Markdown
Member Author

@Aftabbs yes plese, there are some valid comments from Codex.

Aftabbs added a commit to Aftabbs/openclaw that referenced this pull request Apr 5, 2026
The skillStatusReportFixture was defined inside vi.hoisted() and also
returned from it so beforeEach could call mockReturnValue(). This
created two maintenance surfaces for the same data.

Move the fixture to a module-level constant (SKILL_STATUS_FIXTURE) so
it is defined once and referenced from both vi.hoisted() and beforeEach.
Remove the dead initial implementation from buildWorkspaceSkillStatusMock
— mockReset() in beforeEach replaced it before any test ran anyway.

Addresses Codex feedback on openclaw#60914.
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…penclaw#60914)

* fix(cli): route skills list output to stdout when --json is active

runSkillsAction used defaultRuntime.log() which goes through console.log.
The --json preAction hook calls routeLogsToStderr(), redirecting console.log
to stderr. Switch to defaultRuntime.writeStdout() which writes directly to
process.stdout, consistent with how other --json commands (e.g. skills search)
already emit their output.

Fixes openclaw#57599

* test(cli): add skills JSON stdout regression coverage

* test(cli): refine skills CLI stream coverage

* fix(cli): add changelog entry for skills JSON stdout fix

---------

Co-authored-by: Aftabbs <[email protected]>
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…penclaw#60914)

* fix(cli): route skills list output to stdout when --json is active

runSkillsAction used defaultRuntime.log() which goes through console.log.
The --json preAction hook calls routeLogsToStderr(), redirecting console.log
to stderr. Switch to defaultRuntime.writeStdout() which writes directly to
process.stdout, consistent with how other --json commands (e.g. skills search)
already emit their output.

Fixes openclaw#57599

* test(cli): add skills JSON stdout regression coverage

* test(cli): refine skills CLI stream coverage

* fix(cli): add changelog entry for skills JSON stdout fix

---------

Co-authored-by: Aftabbs <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…penclaw#60914)

* fix(cli): route skills list output to stdout when --json is active

runSkillsAction used defaultRuntime.log() which goes through console.log.
The --json preAction hook calls routeLogsToStderr(), redirecting console.log
to stderr. Switch to defaultRuntime.writeStdout() which writes directly to
process.stdout, consistent with how other --json commands (e.g. skills search)
already emit their output.

Fixes openclaw#57599

* test(cli): add skills JSON stdout regression coverage

* test(cli): refine skills CLI stream coverage

* fix(cli): add changelog entry for skills JSON stdout fix

---------

Co-authored-by: Aftabbs <[email protected]>
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
…penclaw#60914)

* fix(cli): route skills list output to stdout when --json is active

runSkillsAction used defaultRuntime.log() which goes through console.log.
The --json preAction hook calls routeLogsToStderr(), redirecting console.log
to stderr. Switch to defaultRuntime.writeStdout() which writes directly to
process.stdout, consistent with how other --json commands (e.g. skills search)
already emit their output.

Fixes openclaw#57599

* test(cli): add skills JSON stdout regression coverage

* test(cli): refine skills CLI stream coverage

* fix(cli): add changelog entry for skills JSON stdout fix

---------

Co-authored-by: Aftabbs <[email protected]>
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…penclaw#60914)

* fix(cli): route skills list output to stdout when --json is active

runSkillsAction used defaultRuntime.log() which goes through console.log.
The --json preAction hook calls routeLogsToStderr(), redirecting console.log
to stderr. Switch to defaultRuntime.writeStdout() which writes directly to
process.stdout, consistent with how other --json commands (e.g. skills search)
already emit their output.

Fixes openclaw#57599

* test(cli): add skills JSON stdout regression coverage

* test(cli): refine skills CLI stream coverage

* fix(cli): add changelog entry for skills JSON stdout fix

---------

Co-authored-by: Aftabbs <[email protected]>
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
…penclaw#60914)

* fix(cli): route skills list output to stdout when --json is active

runSkillsAction used defaultRuntime.log() which goes through console.log.
The --json preAction hook calls routeLogsToStderr(), redirecting console.log
to stderr. Switch to defaultRuntime.writeStdout() which writes directly to
process.stdout, consistent with how other --json commands (e.g. skills search)
already emit their output.

Fixes openclaw#57599

* test(cli): add skills JSON stdout regression coverage

* test(cli): refine skills CLI stream coverage

* fix(cli): add changelog entry for skills JSON stdout fix

---------

Co-authored-by: Aftabbs <[email protected]>
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…penclaw#60914)

* fix(cli): route skills list output to stdout when --json is active

runSkillsAction used defaultRuntime.log() which goes through console.log.
The --json preAction hook calls routeLogsToStderr(), redirecting console.log
to stderr. Switch to defaultRuntime.writeStdout() which writes directly to
process.stdout, consistent with how other --json commands (e.g. skills search)
already emit their output.

Fixes openclaw#57599

* test(cli): add skills JSON stdout regression coverage

* test(cli): refine skills CLI stream coverage

* fix(cli): add changelog entry for skills JSON stdout fix

---------

Co-authored-by: Aftabbs <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: skills list --json writes JSON to stderr instead of stdout since v2026.3.23

3 participants