Core: Fix logger.logBox from being cut out by clack.taskLog relative cursor#34729
Core: Fix logger.logBox from being cut out by clack.taskLog relative cursor#34729huang-julien wants to merge 4 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRefactors clack-based task/group logging to detect external stdout writes during a root taskLog. Adds module-scope stdout-hook and contamination tracking, routes messages through clack.log when contamination is detected, and changes group handling to delegate to the underlying task.group and wrap messages via wrapTextForClack. ChangesContamination-Aware TaskLog Logging
Sequence DiagramsequenceDiagram
participant Root as Root TaskLog
participant Hook as Stdout Hook
participant Detect as Contamination Detector
participant Msg as Message Router
participant Clack as Clack Log
participant Task as Underlying Task
participant Ext as External Writer
Root->>Hook: Install stdout-write hook
Hook->>Detect: Begin tracking writes
Note over Root,Task: Normal taskLog operation
Ext->>Hook: External stdout write
Hook->>Detect: Mark contamination
Root->>Msg: Emit message
Msg->>Detect: Check contamination
alt Contaminated
Msg->>Clack: Emit via clack.log (no erase/redraw)
else Clean
Msg->>Task: Forward to underlying task/group
end
Root->>Hook: Uninstall hook on completion
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~45 minutes ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@code/core/src/node-logger/prompts/prompt-provider-clack.ts`:
- Around line 192-204: The wrapper unconditionally pops the current task log
even for nested taskLog() calls; ensure we only unwind entries this wrapper
created by tracking ownership when calling setCurrentTaskLog()/taskLog() (e.g.,
a boolean like createdCurrentLog) and only call uninstallStdoutHook(),
clearCurrentTaskLog(), and any pop from STORYBOOK_CURRENT_TASK_LOG when that
ownership flag is true; update the error and success branches (the handlers
around uninstallStdoutHook(), hasExternalStdoutWrite, task.error, task.success,
and clearCurrentTaskLog) to check this ownership flag before mutating global
state so nested calls don’t remove parent entries.
- Around line 243-269: The code currently calls setCurrentTaskLog(group) which
pushes the raw clack group onto the active-task stack and bypasses the
contamination-rerouting logic; change it to push the wrapped group (the same
wrapper used on the root path) instead of the raw group so getCurrentTaskLog()
returns the wrapped object with contamination protection—locate where
runTracked(() => task.group(title)) creates group and replace the
setCurrentTaskLog call to use the existing wrapped wrapper object (the one used
elsewhere for the root path) so subsequent message/success/error consumers go
through the contamination checks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 30c6a78d-8bbe-4aeb-aa0b-6d68488ac239
📒 Files selected for processing (2)
code/core/src/node-logger/prompts/prompt-functions.tscode/core/src/node-logger/prompts/prompt-provider-clack.ts
Package BenchmarksCommit: No significant changes detected, all good. 👏 |
What I did
This bug has been discovered within #34718
When a
prompt.taskLog(...)session is active, any direct stdout write performed during that session would be partially or fully overwritten by clack's next'sclacjk.messagecall.clack.ztaskLog tracks lines it emits itself. On
.message(), it does erase-and-redraw and on.sucess()/.error(), it erase the title region.Direct calls tro process.stoud.write from outside clack advance the real cursor invisibly, so the erase region drifts past clack's intended target and clobbers external content.
--
Before:
after:
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Caution
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake sure this PR contains one of the labels below:
Available labels
bug: Internal changes that fixes incorrect behavior.maintenance: User-facing maintenance tasks.dependencies: Upgrading (sometimes downgrading) dependencies.build: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup: Minor cleanup style change. Will not show up in release changelog.documentation: Documentation only changes. Will not show up in release changelog.feature request: Introducing a new feature.BREAKING CHANGE: Changes that break compatibility in some way with current major version.other: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/coreteam here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>Summary by CodeRabbit