Skip to content

feat: add blocks preview command to open blocks in Block Kit Builder#620

Open
WilliamBergamin wants to merge 18 commits into
mainfrom
bill-bkb-open-command
Open

feat: add blocks preview command to open blocks in Block Kit Builder#620
WilliamBergamin wants to merge 18 commits into
mainfrom
bill-bkb-open-command

Conversation

@WilliamBergamin

@WilliamBergamin WilliamBergamin commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Changelog

Add the slack blocks preview command to open Block Kit blocks in the Block Kit Builder.

Summary

This adds a new blocks preview command. It takes a set of Block Kit blocks and opens them in the Block Kit Builder in a web browser.

Blocks are passed with the --blocks flag. The value is a JSON array of blocks or a JSON object with a blocks array. Pass - to read the blocks from standard input.

The command is hidden from the help output unless an AI coding tool is detected. It is meant to be used by AI tools that generate Block Kit layouts.

Preview

(No UI change. The command prints the Builder URL and opens it in the browser.)

Testing

Build the CLI first:

make build

Then run the examples below with SLACK_DISABLE_TELEMETRY=true.

Expected to work:

  1. Preview a bare blocks array passed as a flag value.

    ./bin/slack blocks preview --blocks '[{"type":"divider"}]'
    
  2. Preview a full blocks object passed as a flag value.

    ./bin/slack blocks preview --blocks '{"blocks":[{"type":"section","text":{"type":"mrkdwn","text":"Hello"}}]}'
    
  3. Preview blocks read from a file on standard input.

    echo '[{"type":"divider"}]' > blocks.json
    ./bin/slack blocks preview --blocks - < blocks.json
    

Expected to error:

  1. Pass a value that is not valid JSON. This returns an unable_to_parse_json error.

    ./bin/slack blocks preview --blocks 'not json'
    
  2. Pass valid JSON that is not a blocks payload. This returns an invalid_blocks error.

    ./bin/slack blocks preview --blocks '{"foo":"bar"}'
    

Unit tests:

make test testdir=cmd/blocks

Notes

  • The command is gated on AI-tool detection, so it stays hidden from the normal help output and docs.
  • The URL path segment /block-kit-builder/{id}/builder was verified in an authenticated browser.

Requirements

WilliamBergamin and others added 17 commits July 20, 2026 14:43
Design for reworking `slack blocks preview` input handling (--blocks flag
with `-` stdin sentinel) and folding in the seven code-review findings.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Baseline commit of the in-progress `slack blocks preview` feature before
the input-rework and review-fix tasks. Opens Block Kit blocks in the
Block Kit Builder, gated behind the block-kit-builder experiment.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Adds Os.Stdin() and IOStreams.IsStdinTTY(), mirroring Stdout()/IsTTY(),
so callers can distinguish piped/redirected stdin from an interactive
terminal even when stdout is still a TTY.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Replaces the positional argument with a --blocks flag, supports the -
stdin sentinel and auto-detected piped stdin, and errors on a bare
interactive invocation instead of blocking forever on stdin.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Reading blocks from stdin consumes the pipe, so the interactive team
picker cannot prompt. Detect stdin input with more than one auth and no
--team flag and return an actionable error instead of failing on EOF.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
An org-grid workspace install has an enterprise ID but is not an
enterprise install; key off IsEnterpriseInstall so those installs open
the Builder in the workspace context.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Guard against empty or scheme-less hosts that would otherwise yield a
malformed URL, and wrap the url.Parse error with a structured code.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Hide the blocks command while gated behind the block-kit-builder
experiment and drop its generated doc pages, which docgen omits for
hidden commands.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Surface and allow the blocks command only when the CLI is invoked by an AI
coding tool, reusing the existing useragent.GetAIAgent detection. Replaces the
block-kit-builder experiment: the parent command is hidden from help/docs unless
an AI tool is detected, and preview's PreRunE now returns command_unavailable for
non-AI callers. Removes the BlockKitBuilder experiment.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
These agent-workflow planning artifacts under docs/superpowers/ are not part of
the shipped product and are unreferenced. Remove them from the branch.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
…tools

The blocks preview command was gated two ways on AI-coding-tool detection:
visibility (parent command Hidden) and execution (preview PreRunE returning
command_unavailable for non-AI callers). Drop the execution gate so anyone can
run the command, while keeping the visibility gate so it stays hidden from help
and docs unless an AI coding tool is detected.

Remove the now-orphaned command_unavailable error code (added by the same commit
that introduced the gate, used nowhere else) and regenerate errors.md.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Remove the auto-detected stdin pipe from blocks preview so blocks are read
from standard input only via the explicit --blocks - sentinel, matching the
prevailing convention of comparable tools (kubectl -f -, gh --input -). This
drops the one place the command diverged from those tools.

Fix the file-input example to use the sentinel form and correct the inaccurate
"piped from a file" wording (< is redirection, not a pipe), and update the
Long description and remediation text to match the new behavior.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Remove comments that restate self-explanatory function names and bodies,
and trim the rest to the non-obvious rationale. Comments-only change.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
- Guard `--blocks -` with IsStdinTTY() so an interactive terminal returns
  a clear error instead of blocking forever on stdin.
- Return ErrCredentialsNotFound when no teams are logged in, instead of
  showing an empty team prompt.
- Preserve the user's JSON key order in the Block Kit Builder URL by
  compacting the original input instead of re-marshalling the parsed value.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@WilliamBergamin WilliamBergamin self-assigned this Jul 21, 2026
@WilliamBergamin WilliamBergamin added enhancement M-T: A feature request for new functionality semver:minor Use on pull requests to describe the release version increment labels Jul 21, 2026
@WilliamBergamin
WilliamBergamin marked this pull request as ready for review July 21, 2026 22:20
@WilliamBergamin
WilliamBergamin requested review from a team as code owners July 21, 2026 22:20
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.33333% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.91%. Comparing base (2592815) to head (006f027).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/blocks/preview.go 88.80% 7 Missing and 7 partials ⚠️
internal/slackdeps/os.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #620      +/-   ##
==========================================
+ Coverage   71.78%   71.91%   +0.13%     
==========================================
  Files         227      229       +2     
  Lines       19283    19433     +150     
==========================================
+ Hits        13842    13976     +134     
- Misses       4225     4234       +9     
- Partials     1216     1223       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement M-T: A feature request for new functionality semver:minor Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant