Skip to content

shell: don't print objects by default #8990

Closed

Description

@shykes

Overview

In the context of the shell, it's no longer necessary to auto-print objects. Instead, there should be a .print and perhaps also a .json builtin, that you can easily add to the pipeline. By default, a pipeline that succeeds should simply print nothing.

Examples

No print when returning an object:

⋈ .http https://dagger.io
⋈

To learn more, .doc:

⋈ .http https://dagger.io | .doc
File

DESCRIPTION

A file.

REFERENCE

https://docs.dagger.io/api/reference/#definition-File

FUNCTIONS

  contents          Retrieves the contents of the file.
  digest            Return the file's digest. The format of the digest is not guaranteed to be stable between releases of Dagger. It is guaranteed to be stable between invocations of the same
                    Dagger engine.
  export            Writes the file to a file path on the host.
  name              Retrieves the name of the file.
  size              Retrieves the size of the file, in bytes.
  sync              Force evaluation in the engine.
  with-name         Retrieves this file with its name set to the given name.
  with-timestamps   Retrieves this file with its created/modified timestamps set to the given time.

SEE ALSO

".doc <function>" for more information on a function.

To know the type, .type:

⋈ .http https://dagger.io | .type
File

To print the contents, .print. Note the absence of _Type field, another hack we no longer need:

⋈ .http https://dagger.io | .print
digest: sha256:e37c20d68d9cf63cd164ef06220b6b7b6ea4bc98aed5cc982e3de09c2622c028
name: 78c79fe99761c116238476f0b5a6a528b621e80398bfbaaa991abe41c4942a0d
size: 838056

A special case to encode the object to JSON:

⋈ .http https://dagger.io | .json
{ 
    "digest": "sha256:e37c20d68d9cf63cd164ef06220b6b7b6ea4bc98aed5cc982e3de09c2622c028",
    "name": "78c79fe99761c116238476f0b5a6a528b621e80398bfbaaa991abe41c4942a0d",
    "size": 838056
}
⋈

Activity

  1. added
    area/cli
    on Nov 18, 2024
  2. helderco commented on Nov 19, 2024

    @helderco
    Contributor

    Is there a need for .type when that already shows in .doc? At minimum this is what .doc shows:

    ⋈ .directory | sync | .doc
    CUSTOM SCALAR
      DirectoryId

    Format:

    <KIND>
      <type>
    

    Another example

    dagger-dev ⋈ version | .doc
    SCALAR
      string
    
      Primitive type.

    Want to bikeshed .doc?

  3. helderco commented on Nov 19, 2024

    @helderco
    Contributor

    Isn't it going to be confusing if nothing happens? Let's say a new user creates a Lint function that returns a dagger.Container based on something seen elsewhere. In the CLI the first thing they may try is to call the function directly, but then nothing happens:

    my-module ⋈ lint
    my-module ⋈

    Additionally with .print, what would be the behavior on a scalar?

    dagger-dev ⋈ version | .print
  4. sourishkrout commented on Dec 20, 2024

    @sourishkrout
    Contributor

    @helderco to answer your question from #9258

    Let's discuss (in #8990) first why you need it and see if there's a better solution or if bringing that back is the best long term.

    I'm looking to integrate the Shell into Runme's notebook UX as per the video below. We already have this for the CLI, aka dagger call where under the hood, we redirect stdout to process the type information atomically. This works great which is why I'd like it back, please :-).

    {
        "_type": "File",
        "digest": "sha256:ff24da1f384a60498acdbbb9d6203cb19faa607b96d0d22f8d4d0b71fc3f5d93",
        "name": "dagger",
        "size": 29229208
    }
    
    Response.Payload.mp4

    Hires version here https://www.youtube.com/watch?v=ijEjmH6BkS0
    Notebook trace here https://gist.github.com/sourishkrout/4a1b8ee7fb31df94875bb1f9db155613

    Coming back to the original issue, it makes sense not to print "objects by default", I see a few ways of solving this:

    1. Make it optional, something like dagger shell CLI-flag or ENV var or both.
    2. The notebook kernel could run a subsequent "command" of <snippet> | .doc or <snippet> | .json to fetch type information etc. However, Runme runs cells atomically, which means 2x bootstrapping and potential latency if caching isn't practical due to late binding.
    3. Fetch the type information out-of-band, querying the API via a reliable identifier.

    Of course, I'm open to alternative proposals. However, I'd prefer running cells atomically because that's what a user will do. Please let me know if you have questions. Thanks so much for your help, @helderco.

  5. sourishkrout commented on Jan 8, 2025

    @sourishkrout
    Contributor

    Update

    @shykes & @helderco:

    I've completed an MVP implementation of the Dagger Shell into Runme (screenshot below). I've recorded a little demo here: https://www.youtube.com/watch?v=01-JF77eDhc

    Please note that merely running Dagger Shell in the notebooks works without "printing objects". However, as discussed in my previous comment, the UX integration does require getting hold of the object's type information. I'm running a custom build off #9258 to enable this.

    Pending more polish, this integration already works well and feels natural.

    Screenshot 2025-01-08 at 11 40 53 AM

    I'd love to do a live demo, e.g. at the Community Call, if you are interested.

  6. shykes commented on Jan 8, 2025

    @shykes
    ContributorAuthor

    @sourishkrout regardless of whether we add auto-printing of objects, I feel like it would be better for you not to depend so much on a "cosmetic" decision that might still change later. I'm confident there's a way for you to not care either way, and still have the cool UX integration.

    For example: if you need type information, couldn't you under the hood call <TARGET_PIPELINE> | .doc ? That will give you a complete introspection of all available functions for the returned type (including its type). At the moment it's human-readable format, but we could easily add a flag to output it in json for example, eg. .doc --json. Then you don't have to worry about parsing a _Type from the actual value - you already have all the information you need.

    wdyt?

  7. sourishkrout commented on Jan 14, 2025

    @sourishkrout
    Contributor

    @sourishkrout regardless of whether we add auto-printing of objects, I feel like it would be better for you not to depend so much on a "cosmetic" decision that might still change later. I'm confident there's a way for you to not care either way, and still have the cool UX integration.

    @shykes, 👍 agreed. Building Runme's UX integration on a stable "API" makes sense.

    For example: if you need type information, couldn't you under the hood call <TARGET_PIPELINE> | .doc ? That will give you a complete introspection of all available functions for the returned type (including its type). At the moment it's human-readable format, but we could easily add a flag to output it in json for example, eg. .doc --json. Then you don't have to worry about parsing a _Type from the actual value - you already have all the information you need.

    wdyt?

    That should work 👌 . Unlike regular POSIX-shells, e.g. bash/zsh running dagger call, Runme can deeply integrate with Dagger Shell directly. A .doc --json flag has my vote.

    Meanwhile, we'll push forward with the Dagger Shell integration into Runme's Kernel, which is not contingent on this issue.

  8. sourishkrout commented on Feb 11, 2025

    @sourishkrout
    Contributor

    Native Dagger Shell support landed in Runme's notebooks as of v3.12.0. Currently working on bringing support into the CLI so runme run EXTENSION arrives at the same artifact.

    The UX-level integration that initially connected back to this issue is currently disabled. However, I might send a draft PR to implement the .doc --json flag for discussion.

    Works great otherwise:

    Here's a video clip: https://www.youtube.com/watch?v=IKQQFVmB4UI

    Image
  9. assigned and unassigned on Feb 19, 2025
  10. shykes commented on Feb 19, 2025

    @shykes
    ContributorAuthor

    I believe @vito took this?

  11. sourishkrout commented on Feb 19, 2025

    @sourishkrout
    Contributor

    I believe @vito took this?

    Thanks, @shykes. I'm happy to help if you need anything, @vito. Just holler.

  12. sourishkrout commented on Feb 21, 2025

    @sourishkrout
    Contributor

    Update: Dagger Shell is now fully integrated and supported in both the notebook UX and Runme's CLI!

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

Metadata

Metadata

Assignees

Labels

area/cli

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions