Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c6eb2a7
fix(function): --code and a secret's --value read @file and -
Bradenream Dec 1, 2026
17a6d7b
fix(function): function check exits 6 when a case didn't pass
Bradenream Dec 1, 2026
1126bbe
fix(cli): a flag given two different values is refused, not cut to th…
Bradenream Dec 1, 2026
fe10130
fix(document): a bare --overwrite means true
Bradenream Dec 1, 2026
14fc4f1
fix(agent): --strict fails a write whose {tokens} didn't bind
Bradenream Dec 1, 2026
0e6541e
fix(environment): diff says the global prompt isn't compared, not "No…
Bradenream Dec 1, 2026
2a7e333
fix(document): update --wait shows the outcome, and its answer carrie…
Bradenream Dec 1, 2026
228c433
fix(ui): a spinner's frame fits the terminal, so it doesn't leave a l…
Bradenream Dec 1, 2026
d6ed577
fix(document): a rate-limited URL says try again later, and a 409 "st…
Bradenream Dec 1, 2026
63af29a
fix(knowledge-base): help and the home menu lead to the commands that…
Bradenream Dec 1, 2026
c9a0e38
fix(conversation): send and knowledge-base query talk to the draft un…
Bradenream Dec 1, 2026
d1f3f23
fix(document): the list table names each document's folder, and folde…
Bradenream Dec 1, 2026
312594f
fix(errors): a command too long for the line has a line of its own, w…
Bradenream Dec 1, 2026
1f611d7
fix(output): hints, forms, runs, values and docs pages break between …
Bradenream Dec 1, 2026
028b01a
fix(help): wrapped help keeps its two columns at a narrow terminal
Bradenream Dec 1, 2026
2be15c1
fix(output): a narrow table keeps the ID, the name and what says what…
Bradenream Dec 1, 2026
5286176
fix(help): a described JSON flag says what JSON it takes
Bradenream Dec 1, 2026
835005d
fix(help): function create and update show what the code looks like
Bradenream Dec 1, 2026
43d5be2
fix(output): document list at a terminal is a line per document
Bradenream Dec 1, 2026
133bf0b
fix(widget): the snippet warns when the widget serves an old version
Bradenream Dec 1, 2026
3ddd042
feat(agent): add-playbook and remove-playbook route a playbook to the…
Bradenream Dec 1, 2026
6a5894f
fix(output): a read vf's types can't hold prints as Voiceflow sent it
Bradenream Dec 1, 2026
c440352
feat(environment): export saves a whole environment as JSON
Bradenream Dec 1, 2026
a8e0871
fix(cli): a missing-flag hint repeats the flags typed, and shows an e…
Bradenream Dec 1, 2026
0d89c85
fix(cli): a stray-word hint offers the whole line, with the flags typed
Bradenream Dec 1, 2026
a6b5a1e
fix(cli): "Did you mean" for a misspelt command or flag is the whole …
Bradenream Dec 1, 2026
7264ea8
fix(output): a create's Next lines give every flag their command requ…
Bradenream Dec 1, 2026
9cde97b
fix(conversation): a stale turn's warning says what vf did, not what …
Bradenream Dec 1, 2026
83bd0b7
fix(cli): a missing-flag hint's list and command line run as written
Bradenream Dec 1, 2026
0d2d2ca
fix(output): Next and not-found lines give every flag their command r…
Bradenream Dec 1, 2026
ee86c7c
test(cli): every command vf suggests runs as written
Bradenream Dec 1, 2026
e7527c7
Merge braden/sweep-r5 into braden/sweep-r6: vet.sh skips module downl…
Bradenream Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Worth knowing before you script against the CLI:

- **`--version-param draft` runs what you are editing; `published` runs the live version.** A new project is created with a first release already in place, so either works immediately — you do not have to publish anything first.
- **`--action '{"type":"launch"}'` is optional.** Sending a `text` action straight away works; the runtime starts the conversation itself. The launch step is shown because it makes the first turn explicit.
- **A conversation with the draft runs your latest edits.** The draft runs as last compiled, so vf compiles it before `conversation run-script` and before a `send` that starts a conversation: a `launch` action, or any message to a user ID with no conversation going (new, or its last one ended; vf reads the user's state to tell). A later turn runs the build as it is. If that turn ran an older build (you edited mid-conversation), vf compiles right after it and warns, so the next turn runs the edits; a new `--user-id` runs them at once. `--no-compile` talks to the last build as it is; the published version is never compiled.
- **A conversation with the draft runs your latest edits.** The draft runs as last compiled, so vf compiles it before `conversation run-script` and before a `send` that starts a conversation: a `launch` action, or any message to a user ID with no conversation going (new, or its last one ended; vf reads the user's state to tell). A later turn runs the build as it is. If that turn ran an older build (you edited mid-conversation), vf compiles right after it and warns. To be sure a conversation runs your edits, start a new one: a new `--user-id`, or `vf conversation state delete` to reset the user's. `--no-compile` talks to the last build as it is; the published version is never compiled.
- **Pass `--output-format json` explicitly when piping.** Inside AI coding agents (`CLAUDECODE`, `CURSOR_AGENT`, …) the default output is TOON, not JSON.
- **Capture values with `--jq`**: `ID=$(vf project create … --jq .project.id)`. A string result prints raw, as `jq -r` prints it; anything else prints as JSON.
- **`vf whoami` is offline** — it shows which credential source is configured but does not validate the token. `vf workspace list` is the real check.
Expand Down Expand Up @@ -896,10 +896,12 @@ Each kind of failure has its own exit code, so a script can tell them apart with
| `3` | Authentication: not signed in, no token, HTTP 401, an expired session |
| `4` | Not found: HTTP 404 |
| `5` | Timed out: `--timeout`, or a wait's `--max-wait` ran out with runs still going |
| `6` | A test run didn't pass: `test run wait`, `test run wait-suite`, `test run create-suite --wait` |
| `6` | A test run didn't pass: `test run wait`, `test run wait-suite`, `test run create-suite --wait`; or a case of `function check` didn't |

`vf --help` lists them too.

A write whose `{token}` names no variable or entity, or whose backticked mention names no attached tool, still succeeds: it keeps them as text, exits `0`, and its answer lists them in `unresolvedReferences` and `unresolvedMentions`. `--strict` on `agent update`, `playbook create`, `prompt update` and the other commands that write such text makes it exit `1` instead, with `error_type` `unresolved_references`, after the answer prints. The change is saved either way, so don't run a create again because of it.

In agent mode, and with `-o json` or `--jq`, an error is printed to stderr as one JSON object, with the same keys whether vf found the problem itself or the API answered with it:

| Key | When | Meaning |
Expand Down
1 change: 1 addition & 0 deletions internal/cli/agent/patchinstructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func initPatchInstructionsCmd(parent *cobra.Command) error {
Aliases: []string{"pi"},
}
flagutil.RegisterFlags(cmd, patchInstructionsCmdMeta)
flagutil.ReadsText(cmd, "old-string", "new-string") // flagutil/textfile.go: @file and - read the text
if err := flagutil.ValidateMeta[operations.StableAgentControllerPatchInstructionsV2Request](patchInstructionsCmdMeta); err != nil {
return fmt.Errorf("invalid metadata for patch-instructions: %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions internal/cli/agent/patchprompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func initPatchPromptCmd(parent *cobra.Command) error {
Aliases: []string{"pp"},
}
flagutil.RegisterFlags(cmd, patchPromptCmdMeta)
flagutil.ReadsText(cmd, "old-string", "new-string") // flagutil/textfile.go: @file and - read the text
if err := flagutil.ValidateMeta[operations.StableAgentControllerPatchPromptV2Request](patchPromptCmdMeta); err != nil {
return fmt.Errorf("invalid metadata for patch-prompt: %w", err)
}
Expand Down
326 changes: 326 additions & 0 deletions internal/cli/agent/playbookroute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,326 @@
// This file is not generated by Speakeasy. It adds `vf agent add-playbook`
// and `vf agent remove-playbook`, which route a playbook to the agent and
// stop routing it, as add-workflow and remove-workflow do for workflows.
//
// `playbook create` makes a playbook the agent can't reach: the agent hands
// off only to the playbooks in its own list. The only way to add one was
// `agent update --playbooks '<the whole list>'`, which replaces the list, so
// a tester's Returns playbook sat unrouted and nothing said so.
//
// The API has an endpoint for one workflow but none for one playbook. So
// these commands read the agent's playbooks (one GET), add or drop the one
// named, and send the list back in one `agent update` (PATCH). Every other
// entry goes back as read, with its description, condition and required
// variables, and nothing else on the agent is sent. add-playbook's
// --description defaults to the playbook's own description, read with one
// more GET. A dry run shows the read and says what the write would send.

package agent

import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"strings"

"github.com/spf13/cobra"

"github.com/voiceflow/cli/internal/client"
"github.com/voiceflow/cli/internal/flagutil"
"github.com/voiceflow/cli/internal/interactive"
"github.com/voiceflow/cli/internal/output"
"github.com/voiceflow/cli/internal/sdk"
"github.com/voiceflow/cli/internal/sdk/models/components"
"github.com/voiceflow/cli/internal/sdk/models/operations"
"github.com/voiceflow/cli/internal/usage"
)

// readModifyWrite is what both commands' help says of how they work.
const readModifyWrite = " The API has no endpoint for one playbook, so vf reads the agent's playbooks, " +
"changes that one entry and writes the list back with one agent update: every other entry is kept as read, " +
"and nothing else on the agent changes. An edit made to the list between the read and the write is lost."

// addPlaybookRequest is what add-playbook sends for: the entry to add, and
// where.
type addPlaybookRequest struct {
ProjectID string
EnvironmentAlias string
Body components.StableAgentUpdateRequestV2Playbook
}

// removePlaybookRequest names the entry remove-playbook drops, and where.
type removePlaybookRequest struct {
PlaybookID string
ProjectID string
EnvironmentAlias string
}

var addPlaybookCmdMeta = []flagutil.FlagMeta{
{FlagName: "project-id", Shorthand: "p", FieldPath: "ProjectID", Kind: flagutil.FlagKindString, Required: true, Description: "[required]"},
{FlagName: "environment-alias", Shorthand: "e", FieldPath: "EnvironmentAlias", Kind: flagutil.FlagKindString, Required: true, Description: "[required]"},
{FlagName: "playbook-id", FieldPath: "Body.PlaybookID", Kind: flagutil.FlagKindString, Required: true, Description: "The playbook to add. Copy its ID from 'vf playbook list'. [required]"},
{FlagName: "description", FieldPath: "Body.Description", Kind: flagutil.FlagKindString, Optional: true, Description: "When the agent should hand off to this playbook. The agent reads it to choose between its playbooks and workflows. Leave it out to use the playbook's own description."},
{FlagName: "condition", Shorthand: "c", FieldPath: "Body.Condition", Kind: flagutil.FlagKindJSON, Optional: true, Annotations: `json:"condition,omitempty"`, Description: "The agent can hand off to the playbook only while this condition holds. Leave it out for a playbook it can always use."},
{FlagName: "required-variables", Shorthand: "r", FieldPath: "Body.RequiredVariables", Kind: flagutil.FlagKindJSON, Optional: true, Annotations: `json:"requiredVariables,omitempty"`, Description: "Variables the agent fills from the conversation before it hands off, each with a description of what it holds."},
}

var removePlaybookCmdMeta = []flagutil.FlagMeta{
{FlagName: "playbook-id", FieldPath: "PlaybookID", Kind: flagutil.FlagKindString, Required: true, Description: "The playbook to stop routing to. [required]"},
{FlagName: "project-id", Shorthand: "p", FieldPath: "ProjectID", Kind: flagutil.FlagKindString, Required: true, Description: "[required]"},
{FlagName: "environment-alias", Shorthand: "e", FieldPath: "EnvironmentAlias", Kind: flagutil.FlagKindString, Required: true, Description: "[required]"},
}

// addPlaybookRouting gives the agent group add-playbook and remove-playbook.
// Their metadata is fixed, so a mistake in it is a bug any test that builds
// the commands finds.
func addPlaybookRouting(parent *cobra.Command) {
add := &cobra.Command{
Use: "add-playbook",
Short: "Add agent playbook",
Long: "Add one playbook to the main agent's playbooks, so the agent can hand off to it. Rejected when the list already has it." +
readModifyWrite,
Example: " vf agent add-playbook --project-id <id> --environment-alias <value> --playbook-id <id> --description 'Use when the customer wants to return an item'",
RunE: runAddPlaybookCmd,
Aliases: []string{"ap"},
}
flagutil.RegisterFlags(add, addPlaybookCmdMeta)
mustValidate(flagutil.ValidateMeta[addPlaybookRequest](addPlaybookCmdMeta))
add.Flags().String("body", "", "Request body as JSON (alternative to individual flags). Can also be provided via stdin.")
parent.AddCommand(add)

remove := &cobra.Command{
Use: "remove-playbook",
Short: "Remove agent playbook",
Long: "Remove one playbook from the main agent's playbooks. The playbook itself is not deleted." + readModifyWrite,
Example: " vf agent remove-playbook --playbook-id <id> --project-id <id> --environment-alias <value>",
RunE: runRemovePlaybookCmd,
Aliases: []string{"rp"},
}
flagutil.RegisterFlags(remove, removePlaybookCmdMeta)
mustValidate(flagutil.ValidateMeta[removePlaybookRequest](removePlaybookCmdMeta))
parent.AddCommand(remove)

// `agent update --playbooks` said what the list does but not its shape.
for _, c := range parent.Commands() {
if f := c.Flags().Lookup("playbooks"); c.Name() == "update" && f != nil {
f.Usage += ` For example: '[{"playbookID":"<id>","description":"<when to hand off>"}]'. 'vf agent add-playbook' adds one without resending the list.`
}
}
}

func mustValidate(err error) {
if err != nil {
panic("agent playbook routing: " + err.Error())
}
}

func runAddPlaybookCmd(cmd *cobra.Command, args []string) error {
if usage.UsageRequested(cmd) {
return usage.EmitSchema(cmd, cmd.OutOrStdout())
}
if interactive.ShouldPrompt(cmd, addPlaybookCmdMeta) {
if err := interactive.PromptAndSetFlags(cmd, addPlaybookCmdMeta); err != nil {
return err
}
}
req, err := flagutil.BuildRequest[addPlaybookRequest](cmd, addPlaybookCmdMeta, "Body", "body")
if err != nil {
return err
}
s, opts, err := playbookClient(cmd)
if err != nil {
return err
}
entry := req.Body
list, err := routedPlaybooks(cmd, s, opts, req.ProjectID, req.EnvironmentAlias)
if err != nil {
return err
}
if client.IsDryRun(cmd) {
return previewWrite(cmd, "the agent's playbooks plus this one", entry)
}
for _, p := range list {
if p.PlaybookID == entry.PlaybookID {
return refuse(cmd, "already_routed", "Playbook "+entry.PlaybookID+" is already one of the agent's playbooks",
"`vf agent get --project-id "+req.ProjectID+" --environment-alias "+req.EnvironmentAlias+"` shows its entry",
"To change it, remove it with `vf agent remove-playbook`, then add it again")
}
}
if entry.Description == nil {
entry.Description = playbookDescription(cmd, s, opts, entry.PlaybookID, req.ProjectID, req.EnvironmentAlias)
}
list = append(list, entry)
return writePlaybooks(cmd, s, opts, req.ProjectID, req.EnvironmentAlias, list,
fmt.Sprintf("Playbook %s added to the agent's playbooks (%d in all).", entry.PlaybookID, len(list)))
}

func runRemovePlaybookCmd(cmd *cobra.Command, args []string) error {
if usage.UsageRequested(cmd) {
return usage.EmitSchema(cmd, cmd.OutOrStdout())
}
if interactive.ShouldPrompt(cmd, removePlaybookCmdMeta) {
if err := interactive.PromptAndSetFlags(cmd, removePlaybookCmdMeta); err != nil {
return err
}
}
req, err := flagutil.BuildRequest[removePlaybookRequest](cmd, removePlaybookCmdMeta, "", "")
if err != nil {
return err
}
s, opts, err := playbookClient(cmd)
if err != nil {
return err
}
list, err := routedPlaybooks(cmd, s, opts, req.ProjectID, req.EnvironmentAlias)
if err != nil {
return err
}
if client.IsDryRun(cmd) {
return previewWrite(cmd, "the agent's playbooks minus "+req.PlaybookID, nil)
}
kept := make([]components.StableAgentUpdateRequestV2Playbook, 0, len(list))
for _, p := range list {
if p.PlaybookID != req.PlaybookID {
kept = append(kept, p)
}
}
if len(kept) == len(list) {
return refuse(cmd, "not_found", "Playbook "+req.PlaybookID+" isn't one of the agent's playbooks",
"`vf agent get --project-id "+req.ProjectID+" --environment-alias "+req.EnvironmentAlias+"` lists the playbooks it routes to")
}
return writePlaybooks(cmd, s, opts, req.ProjectID, req.EnvironmentAlias, kept,
fmt.Sprintf("Playbook %s removed from the agent's playbooks (%d left).", req.PlaybookID, len(kept)))
}

// playbookClient is the SDK client and call options every request here
// uses. Bodies are read here, not by the SDK.
func playbookClient(cmd *cobra.Command) (*sdk.VoiceflowSDK, []operations.Option, error) {
s, err := client.NewClient(cmd)
if err != nil {
return nil, nil, err
}
opts, err := output.PrepareCallOpts(cmd)
if err != nil {
return nil, nil, err
}
if err := output.ValidateGlobalServerIndex(cmd, len(sdk.ServerList)); err != nil {
return nil, nil, err
}
return s, append(opts, operations.WithSkipDeserialization()), nil
}

// routedPlaybooks reads the agent's playbooks, each as the update takes it.
// An entry vf can't read stops the command, so none is dropped.
func routedPlaybooks(cmd *cobra.Command, s *sdk.VoiceflowSDK, opts []operations.Option, projectID, alias string) ([]components.StableAgentUpdateRequestV2Playbook, error) {
ctx := client.WithSpinnerMessage(cmd.Context(), "Reading the agent's playbooks…")
res, err := s.Agent.Get(ctx, operations.StableAgentControllerGetV2Request{ProjectID: projectID, EnvironmentAlias: alias}, opts...)
if err != nil {
return nil, output.Error(cmd, err)
}
if client.IsDryRun(cmd) {
return nil, nil
}
var read struct {
Agent struct {
Playbooks []json.RawMessage `json:"playbooks"`
} `json:"agent"`
}
if !readBody(res.HTTPMeta.Response, &read) {
return nil, unreadable(cmd, "the agent's answer")
}
list := make([]components.StableAgentUpdateRequestV2Playbook, 0, len(read.Agent.Playbooks)+1)
for i, raw := range read.Agent.Playbooks {
var p components.StableAgentUpdateRequestV2Playbook
if err := json.Unmarshal(raw, &p); err != nil || p.PlaybookID == "" {
return nil, unreadable(cmd, fmt.Sprintf("entry %d of its playbooks (%s)", i, cut(string(raw))))
}
list = append(list, p)
}
return list, nil
}

// playbookDescription is the playbook's own description, or nil when it has
// none or can't be read: the update then says why, if it matters.
func playbookDescription(cmd *cobra.Command, s *sdk.VoiceflowSDK, opts []operations.Option, playbookID, projectID, alias string) *string {
ctx := client.WithSpinnerMessage(cmd.Context(), "Reading the playbook's description…")
res, err := s.Playbook.Get(ctx, operations.StablePlaybookControllerGetV2Request{PlaybookID: playbookID, ProjectID: projectID, EnvironmentAlias: alias}, opts...)
if err != nil || res == nil {
return nil
}
var read struct {
Playbook struct {
Description *string `json:"description"`
} `json:"playbook"`
}
if !readBody(res.HTTPMeta.Response, &read) || read.Playbook.Description == nil || strings.TrimSpace(*read.Playbook.Description) == "" {
return nil
}
return read.Playbook.Description
}

// writePlaybooks sends list as the agent's playbooks, and prints the
// update's answer with said as its message.
func writePlaybooks(cmd *cobra.Command, s *sdk.VoiceflowSDK, opts []operations.Option, projectID, alias string, list []components.StableAgentUpdateRequestV2Playbook, said string) error {
res, err := s.Agent.Update(cmd.Context(), operations.StableAgentControllerUpdateV2Request{
ProjectID: projectID, EnvironmentAlias: alias,
Body: components.StableAgentUpdateRequestV2{Playbooks: list},
}, opts...)
if err != nil {
return output.Error(cmd, err)
}
answer := map[string]any{}
_ = readBody(res.HTTPMeta.Response, &answer)
for k, v := range answer {
if items, ok := v.([]any); ok && len(items) == 0 {
delete(answer, k) // no unresolved references or mentions
}
}
answer["message"] = said
return output.Result(cmd, answer)
}

// previewWrite ends a dry run: the read was shown, and the write sends
// what it would have read, changed as what says.
func previewWrite(cmd *cobra.Command, what string, entry any) error {
w := cmd.ErrOrStderr()
fmt.Fprintf(w, "[DRY-RUN] Then would send: PATCH /v2/stable/agent, with playbooks set to %s\n", what)
if entry != nil {
if data, err := json.MarshalIndent(entry, " ", " "); err == nil {
fmt.Fprintf(w, "[DRY-RUN] Body: the playbooks read, then\n %s\n", data)
}
}
fmt.Fprintln(w, "[DRY-RUN] Network call skipped.")
return nil
}

// refuse stops the command before it writes anything.
func refuse(cmd *cobra.Command, kind, title string, next ...string) error {
return output.Report(cmd, output.Explanation{Type: kind, Title: title, Why: []string{"Nothing was changed."}, Next: next}, errors.New(title))
}

// unreadable stops the command when vf can't read the playbooks it would
// write back.
func unreadable(cmd *cobra.Command, what string) error {
return refuse(cmd, "unexpected_response", "vf couldn't read "+what+", so it changed nothing",
"`vf agent update --playbooks` sets the whole list: `vf agent get -o json` shows the current one")
}

// cut shortens s for a message.
func cut(s string) string {
if r := []rune(s); len(r) > 80 {
return string(r[:80]) + "…"
}
return s
}

// readBody decodes the body the SDK left unread.
func readBody(res *http.Response, v any) bool {
if res == nil || res.Body == nil {
return false
}
defer res.Body.Close()
data, err := io.ReadAll(res.Body)
return err == nil && json.Unmarshal(data, v) == nil
}
2 changes: 2 additions & 0 deletions internal/cli/agent/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func InitAgentRoot(parent *cobra.Command) error {
return err
}

addPlaybookRouting(AgentCmd) // playbookroute.go: add-playbook and remove-playbook, which the API has no endpoint for

parent.AddCommand(AgentCmd)
return nil
}
Loading
Loading