Skip to content

Conversation

@rgarcia
Copy link
Contributor

@rgarcia rgarcia commented Jan 8, 2026

Summary

Add a --payload-file / -f flag to kernel invoke that allows reading the JSON payload from a file instead of passing it inline. This is useful for:

  • Large payloads that are unwieldy on the command line
  • Payloads with special characters that need escaping
  • Scripting and automation workflows
  • Piping data from other commands

Usage

# Read payload from a file
kernel invoke myapp action -f payload.json

# Read payload from stdin
cat payload.json | kernel invoke myapp action -f -

# Pipe from another command
echo '{"key": "value"}' | kernel invoke myapp action -f -

# Combine with other tools
jq '.data' response.json | kernel invoke myapp process -f -

Details

  • The --payload and --payload-file flags are mutually exclusive (enforced by cobra)
  • Supports - as a special filename to read from stdin
  • Validates that the file contents are valid JSON before invoking
  • Trims whitespace from file contents

Test plan

  • go build ./... passes
  • go test ./... passes
  • Help output shows new flag correctly
  • Manual test: kernel invoke app action -f payload.json
  • Manual test: echo '{}' | kernel invoke app action -f -
  • Manual test: verify --payload and --payload-file cannot be used together

Note

Adds file/stdin-based payload input to kernel invoke with JSON validation and updates docs.

  • Introduces --payload-file, -f flag in invoke (mutually exclusive with --payload)
  • New getPayload helper supports reading from file or - (stdin), trims whitespace, and validates JSON before invoking
  • Wires payload into invocation params when provided; preserves existing sync/async behavior
  • README updated with new flag in command reference and examples for file/stdin/pipe usage

Written by Cursor Bugbot for commit d7205d5. This will update automatically on new commits. Configure here.

Allow reading JSON payload from a file instead of passing it inline.
Supports reading from stdin with '-' as the filename.

Examples:
  kernel invoke myapp action -f payload.json
  cat payload.json | kernel invoke myapp action -f -
  echo '{"key": "value"}' | kernel invoke myapp action -f -
Address review feedback: ensure --payload "" still explicitly sets
an empty payload, preserving the original behavior where the API
can distinguish between "no payload" and "empty payload".
Add documentation for the new --payload-file / -f flag including:
- Flag description in the commands reference
- Usage examples showing file and stdin input
@rgarcia rgarcia requested a review from hiroTamada January 8, 2026 19:21
if payloadStr != "" {
var v interface{}
if err := json.Unmarshal([]byte(payloadStr), &v); err != nil {
return "", false, fmt.Errorf("invalid JSON in payload file: %w", err)
Copy link

Choose a reason for hiding this comment

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

Misleading error message for stdin JSON validation failure

Low Severity

When reading from stdin using -f -, the JSON validation error message says "invalid JSON in payload file" which is incorrect for stdin input. The read error messages correctly differentiate between stdin and file cases (lines 243 and 249), but the JSON validation error message at line 258 is shared and uses the file-specific wording. Users piping data via stdin will see a confusing error referencing a "payload file" that doesn't exist.

Fix in Cursor Fix in Web

@rgarcia rgarcia merged commit 4570261 into main Jan 8, 2026
2 checks passed
@rgarcia rgarcia deleted the rgarcia/invoke-payload-file branch January 8, 2026 20:04
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.

3 participants