From 979d9a3679cd88816c2c672e7077d61da77d8728 Mon Sep 17 00:00:00 2001 From: cvince Date: Wed, 2 Dec 2026 04:17:13 +0000 Subject: [PATCH] CAP-983: always show the conversation link, even when Keep opens it itself Vincent, 2026-12-02: the agent always returns the conversation link. opens_in_keep stays as information; the 45-second CONVERSATION_NOT_OPENED_IN_KEEP fallback is removed because the link is already shown. --- docs/cli-reference.md | 3 +- src/commands/setupConversation.ts | 32 +++----------------- src/conversation/recovery.ts | 4 +-- src/core/agentsBlockPlan.ts | 2 +- src/types/index.ts | 1 - src/ui/elicitation.ts | 2 +- tests/conversation/setupConversation.test.ts | 26 +++------------- 7 files changed, 14 insertions(+), 56 deletions(-) diff --git a/docs/cli-reference.md b/docs/cli-reference.md index 112e15c8..302064a8 100644 --- a/docs/cli-reference.md +++ b/docs/cli-reference.md @@ -1334,7 +1334,6 @@ Every refusal carries a stable `code` — branch on it, never on message text. - `SETUP_INTENT_REQUIRED` - `CONVERSATION_OPEN` - `CONVERSATION_WAITING` -- `CONVERSATION_NOT_OPENED_IN_KEEP` - `CONVERSATION_STEP_DONE` - `CONVERSATION_STEP_REPEATED` - `CONVERSATION_AGENT_NEEDED` @@ -1392,4 +1391,4 @@ Every refusal carries a stable `code` — branch on it, never on message text. - **Codes**: Branch only on the machine-readable `code` field (from --json output or a CapyError), never on human-readable message text — messages may be reworded without notice. - **Conflicts**: Every command that writes from a folder (edit, add, remove, connect, rotate, push, checkout, org, deploy, deploy revoke, deploy targets-remove) runs bare `capy` first; `checkout -b` is the one exception (a new branch carries the uncommitted values of the folder). Off a terminal, if the folder and Capy differ on any variable, nothing is written, the exit code is 3, and stdout is {ok:false, code:"SECRETS_CONFLICT", conflict_id, conflicts:[{name, project, branch, type, pinned, local, remote}]} (fingerprints only, never values; a Dokploy value has {name, target, pinned, local, remote}). Folder-only rows omit pinned and list their available choices. Choosing an absent side removes that name. Ask the person to select from the choices for each row, then rerun the same command with --resolve NAME= for every row (NAME@TARGET=local|remote for a Dokploy value) and --conflict . A state that moved since is SECRETS_CONFLICT_STALE with the fresh rows. There is no resolve-all. `secrets set` and `secrets deploy` take the same --resolve and --conflict for a location that changed since its row was listed. - **Organizations**: These commands work on an organization, not on a folder, and run with no project folder: users, grant-branch, revoke-branch, invite, kick, projects, projects rename --project-id, project create, project delete, project restore, secrets, secrets set, secrets deploy, system. The organization is the one in the keep.lock of the folder when it has one, else the only organization the account belongs to. With several organizations, no keep.lock and nobody to ask, `users --json`, `projects rename` and `project create|delete|restore` refuse with ORG_SELECTION_REQUIRED (exit 3), `orgs:[{id, name}]` and a form asking which; each of those commands takes `--org `, which picks among the account's own organizations only. -- **Elicitation**: A refusal with exit code 3 can carry an `elicitation` next to its `code`: a question for the human, never for you. Write `display` (a markdown table) in your reply exactly as given, without shortening or reordering it and never inside the question. Then ask the short `question` as an elicitation with your question tool: one question per field, every field of the form together in one go (never one, then the next), using the field's own `question` followed by its `description` when it has them, and its `options` or `default` as the choices; without a question tool, end your reply with the `question` and the human answers in chat. `capy setup` adds two things to each of its stops (CAP-940): a form's `instructions`, written from its own fields (ask them all together, list a field with more choices than your question tool holds in chat as text, run `answer.rerun` at once), and `next`, the steps still to come (pairing, the Set up step, the project questions, the finished setup), so you never stop to ask whether to go on; follow both. kind "confirm" is a yes/no ({kind, question, details, display, answer:{yes}}): ask the human; on yes, run the command in `answer.yes`; on no, stop. kind "form" asks for values ({kind, question, details, display, fields:[{name, type, pattern, question?, default?, description?, options?:[{value, label, description?}], other?}], answer:{rerun}}): ask the human for each field, then run `answer.rerun` with the values filled in. A field with `options` is a choice: offer its `options` (the human picks a `label`, with its `description` under it, and you fill in its `value`), plus "Other" when it has `other: true`. A field without `options` is typed in: with a `default`, offer the `default` and "Other"; with no `default`, leave it out of the question tool and ask its `question` in chat, in the same reply as the other questions. A choice with exactly one option and no `other` is already decided (CAP-978): show it as chosen (its label), do not ask it, and fill its `value` into the rerun. A typed field that only offers its `default` gets "Cancel" too; never pick that answer for the human. On "Other", ask the field's `question` in chat and fill in what the human types, as typed; if your question tool adds its own free-text "Other", that is the "Other" choice, so never add a second. On "Cancel", stop. A field with more choices than your question tool holds (4, counting "Other" and "Cancel"), or one with a label or description your question tool can't show word for word, goes in chat instead: list every choice, its label then its description, and let the human answer there. Never shorten, reword, reorder or drop a choice. On a `capy setup` form each field also has `ask`, these rules already applied: ask it where `ask.in` says (`question_tool` or `chat`, and in chat when your question tool can't show it word for word; `decided` is shown as chosen and never asked) with exactly `ask.choices`, in order and word for word; a choice's `then` is "type_in_chat" for "Other" and "stop" for "Cancel"; `default: true` marks the default, which you may show as recommended but never pick. `details` holds names and ids only, never a value. Today: `capy project restore` without --yes refuses with CONFIRMATION_REQUIRED and a confirm (details: {org:{id,name}, project:{id,name,deleted_at}}); `capy project delete` without --yes refuses with CONFIRMATION_REQUIRED and a confirm (details: {org:{id,name}, project:{id,name}, branches:[name], variables:[{name, branches:[name]}], live_deploy_tokens:[{deploy_id, label}], unavailable?:["branches"|"variables"]}); `capy project create` missing the name, `--branch` or `--protected` in agent mode refuses with PROJECT_NAME_REQUIRED, BRANCH_NAME_REQUIRED or BRANCH_PROTECTION_REQUIRED and a form (fields: name, branch, protected (options yes/no); details: {org:{id,name}}); `capy project delete` / `project restore` with a name several projects share refuses with PROJECT_AMBIGUOUS and a form with one `project` field whose options are the projects (details: {org:{id,name}, matches:[{id, name, created_at, variables}]}); `capy kick ` without --yes refuses with CONFIRMATION_REQUIRED and a confirm (details: {org:{id,name}, member:{email}}); `capy projects rename` with no name refuses with PROJECT_NAME_REQUIRED and a form with one `name` field (details: {org:{id,name}, project:{id,name}}); `capy secrets set` / `capy secrets deploy` with a project that is linked to more than one repo refuses with PR_REPO_AMBIGUOUS and a form with one field per such project whose options are its repos (details: {projects:[{id, name, repos:[owner/name[/folder]]}]}); pass the same `--pr-repo` again on the run with `--confirm`. `capy branch -D NAME` without --yes in agent mode refuses with CONFIRMATION_REQUIRED and a confirm (details: {branch:{name}}); `capy remove NAME...` without --yes refuses with REMOVE_NEEDS_TTY and a confirm (details: {branch, variables:[name], removing_all}); `capy system rm NAME` without --yes refuses with SYSTEM_STORE_NEEDS_TTY and a confirm (details: {name, org?}); `capy connect vercel|dokploy` with --overwrite or --discover and without --yes refuses with VERCEL_CONFIRMATION_REQUIRED or DOKPLOY_CONFIRMATION_REQUIRED (exit 3) and a confirm whose `display` lists the terminal's lines (details: {import, replace, clear} or {folders}); `capy connect vercel` with nobody to ask refuses with VERCEL_TEAM_REQUIRED (form, one `team` field whose options are the team slugs; details: {teams:[{id, slug}]}), VERCEL_PROJECT_REQUIRED (form, one typed `project` field; details: {}) or VERCEL_ENVIRONMENT_REQUIRED (form, one `environment` field whose options are the environments; details: {branch, environments:[name]}), all exit 3; `capy connect dokploy` refuses with DOKPLOY_TARGET_AMBIGUOUS (form, one `target` field: each option's label is a saved target and its value that target's flags; details: {targets:[name]}) or DOKPLOY_SETTINGS_MISSING (form asking only what is missing: `base_url`, then `source` (option values `--application` / `--compose`) and `service_id`; details: {}); fill the values into `answer.rerun` as they are. With nobody at a terminal, these picks refuse with a form of one field whose options are the terminal's choices (exit 3): `capy rotate` with no variable, ROTATE_VARIABLE_REQUIRED (field `variable`; details: {branch, variables}); `capy rotate VAR` for an unmanaged variable with several integrations, ROTATE_PROVIDER_REQUIRED (field `provider`; details: {variable, providers}); `capy invite` for a role that needs project access, INVITE_PROJECT_REQUIRED (field `project`, one project; details: {role, projects:[{id, name}]}); `capy connect stripe` with several accounts, STRIPE_ACCOUNT_REQUIRED (field `account`; details: {accounts:[{name, account_id}]}); `capy connect stripe|workos` when the key's variable is unclear, CONNECTOR_VAR_REQUIRED (field `var`; details: {branch, variables}). `capy rotate` has no --json, so its `answer.rerun` ends with --non-tty. A command that works on an organization (users, projects, project create|delete|restore, projects rename, secrets, invite, kick, grant-branch, revoke-branch) with several organizations, no keep.lock and no --org refuses with ORG_SELECTION_REQUIRED (exit 3) and a form with one `org` field whose options are the org ids labelled by name (details: {orgs:[{id, name}]}); its rerun adds --org. `capy agents` (or `capy agents --remove`) without --yes in agent mode refuses with AGENTS_SETUP_NEEDS_TTY and a confirm asking the terminal's question (details: {files:[{path, action}]}); `capy checkout NAME -b --json` without --protected or --no-protected refuses with BRANCH_PROTECTION_REQUIRED and a form with one `protected` field whose option values are the flags `--protected` and `--no-protected` (details: {branch:{name}}); its `answer.rerun` uses --non-tty, because `-b --json` only describes the route. kind "link" hands the human a page to approve on ({kind, url, code, fingerprint?, purpose, expires_at, qr?:{text?, image?:{mime_type, file, data_uri?}}, instructions, answer:{wait}}): write the `url` as a clickable link, with the `code`, the `fingerprint` (the page shows the same one) and `expires_at`, as plain text, every time a link is shown (the `qr`, as `conventions.pairing` says, is only an addition, never the only way), then run `answer.wait` at once in the foreground (it can take up to 9 minutes, so give it a tool timeout of at least 10 minutes), and run it again whenever it exits 3 with PAIR_STILL_WAITING or your tool stopped it early; when it exits 3 with PAIR_LINK_RENEWED the old link expired and the elicitation is a new link: show it to the human the same way and run its `answer.wait` again. Its `instructions` say the same. Pass `--title` and `--description` to `capy pair` and `capy setup`: your own words for what you are doing and why, which Keep shows the human on the unlock request; `capy setup` refuses to start a pairing without them (SETUP_INTENT_REQUIRED, exit 1, with `next_command`). Today `capy pair` in agent mode asks nothing up front (no email, no keys choice: on a machine with no keys it asks for them, and Keep decides after sign-in between the organization keys and a new organization); it refuses with PAIR_APPROVAL_PENDING and a link; once the human approves, the wait refuses with PAIR_CODE_REQUIRED (or PAIR_CODE_MISMATCH after a wrong code) and a form (field: code; details: {attempts_left?}) for the one-time code Keep shows the human; never fill in the code yourself. Bare `capy` in a folder that is not a project, in agent mode, with questions left refuses with INIT_INPUT_REQUIRED and one form that asks only what is unanswered: first, alone, folder when no --folder was typed (options: this folder and every subfolder that holds a .env or a package file, those with a .env first, each option's description saying which it holds, with `other`; when there are more choices than your question tool takes, list every option with its description in chat and let the human answer there, never dropping one; the rerun adds --folder), then org (options: the organizations; asked before the project questions when there are several, with only share beside it), then the Set up step when no --choice was typed (CAP-941: when a choice that creates a project fits, the same form also asks that new project's `name` and first `branch`, and `share` inside Git, so there is one round trip after the code; `details.new_project_fields` names them; they are used only by `existing` and `new`, and a rerun with `--choice import` ignores `--name`, and ignores `--branch` until the project to link is answered, so it asks the project and then its branch; question "What would you like Capy to set up?"; field `choice` offers only the choices that fit: `existing` "Create project from folder" when the .env has secrets, `new` "Create a new Capy project" when it has none, `import` "Use existing Capy project" (link this folder to a project that already exists) when the organization has a project, and `skip` "Skip for now"; when only one fits, `choice` is a field with that one option, already decided (`ask.in` is `decided`): show it as chosen and never ask it; fields `discover` ("Discover application services") and `deployments` ("Manage secrets deployments"), options yes/no, default yes; CAP-960: when the folder's package.json has local scripts (dev, test and the like) also `run_scripts` ("Run your scripts with your encrypted variables"), options yes/no, default yes, its description naming the scripts (`details.scripts`); yes changes each to start with `capy run --`, never build, deploy or install scripts, and the rerun adds --run-scripts; encrypting the .env is always on and is never a field, `details.always.encrypt_line` says it; answering the step is the yes to encrypting, so no separate encrypt question follows; the rerun adds --choice, --discover and --deployments (and --run-scripts when asked); `skip` creates nothing, leaves the .env as it is and ends with `skipped: true` (`capy setup` then returns `setup: "skipped"` and writes no AGENTS block); a --choice that does not fit refuses with SETUP_CHOICE_UNAVAILABLE (exit 3, `extra.choices` lists the ones that fit: ask the human again with those); a --choice, --discover or --deployments that is not one of its values refuses with SETUP_CHOICE_INVALID or SETUP_SCOPE_INVALID; the result carries `setup_choice` and `scope`), project (for `import` only; options: the existing projects), then for a new project (`existing` or `new`) name (its default is a free name: the folder's, or the first free `-2` to `-9`; a name that turns out to be taken refuses with PROJECT_NAME_EXISTS, exit 3, and the same form asking only `name`, its `display` saying the name is taken: ask the human again and run its `answer.rerun`) and branch (its protection is not asked: the first branch starts open, as in the terminal, unless --protected was typed), and for an existing project branch (options: that project's branches, never chosen for the human even when there is one), or, when that project has no branches yet, branch for its first one (default development; the rerun creates it open to the project); and, inside a git repository, share (options yes: "Sync through Capy and Git", no: "Sync through Capy"; the rerun adds --share-setup); a typed --encrypt-env no still creates nothing and leaves the .env as it is; while folder is asked its `display` only names the folder Capy runs in; otherwise its `display` is the whole summary, so after the human answers, run `answer.rerun` with no further confirmation (details: {folder?, org?, orgs?, projects?, project?, branches?, new_project_fields?, variables}; `variables` is a count). Never answer it yourself and never add --yes on your own. A finished setup can carry `warnings`, each with a `code`, a `message` and a `next` step (today ENV_IN_GIT_HISTORY: the .env was committed to Git, so its old values are still in the history; and GITIGNORE_NOT_COMMITTED: the .gitignore is left out of the commit of a shared setup (and of `git.files`), because it has changes Capy did not make): tell the human each `message` and its `next` step in your reply, and never act on it for them. CAP-960: a finished setup carries `run` ({command, message, note?}): the .env now holds ciphertext, so tell the human `message` and `command` (the command that starts the app with the decrypted .env, or null), and `note` when there is one; start the app, its tests and anything that reads the .env only that way. `scripts` ({file, wrapped, skipped}) lists the package.json scripts Capy changed; in a shared setup package.json is in `git.files` when Capy's change is its only one. CAP-971: discovery is yours. A finished setup whose Set up step looks for services or deployments carries `discover` in place of `summary`: follow its `instructions`. CAP-954: in agent mode Capy commits nothing and runs no gh. A setup shared through Git ("Sync through Capy and Git") ends with `git`: `folder`, `files`, `commit_message`, `branch`, `base`, `pull_request` ({title, body}, or null with `--pr no` or no origin), `instructions` and `commands`. Follow its `instructions` with your own Git access and access to the Git host: commit exactly `files` in `folder` with `commit_message`, open `pull_request` on `base` from `branch` so it holds only those files (push the commit as `branch` only when its parent is the head of `base` on origin, else make `branch` from `base` on origin); Capy pull requests stack: with an open pull request from a `capy/` branch, open it on the newest open `capy/` branch that no other open pull request is based on, and show the human its link. Never change Git settings or identity yourself; if Git has no name or email, ask the human to set theirs. Without Git tools, run `commands` in `folder` exactly as given. `capy setup --conversation --json` asks those folder questions in a Keep conversation instead (CAP-921): it refuses with CONVERSATION_OPEN (exit 3) and a link whose `purpose` is "conversation" (show its url, fingerprint and expiry the same way, and its `preview` steps; CAP-983: except when its `opens_in_keep` is true, which means Keep is opening the conversation by itself in the tab where the human approved pairing: then do not show the link, tell the human to continue in Keep, and if a wait refuses with CONVERSATION_NOT_OPENED_IN_KEEP (exit 3, with the link as its `elicitation`) show that link the same way then), then run `answer.wait` (`capy setup --wait --folder --flow --json`, which finds the conversation from any folder) at once and again on every exit 3. When Keep can't hold the conversation, `capy setup --conversation` refuses with CONVERSATION_ASK_IN_CHAT (exit 3, `extra.conversation_unavailable.reason`: not_signed_in, no_transport_record, no_local_key or refused) and the same question it would have asked: tell the human its `message`, then ask the question in chat as above; its `answer.rerun` keeps `--conversation`, so the next step tries Keep again. On a machine that must pair first, the pairing's commands keep `--conversation`, so the questions go to Keep once it is paired. Waits: CONVERSATION_WAITING means nothing new yet; CONVERSATION_STEP_DONE means the human answered a step in Keep (`step`, `answered_in: "keep"`, `answers`, `goals`): show it as done in one line and run the wait again. Never end your turn between waits while the conversation is open: run `answer.wait` again at once after every exit 3. Nothing is lost if a wait ends or your tool stops it: answers given in Keep while no wait runs are kept and returned by the next wait. To reconnect from a fresh session, run `capy setup --wait --json` in the same folder (add `--flow ` only when more than one conversation is open there), or `capy setup --conversation --json` there, which hands back the open conversation's link with `resumed: true`. CAP-977: CONVERSATION_STEP_REPEATED (exit 1, `shown_in_keep: true`, `step`) means setup asked the human the exact question they had just answered; it was not posted again, Keep shows the step as failed, and the answers are kept: tell the human in one line and report it as a Capy bug, never answer it yourself. The finished setup has `conversation.code` CONVERSATION_DONE. `goals` lists every step with its status. Add `--note -` to the wait to show the human a plain-text note in Keep (piped on stdin, at most 2,000 characters, no links; it is echoed back as `note`), and `--cancel` to end the conversation. CAP-957: one wait (280 seconds by default) runs on through every step the human answers in Keep (run it in the foreground with a tool timeout of at least 6 minutes) and returns early only at the end, at a stop, or when its time is up; CONVERSATION_STEP_DONE then lists every step answered during it in `steps`. Every stop reaches Keep. A refused answer given in Keep is asked again in Keep, so you only see a wait. Any other stop comes to you as its own refusal with `shown_in_keep: true` and `answer.wait`: Keep has already told the human that this step stopped, so tell them its `message` and next step in one line, then run `answer.wait` again once it is done; the conversation carries on from its saved answers. Running `capy setup --conversation` again in a folder whose conversation is still open hands back the same link with `resumed: true`: show it again and run its `answer.wait`. You never answer a question asked in Keep, and you never see a key or a sealed record. +- **Elicitation**: A refusal with exit code 3 can carry an `elicitation` next to its `code`: a question for the human, never for you. Write `display` (a markdown table) in your reply exactly as given, without shortening or reordering it and never inside the question. Then ask the short `question` as an elicitation with your question tool: one question per field, every field of the form together in one go (never one, then the next), using the field's own `question` followed by its `description` when it has them, and its `options` or `default` as the choices; without a question tool, end your reply with the `question` and the human answers in chat. `capy setup` adds two things to each of its stops (CAP-940): a form's `instructions`, written from its own fields (ask them all together, list a field with more choices than your question tool holds in chat as text, run `answer.rerun` at once), and `next`, the steps still to come (pairing, the Set up step, the project questions, the finished setup), so you never stop to ask whether to go on; follow both. kind "confirm" is a yes/no ({kind, question, details, display, answer:{yes}}): ask the human; on yes, run the command in `answer.yes`; on no, stop. kind "form" asks for values ({kind, question, details, display, fields:[{name, type, pattern, question?, default?, description?, options?:[{value, label, description?}], other?}], answer:{rerun}}): ask the human for each field, then run `answer.rerun` with the values filled in. A field with `options` is a choice: offer its `options` (the human picks a `label`, with its `description` under it, and you fill in its `value`), plus "Other" when it has `other: true`. A field without `options` is typed in: with a `default`, offer the `default` and "Other"; with no `default`, leave it out of the question tool and ask its `question` in chat, in the same reply as the other questions. A choice with exactly one option and no `other` is already decided (CAP-978): show it as chosen (its label), do not ask it, and fill its `value` into the rerun. A typed field that only offers its `default` gets "Cancel" too; never pick that answer for the human. On "Other", ask the field's `question` in chat and fill in what the human types, as typed; if your question tool adds its own free-text "Other", that is the "Other" choice, so never add a second. On "Cancel", stop. A field with more choices than your question tool holds (4, counting "Other" and "Cancel"), or one with a label or description your question tool can't show word for word, goes in chat instead: list every choice, its label then its description, and let the human answer there. Never shorten, reword, reorder or drop a choice. On a `capy setup` form each field also has `ask`, these rules already applied: ask it where `ask.in` says (`question_tool` or `chat`, and in chat when your question tool can't show it word for word; `decided` is shown as chosen and never asked) with exactly `ask.choices`, in order and word for word; a choice's `then` is "type_in_chat" for "Other" and "stop" for "Cancel"; `default: true` marks the default, which you may show as recommended but never pick. `details` holds names and ids only, never a value. Today: `capy project restore` without --yes refuses with CONFIRMATION_REQUIRED and a confirm (details: {org:{id,name}, project:{id,name,deleted_at}}); `capy project delete` without --yes refuses with CONFIRMATION_REQUIRED and a confirm (details: {org:{id,name}, project:{id,name}, branches:[name], variables:[{name, branches:[name]}], live_deploy_tokens:[{deploy_id, label}], unavailable?:["branches"|"variables"]}); `capy project create` missing the name, `--branch` or `--protected` in agent mode refuses with PROJECT_NAME_REQUIRED, BRANCH_NAME_REQUIRED or BRANCH_PROTECTION_REQUIRED and a form (fields: name, branch, protected (options yes/no); details: {org:{id,name}}); `capy project delete` / `project restore` with a name several projects share refuses with PROJECT_AMBIGUOUS and a form with one `project` field whose options are the projects (details: {org:{id,name}, matches:[{id, name, created_at, variables}]}); `capy kick ` without --yes refuses with CONFIRMATION_REQUIRED and a confirm (details: {org:{id,name}, member:{email}}); `capy projects rename` with no name refuses with PROJECT_NAME_REQUIRED and a form with one `name` field (details: {org:{id,name}, project:{id,name}}); `capy secrets set` / `capy secrets deploy` with a project that is linked to more than one repo refuses with PR_REPO_AMBIGUOUS and a form with one field per such project whose options are its repos (details: {projects:[{id, name, repos:[owner/name[/folder]]}]}); pass the same `--pr-repo` again on the run with `--confirm`. `capy branch -D NAME` without --yes in agent mode refuses with CONFIRMATION_REQUIRED and a confirm (details: {branch:{name}}); `capy remove NAME...` without --yes refuses with REMOVE_NEEDS_TTY and a confirm (details: {branch, variables:[name], removing_all}); `capy system rm NAME` without --yes refuses with SYSTEM_STORE_NEEDS_TTY and a confirm (details: {name, org?}); `capy connect vercel|dokploy` with --overwrite or --discover and without --yes refuses with VERCEL_CONFIRMATION_REQUIRED or DOKPLOY_CONFIRMATION_REQUIRED (exit 3) and a confirm whose `display` lists the terminal's lines (details: {import, replace, clear} or {folders}); `capy connect vercel` with nobody to ask refuses with VERCEL_TEAM_REQUIRED (form, one `team` field whose options are the team slugs; details: {teams:[{id, slug}]}), VERCEL_PROJECT_REQUIRED (form, one typed `project` field; details: {}) or VERCEL_ENVIRONMENT_REQUIRED (form, one `environment` field whose options are the environments; details: {branch, environments:[name]}), all exit 3; `capy connect dokploy` refuses with DOKPLOY_TARGET_AMBIGUOUS (form, one `target` field: each option's label is a saved target and its value that target's flags; details: {targets:[name]}) or DOKPLOY_SETTINGS_MISSING (form asking only what is missing: `base_url`, then `source` (option values `--application` / `--compose`) and `service_id`; details: {}); fill the values into `answer.rerun` as they are. With nobody at a terminal, these picks refuse with a form of one field whose options are the terminal's choices (exit 3): `capy rotate` with no variable, ROTATE_VARIABLE_REQUIRED (field `variable`; details: {branch, variables}); `capy rotate VAR` for an unmanaged variable with several integrations, ROTATE_PROVIDER_REQUIRED (field `provider`; details: {variable, providers}); `capy invite` for a role that needs project access, INVITE_PROJECT_REQUIRED (field `project`, one project; details: {role, projects:[{id, name}]}); `capy connect stripe` with several accounts, STRIPE_ACCOUNT_REQUIRED (field `account`; details: {accounts:[{name, account_id}]}); `capy connect stripe|workos` when the key's variable is unclear, CONNECTOR_VAR_REQUIRED (field `var`; details: {branch, variables}). `capy rotate` has no --json, so its `answer.rerun` ends with --non-tty. A command that works on an organization (users, projects, project create|delete|restore, projects rename, secrets, invite, kick, grant-branch, revoke-branch) with several organizations, no keep.lock and no --org refuses with ORG_SELECTION_REQUIRED (exit 3) and a form with one `org` field whose options are the org ids labelled by name (details: {orgs:[{id, name}]}); its rerun adds --org. `capy agents` (or `capy agents --remove`) without --yes in agent mode refuses with AGENTS_SETUP_NEEDS_TTY and a confirm asking the terminal's question (details: {files:[{path, action}]}); `capy checkout NAME -b --json` without --protected or --no-protected refuses with BRANCH_PROTECTION_REQUIRED and a form with one `protected` field whose option values are the flags `--protected` and `--no-protected` (details: {branch:{name}}); its `answer.rerun` uses --non-tty, because `-b --json` only describes the route. kind "link" hands the human a page to approve on ({kind, url, code, fingerprint?, purpose, expires_at, qr?:{text?, image?:{mime_type, file, data_uri?}}, instructions, answer:{wait}}): write the `url` as a clickable link, with the `code`, the `fingerprint` (the page shows the same one) and `expires_at`, as plain text, every time a link is shown (the `qr`, as `conventions.pairing` says, is only an addition, never the only way), then run `answer.wait` at once in the foreground (it can take up to 9 minutes, so give it a tool timeout of at least 10 minutes), and run it again whenever it exits 3 with PAIR_STILL_WAITING or your tool stopped it early; when it exits 3 with PAIR_LINK_RENEWED the old link expired and the elicitation is a new link: show it to the human the same way and run its `answer.wait` again. Its `instructions` say the same. Pass `--title` and `--description` to `capy pair` and `capy setup`: your own words for what you are doing and why, which Keep shows the human on the unlock request; `capy setup` refuses to start a pairing without them (SETUP_INTENT_REQUIRED, exit 1, with `next_command`). Today `capy pair` in agent mode asks nothing up front (no email, no keys choice: on a machine with no keys it asks for them, and Keep decides after sign-in between the organization keys and a new organization); it refuses with PAIR_APPROVAL_PENDING and a link; once the human approves, the wait refuses with PAIR_CODE_REQUIRED (or PAIR_CODE_MISMATCH after a wrong code) and a form (field: code; details: {attempts_left?}) for the one-time code Keep shows the human; never fill in the code yourself. Bare `capy` in a folder that is not a project, in agent mode, with questions left refuses with INIT_INPUT_REQUIRED and one form that asks only what is unanswered: first, alone, folder when no --folder was typed (options: this folder and every subfolder that holds a .env or a package file, those with a .env first, each option's description saying which it holds, with `other`; when there are more choices than your question tool takes, list every option with its description in chat and let the human answer there, never dropping one; the rerun adds --folder), then org (options: the organizations; asked before the project questions when there are several, with only share beside it), then the Set up step when no --choice was typed (CAP-941: when a choice that creates a project fits, the same form also asks that new project's `name` and first `branch`, and `share` inside Git, so there is one round trip after the code; `details.new_project_fields` names them; they are used only by `existing` and `new`, and a rerun with `--choice import` ignores `--name`, and ignores `--branch` until the project to link is answered, so it asks the project and then its branch; question "What would you like Capy to set up?"; field `choice` offers only the choices that fit: `existing` "Create project from folder" when the .env has secrets, `new` "Create a new Capy project" when it has none, `import` "Use existing Capy project" (link this folder to a project that already exists) when the organization has a project, and `skip` "Skip for now"; when only one fits, `choice` is a field with that one option, already decided (`ask.in` is `decided`): show it as chosen and never ask it; fields `discover` ("Discover application services") and `deployments` ("Manage secrets deployments"), options yes/no, default yes; CAP-960: when the folder's package.json has local scripts (dev, test and the like) also `run_scripts` ("Run your scripts with your encrypted variables"), options yes/no, default yes, its description naming the scripts (`details.scripts`); yes changes each to start with `capy run --`, never build, deploy or install scripts, and the rerun adds --run-scripts; encrypting the .env is always on and is never a field, `details.always.encrypt_line` says it; answering the step is the yes to encrypting, so no separate encrypt question follows; the rerun adds --choice, --discover and --deployments (and --run-scripts when asked); `skip` creates nothing, leaves the .env as it is and ends with `skipped: true` (`capy setup` then returns `setup: "skipped"` and writes no AGENTS block); a --choice that does not fit refuses with SETUP_CHOICE_UNAVAILABLE (exit 3, `extra.choices` lists the ones that fit: ask the human again with those); a --choice, --discover or --deployments that is not one of its values refuses with SETUP_CHOICE_INVALID or SETUP_SCOPE_INVALID; the result carries `setup_choice` and `scope`), project (for `import` only; options: the existing projects), then for a new project (`existing` or `new`) name (its default is a free name: the folder's, or the first free `-2` to `-9`; a name that turns out to be taken refuses with PROJECT_NAME_EXISTS, exit 3, and the same form asking only `name`, its `display` saying the name is taken: ask the human again and run its `answer.rerun`) and branch (its protection is not asked: the first branch starts open, as in the terminal, unless --protected was typed), and for an existing project branch (options: that project's branches, never chosen for the human even when there is one), or, when that project has no branches yet, branch for its first one (default development; the rerun creates it open to the project); and, inside a git repository, share (options yes: "Sync through Capy and Git", no: "Sync through Capy"; the rerun adds --share-setup); a typed --encrypt-env no still creates nothing and leaves the .env as it is; while folder is asked its `display` only names the folder Capy runs in; otherwise its `display` is the whole summary, so after the human answers, run `answer.rerun` with no further confirmation (details: {folder?, org?, orgs?, projects?, project?, branches?, new_project_fields?, variables}; `variables` is a count). Never answer it yourself and never add --yes on your own. A finished setup can carry `warnings`, each with a `code`, a `message` and a `next` step (today ENV_IN_GIT_HISTORY: the .env was committed to Git, so its old values are still in the history; and GITIGNORE_NOT_COMMITTED: the .gitignore is left out of the commit of a shared setup (and of `git.files`), because it has changes Capy did not make): tell the human each `message` and its `next` step in your reply, and never act on it for them. CAP-960: a finished setup carries `run` ({command, message, note?}): the .env now holds ciphertext, so tell the human `message` and `command` (the command that starts the app with the decrypted .env, or null), and `note` when there is one; start the app, its tests and anything that reads the .env only that way. `scripts` ({file, wrapped, skipped}) lists the package.json scripts Capy changed; in a shared setup package.json is in `git.files` when Capy's change is its only one. CAP-971: discovery is yours. A finished setup whose Set up step looks for services or deployments carries `discover` in place of `summary`: follow its `instructions`. CAP-954: in agent mode Capy commits nothing and runs no gh. A setup shared through Git ("Sync through Capy and Git") ends with `git`: `folder`, `files`, `commit_message`, `branch`, `base`, `pull_request` ({title, body}, or null with `--pr no` or no origin), `instructions` and `commands`. Follow its `instructions` with your own Git access and access to the Git host: commit exactly `files` in `folder` with `commit_message`, open `pull_request` on `base` from `branch` so it holds only those files (push the commit as `branch` only when its parent is the head of `base` on origin, else make `branch` from `base` on origin); Capy pull requests stack: with an open pull request from a `capy/` branch, open it on the newest open `capy/` branch that no other open pull request is based on, and show the human its link. Never change Git settings or identity yourself; if Git has no name or email, ask the human to set theirs. Without Git tools, run `commands` in `folder` exactly as given. `capy setup --conversation --json` asks those folder questions in a Keep conversation instead (CAP-921): it refuses with CONVERSATION_OPEN (exit 3) and a link whose `purpose` is "conversation" (show its url, fingerprint and expiry the same way, and its `preview` steps; CAP-983: when its `opens_in_keep` is true, Keep is also opening the conversation by itself in the tab where the human approved pairing: still show the link, and say Keep should open it by itself), then run `answer.wait` (`capy setup --wait --folder --flow --json`, which finds the conversation from any folder) at once and again on every exit 3. When Keep can't hold the conversation, `capy setup --conversation` refuses with CONVERSATION_ASK_IN_CHAT (exit 3, `extra.conversation_unavailable.reason`: not_signed_in, no_transport_record, no_local_key or refused) and the same question it would have asked: tell the human its `message`, then ask the question in chat as above; its `answer.rerun` keeps `--conversation`, so the next step tries Keep again. On a machine that must pair first, the pairing's commands keep `--conversation`, so the questions go to Keep once it is paired. Waits: CONVERSATION_WAITING means nothing new yet; CONVERSATION_STEP_DONE means the human answered a step in Keep (`step`, `answered_in: "keep"`, `answers`, `goals`): show it as done in one line and run the wait again. Never end your turn between waits while the conversation is open: run `answer.wait` again at once after every exit 3. Nothing is lost if a wait ends or your tool stops it: answers given in Keep while no wait runs are kept and returned by the next wait. To reconnect from a fresh session, run `capy setup --wait --json` in the same folder (add `--flow ` only when more than one conversation is open there), or `capy setup --conversation --json` there, which hands back the open conversation's link with `resumed: true`. CAP-977: CONVERSATION_STEP_REPEATED (exit 1, `shown_in_keep: true`, `step`) means setup asked the human the exact question they had just answered; it was not posted again, Keep shows the step as failed, and the answers are kept: tell the human in one line and report it as a Capy bug, never answer it yourself. The finished setup has `conversation.code` CONVERSATION_DONE. `goals` lists every step with its status. Add `--note -` to the wait to show the human a plain-text note in Keep (piped on stdin, at most 2,000 characters, no links; it is echoed back as `note`), and `--cancel` to end the conversation. CAP-957: one wait (280 seconds by default) runs on through every step the human answers in Keep (run it in the foreground with a tool timeout of at least 6 minutes) and returns early only at the end, at a stop, or when its time is up; CONVERSATION_STEP_DONE then lists every step answered during it in `steps`. Every stop reaches Keep. A refused answer given in Keep is asked again in Keep, so you only see a wait. Any other stop comes to you as its own refusal with `shown_in_keep: true` and `answer.wait`: Keep has already told the human that this step stopped, so tell them its `message` and next step in one line, then run `answer.wait` again once it is done; the conversation carries on from its saved answers. Running `capy setup --conversation` again in a folder whose conversation is still open hands back the same link with `resumed: true`: show it again and run its `answer.wait`. You never answer a question asked in Keep, and you never see a key or a sealed record. diff --git a/src/commands/setupConversation.ts b/src/commands/setupConversation.ts index 8196567b..c0683cee 100644 --- a/src/commands/setupConversation.ts +++ b/src/commands/setupConversation.ts @@ -34,8 +34,6 @@ import { timedWait } from '../utils/timingLog'; */ export const DEFAULT_WAIT_SECONDS = 280; export const MAX_WAIT_SECONDS = 300; -/** CAP-983 (spec 3o rule 7): how long a wait gives Keep's pairing tab to open the conversation before the link is shown. */ -export const KEEP_OPEN_SECONDS = 45; export interface ConversationIdentity { readonly userId: string; @@ -271,14 +269,14 @@ export async function openSetupConversation(question: Refusal, deps: Conversatio /** The conversation's link, as the agent shows it (CONVERSATION_OPEN, exit 3). */ function linkRefusal(state: ConversationState, goals: readonly Goal[], deps: ConversationSetupDeps, bin: string, resumed: boolean): ConversationOutcome { const fingerprint = conversationFingerprint(state.k); - // CAP-983 (spec 3o): the tab that approved pairing is waiting and opens this conversation itself; a resumed one keeps its link. + // CAP-983 (spec 3o): the tab that approved pairing is waiting and opens this conversation itself. The link is still shown (Vincent, 2026-12-02). const opensInKeep = !resumed && state.opensInKeep === true; return refusal({ code: ERROR_CODES.CONVERSATION_OPEN, message: resumed ? 'Setup for this folder is already open in Keep, so it carries on there. Show the human the link again, then run `answer.wait` at once and again whenever it exits 3.' // COPY-FLAG : opensInKeep - ? 'Keep is opening setup by itself in the tab where the human approved pairing. Do not post the link. Tell the human to continue in Keep, then run `answer.wait` at once and again whenever it exits 3.' // COPY-FLAG + ? 'Keep is opening setup by itself in the tab where the human approved pairing. Still show the human the link, in case that tab is closed, then run `answer.wait` at once and again whenever it exits 3.' // COPY-FLAG : 'Setup continues in Keep. Show the human the link, then run `answer.wait` at once and again whenever it exits 3.', // COPY-FLAG exitCode: 3, extra: { @@ -292,7 +290,7 @@ function linkRefusal(state: ConversationState, goals: readonly Goal[], deps: Con expires_at: state.openBy, opens_in_keep: opensInKeep, instructions: opensInKeep - ? 'Keep opens this by itself in the tab where the human approved pairing. Show the link only if a wait refuses with CONVERSATION_NOT_OPENED_IN_KEEP.' // COPY-FLAG + ? 'Keep opens this by itself in the tab where the human approved pairing. If it does not, open this link to answer the setup questions in Keep. Keep shows the same fingerprint.' // COPY-FLAG : 'Open this link to answer the setup questions in Keep. Keep shows the same fingerprint.', // COPY-FLAG answer: { wait: waitCommand(bin, state.id, state.folder) }, }, @@ -522,31 +520,9 @@ async function steps(run: ConversationRun, options: WaitOptions, deps: Conversat extra: { flow_id: id, step: last.step, answered_in: 'keep', answers: last.answers, steps: answeredHere, goals: goalList(run.state.goals), answer: { wait: waitCommand(bin, id, run.state.folder) }, ...echo }, }); }; - // CAP-983 (spec 3o rule 7): Keep was to open it in the pairing tab. Give it 45 seconds, then hand the agent the link. - const keepOpens = !run.helloDone && run.state.opensInKeep === true; - const helloBy = keepOpens ? Math.min(deadline, now() + KEEP_OPEN_SECONDS * 1000) : deadline; for (;;) { if (!run.helloDone) { - const event = await timedWait('wait.conversation', () => run.next(helloBy)); - if (event.kind === 'timeout' && keepOpens) { - // From here on the agent holds the link, so this conversation is like any other. - run.update((s) => ({ ...s, opensInKeep: false })); - const fingerprint = conversationFingerprint(run.state.k); - return refusal({ - code: ERROR_CODES.CONVERSATION_NOT_OPENED_IN_KEEP, - message: 'Keep has not opened setup yet. Show the human this link now, then run `answer.wait` at once and again whenever it exits 3.', // COPY-FLAG - exitCode: 3, - extra: { - flow_id: id, - elicitation: { - kind: 'link', url: conversationUrl(deps.keepOrigin, run.state), code: fingerprint, fingerprint, purpose: 'conversation', expires_at: run.state.openBy, - opens_in_keep: false, instructions: 'Open this link to answer the setup questions in Keep. Keep shows the same fingerprint.', // COPY-FLAG - answer: { wait: waitCommand(bin, id, run.state.folder) }, - }, - goals: goalList(run.state.goals), - }, - }); - } + const event = await timedWait('wait.conversation', () => run.next(deadline)); if (event.kind === 'timeout') return waiting({ opened: false, ...(note !== undefined ? { note_sent: false } : {}) }); if (event.kind === 'ended') return refusal(stopRefusal(new ConversationStop(endedCode(event, event.outcome === 'expired'), true), bin, id, run.state.folder, run.state.about, run.state.answers)); continue; diff --git a/src/conversation/recovery.ts b/src/conversation/recovery.ts index 40da785f..0bdc0b3e 100644 --- a/src/conversation/recovery.ts +++ b/src/conversation/recovery.ts @@ -88,8 +88,8 @@ export interface ConversationState { /** CAP-957: the last stop shown in Keep (code and message), so a rerun that hits the same stop doesn't repeat it. */ readonly shownStop?: string; /** - * CAP-983 (spec 3o): the service said the pairing tab is waiting, so Keep opens this conversation itself and the agent - * does not post the link. Cleared once the CLI has handed the link out after all (CONVERSATION_NOT_OPENED_IN_KEEP). + * CAP-983 (spec 3o): the service said the pairing tab is waiting, so Keep opens this conversation itself. The agent + * still shows the link. */ readonly opensInKeep?: boolean; /** CAP-977: the fingerprint of the question the human last answered, until a different question is asked or it is asked again on purpose. */ diff --git a/src/core/agentsBlockPlan.ts b/src/core/agentsBlockPlan.ts index fb6c766b..97eb058b 100644 --- a/src/core/agentsBlockPlan.ts +++ b/src/core/agentsBlockPlan.ts @@ -30,7 +30,7 @@ export const AGENTS_BLOCK = [ '- A result can succeed and still report a step that did not happen: an object in it with `"ok": false`, a `code`, a `message` and a `next_command` (such as `services_recorded`, `keep_not_told`, `scan_incomplete` or `scripts_not_wired`). Tell the human its `message`, then run its `next_command` when it has one. Never treat it as done.', // COPY-FLAG (CAP-980) '- To pair this machine, run `capy pair --title "" --description "" --json`, in your own words (`capy setup` takes the same two flags). Keep shows them to the human on the unlock request, so say plainly what you want access for. Do not ask the human anything first, and add no other flags. It gives one approval link: Keep signs the human in or up and decides whether this machine gets their organization keys or a new organization. When the keys are already on this machine, the pairing only signs in (`"keys": "already_present"`).', // COPY-FLAG '- If an elicitation has `kind` `"link"`, show the human its `url`, `code`, `fingerprint` and `expires_at`, and its QR. Every time you show a link (the first one and each PAIR_LINK_RENEWED), write the `url` as a clickable link, with the `code`, `fingerprint` and `expires_at`, as plain text in your reply. The QR is an addition, never the only way: not every agent or client can show images. Show the QR as an image the human can scan right in the conversation: if your client can show images or HTML widgets, show the PNG inline with `qr.image.data_uri` as the image source (a wait response has no data URI, so read `qr.image.file` and show it inline the same way). An attached file, a download link or a file path is not showing the QR. If you cannot show an image, show `qr.text` only in a real terminal with a monospace grid and no extra line spacing, else say plainly that the QR cannot be shown here. Never use an external QR service. Then run its `answer.wait` command at once in the foreground. It can take up to 9 minutes, because it returns only when something changes, so give it a tool timeout of at least 10 minutes. Run it again whenever it exits 3 with `PAIR_STILL_WAITING`, or if your tool stopped it early. If it exits 3 with `PAIR_LINK_RENEWED`, the old link expired and Capy made a new one: show the human the new `url`, `code`, `fingerprint`, `expires_at` and QR the same way, then run `answer.wait` again. Keep showing each new link and running its `answer.wait` without stopping to ask the human, until the human gives you the one-time code or says stop, the pairing is denied, or the CLI answers PAIR_EXPIRED. The CLI renews a link at most 4 times; when the last one expires it exits 3 with `PAIR_EXPIRED` and a confirm: only then ask the human whether to start again, and run `answer.yes` if they say yes. Never start a new `capy pair` for an expired link any other way. After the human approves, Keep shows them a one-time code and the wait exits 3 with `PAIR_CODE_REQUIRED`: ask the human for that code and run `capy pair --wait --code --json`. Never fill in the code yourself: only the person who approved can see it, which is what stops a phished approval.', // COPY-FLAG - '- When a link elicitation has `opens_in_keep: true`, Keep is opening it by itself in the tab where the human approved pairing: do not post the link, tell the human to continue in Keep, and run `answer.wait` at once. If the wait exits 3 with `CONVERSATION_NOT_OPENED_IN_KEEP`, show the link it returns then.', // COPY-FLAG + '- When a link elicitation has `opens_in_keep: true`, Keep is opening it by itself in the tab where the human approved pairing: still show the link as usual, say Keep should open it by itself, and run `answer.wait` at once.', // COPY-FLAG `- ${SETUP_COPY.run.agentsLine}`, // COPY-FLAG (CAP-960) '- To refresh what this project has hooked up, run `capy summary --json` and follow its `discover.instructions`: discovery is yours, and its `suggestions` are only a starting point.', // COPY-FLAG (CAP-971) '- To send a secret to GitHub or any other platform, run `capy deploy --json`. If no deploy target is set up, ask the human whether to set one up, and do not set one up yourself. Never push the value any other way, such as `gh secret set` or `vercel env add`. Never add `--yes` on your own.', // COPY-FLAG diff --git a/src/types/index.ts b/src/types/index.ts index a87696d4..acea3d65 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1078,7 +1078,6 @@ export const ERROR_CODES = { CONVERSATION_OPEN: 'CONVERSATION_OPEN', CONVERSATION_WAITING: 'CONVERSATION_WAITING', /** CAP-983 (spec 3o): Keep was to open the conversation by itself in the pairing tab and has not within 45 seconds. Show the link now. Exit 3. */ - CONVERSATION_NOT_OPENED_IN_KEEP: 'CONVERSATION_NOT_OPENED_IN_KEEP', CONVERSATION_STEP_DONE: 'CONVERSATION_STEP_DONE', /** CAP-977: setup asked again the exact form the human just answered in Keep. The CLI does not post it a second time; the step is failed in Keep with one note. Exit 1. */ CONVERSATION_STEP_REPEATED: 'CONVERSATION_STEP_REPEATED', diff --git a/src/ui/elicitation.ts b/src/ui/elicitation.ts index 7eb70d05..c4ae7f6c 100644 --- a/src/ui/elicitation.ts +++ b/src/ui/elicitation.ts @@ -186,4 +186,4 @@ export type Elicitation = ElicitationConfirm | ElicitationForm | ElicitationLink /** What `capy help --json` says about elicitations (`conventions.elicitation`). */ export const ELICITATION_HELP = // COPY-FLAG: minimal and neutral. - 'A refusal with exit code 3 can carry an `elicitation` next to its `code`: a question for the human, never for you. Write `display` (a markdown table) in your reply exactly as given, without shortening or reordering it and never inside the question. Then ask the short `question` as an elicitation with your question tool: one question per field, every field of the form together in one go (never one, then the next), using the field\'s own `question` followed by its `description` when it has them, and its `options` or `default` as the choices; without a question tool, end your reply with the `question` and the human answers in chat. `capy setup` adds two things to each of its stops (CAP-940): a form\'s `instructions`, written from its own fields (ask them all together, list a field with more choices than your question tool holds in chat as text, run `answer.rerun` at once), and `next`, the steps still to come (pairing, the Set up step, the project questions, the finished setup), so you never stop to ask whether to go on; follow both. kind "confirm" is a yes/no ({kind, question, details, display, answer:{yes}}): ask the human; on yes, run the command in `answer.yes`; on no, stop. kind "form" asks for values ({kind, question, details, display, fields:[{name, type, pattern, question?, default?, description?, options?:[{value, label, description?}], other?}], answer:{rerun}}): ask the human for each field, then run `answer.rerun` with the values filled in. ' + ASK_RULES_TEXT + ' `details` holds names and ids only, never a value. Today: `capy project restore` without --yes refuses with CONFIRMATION_REQUIRED and a confirm (details: {org:{id,name}, project:{id,name,deleted_at}}); `capy project delete` without --yes refuses with CONFIRMATION_REQUIRED and a confirm (details: {org:{id,name}, project:{id,name}, branches:[name], variables:[{name, branches:[name]}], live_deploy_tokens:[{deploy_id, label}], unavailable?:["branches"|"variables"]}); `capy project create` missing the name, `--branch` or `--protected` in agent mode refuses with PROJECT_NAME_REQUIRED, BRANCH_NAME_REQUIRED or BRANCH_PROTECTION_REQUIRED and a form (fields: name, branch, protected (options yes/no); details: {org:{id,name}}); `capy project delete` / `project restore` with a name several projects share refuses with PROJECT_AMBIGUOUS and a form with one `project` field whose options are the projects (details: {org:{id,name}, matches:[{id, name, created_at, variables}]}); `capy kick ` without --yes refuses with CONFIRMATION_REQUIRED and a confirm (details: {org:{id,name}, member:{email}}); `capy projects rename` with no name refuses with PROJECT_NAME_REQUIRED and a form with one `name` field (details: {org:{id,name}, project:{id,name}}); `capy secrets set` / `capy secrets deploy` with a project that is linked to more than one repo refuses with PR_REPO_AMBIGUOUS and a form with one field per such project whose options are its repos (details: {projects:[{id, name, repos:[owner/name[/folder]]}]}); pass the same `--pr-repo` again on the run with `--confirm`. `capy branch -D NAME` without --yes in agent mode refuses with CONFIRMATION_REQUIRED and a confirm (details: {branch:{name}}); `capy remove NAME...` without --yes refuses with REMOVE_NEEDS_TTY and a confirm (details: {branch, variables:[name], removing_all}); `capy system rm NAME` without --yes refuses with SYSTEM_STORE_NEEDS_TTY and a confirm (details: {name, org?}); `capy connect vercel|dokploy` with --overwrite or --discover and without --yes refuses with VERCEL_CONFIRMATION_REQUIRED or DOKPLOY_CONFIRMATION_REQUIRED (exit 3) and a confirm whose `display` lists the terminal\'s lines (details: {import, replace, clear} or {folders}); `capy connect vercel` with nobody to ask refuses with VERCEL_TEAM_REQUIRED (form, one `team` field whose options are the team slugs; details: {teams:[{id, slug}]}), VERCEL_PROJECT_REQUIRED (form, one typed `project` field; details: {}) or VERCEL_ENVIRONMENT_REQUIRED (form, one `environment` field whose options are the environments; details: {branch, environments:[name]}), all exit 3; `capy connect dokploy` refuses with DOKPLOY_TARGET_AMBIGUOUS (form, one `target` field: each option\'s label is a saved target and its value that target\'s flags; details: {targets:[name]}) or DOKPLOY_SETTINGS_MISSING (form asking only what is missing: `base_url`, then `source` (option values `--application` / `--compose`) and `service_id`; details: {}); fill the values into `answer.rerun` as they are. With nobody at a terminal, these picks refuse with a form of one field whose options are the terminal\'s choices (exit 3): `capy rotate` with no variable, ROTATE_VARIABLE_REQUIRED (field `variable`; details: {branch, variables}); `capy rotate VAR` for an unmanaged variable with several integrations, ROTATE_PROVIDER_REQUIRED (field `provider`; details: {variable, providers}); `capy invite` for a role that needs project access, INVITE_PROJECT_REQUIRED (field `project`, one project; details: {role, projects:[{id, name}]}); `capy connect stripe` with several accounts, STRIPE_ACCOUNT_REQUIRED (field `account`; details: {accounts:[{name, account_id}]}); `capy connect stripe|workos` when the key\'s variable is unclear, CONNECTOR_VAR_REQUIRED (field `var`; details: {branch, variables}). `capy rotate` has no --json, so its `answer.rerun` ends with --non-tty. A command that works on an organization (users, projects, project create|delete|restore, projects rename, secrets, invite, kick, grant-branch, revoke-branch) with several organizations, no keep.lock and no --org refuses with ORG_SELECTION_REQUIRED (exit 3) and a form with one `org` field whose options are the org ids labelled by name (details: {orgs:[{id, name}]}); its rerun adds --org. `capy agents` (or `capy agents --remove`) without --yes in agent mode refuses with AGENTS_SETUP_NEEDS_TTY and a confirm asking the terminal\'s question (details: {files:[{path, action}]}); `capy checkout NAME -b --json` without --protected or --no-protected refuses with BRANCH_PROTECTION_REQUIRED and a form with one `protected` field whose option values are the flags `--protected` and `--no-protected` (details: {branch:{name}}); its `answer.rerun` uses --non-tty, because `-b --json` only describes the route. kind "link" hands the human a page to approve on ({kind, url, code, fingerprint?, purpose, expires_at, qr?:{text?, image?:{mime_type, file, data_uri?}}, instructions, answer:{wait}}): write the `url` as a clickable link, with the `code`, the `fingerprint` (the page shows the same one) and `expires_at`, as plain text, every time a link is shown (the `qr`, as `conventions.pairing` says, is only an addition, never the only way), then run `answer.wait` at once in the foreground (it can take up to 9 minutes, so give it a tool timeout of at least 10 minutes), and run it again whenever it exits 3 with PAIR_STILL_WAITING or your tool stopped it early; when it exits 3 with PAIR_LINK_RENEWED the old link expired and the elicitation is a new link: show it to the human the same way and run its `answer.wait` again. Its `instructions` say the same. Pass `--title` and `--description` to `capy pair` and `capy setup`: your own words for what you are doing and why, which Keep shows the human on the unlock request; `capy setup` refuses to start a pairing without them (SETUP_INTENT_REQUIRED, exit 1, with `next_command`). Today `capy pair` in agent mode asks nothing up front (no email, no keys choice: on a machine with no keys it asks for them, and Keep decides after sign-in between the organization keys and a new organization); it refuses with PAIR_APPROVAL_PENDING and a link; once the human approves, the wait refuses with PAIR_CODE_REQUIRED (or PAIR_CODE_MISMATCH after a wrong code) and a form (field: code; details: {attempts_left?}) for the one-time code Keep shows the human; never fill in the code yourself. Bare `capy` in a folder that is not a project, in agent mode, with questions left refuses with INIT_INPUT_REQUIRED and one form that asks only what is unanswered: first, alone, folder when no --folder was typed (options: this folder and every subfolder that holds a .env or a package file, those with a .env first, each option\'s description saying which it holds, with `other`; when there are more choices than your question tool takes, list every option with its description in chat and let the human answer there, never dropping one; the rerun adds --folder), then org (options: the organizations; asked before the project questions when there are several, with only share beside it), then the Set up step when no --choice was typed (CAP-941: when a choice that creates a project fits, the same form also asks that new project\'s `name` and first `branch`, and `share` inside Git, so there is one round trip after the code; `details.new_project_fields` names them; they are used only by `existing` and `new`, and a rerun with `--choice import` ignores `--name`, and ignores `--branch` until the project to link is answered, so it asks the project and then its branch; question "' + SETUP_COPY.setUp.question + '"; field `choice` offers only the choices that fit: `existing` "' + SETUP_COPY.choice.options.existing.label + '" when the .env has secrets, `new` "' + SETUP_COPY.choice.options.new.label + '" when it has none, `import` "' + SETUP_COPY.choice.options.import.label + '" (link this folder to a project that already exists) when the organization has a project, and `skip` "' + SETUP_COPY.choice.options.skip.label + '"; when only one fits, `choice` is a field with that one option, already decided (`ask.in` is `decided`): show it as chosen and never ask it; fields `discover` ("' + SETUP_COPY.scope.discover.label + '") and `deployments` ("' + SETUP_COPY.scope.deployments.label + '"), options yes/no, default yes; CAP-960: when the folder\'s package.json has local scripts (dev, test and the like) also `run_scripts` ("' + SETUP_COPY.scope.runScripts.label + '"), options yes/no, default yes, its description naming the scripts (`details.scripts`); yes changes each to start with `capy run --`, never build, deploy or install scripts, and the rerun adds --run-scripts; encrypting the .env is always on and is never a field, `details.always.encrypt_line` says it; answering the step is the yes to encrypting, so no separate encrypt question follows; the rerun adds --choice, --discover and --deployments (and --run-scripts when asked); `skip` creates nothing, leaves the .env as it is and ends with `skipped: true` (`capy setup` then returns `setup: "skipped"` and writes no AGENTS block); a --choice that does not fit refuses with SETUP_CHOICE_UNAVAILABLE (exit 3, `extra.choices` lists the ones that fit: ask the human again with those); a --choice, --discover or --deployments that is not one of its values refuses with SETUP_CHOICE_INVALID or SETUP_SCOPE_INVALID; the result carries `setup_choice` and `scope`), project (for `import` only; options: the existing projects), then for a new project (`existing` or `new`) name (its default is a free name: the folder\'s, or the first free `-2` to `-9`; a name that turns out to be taken refuses with PROJECT_NAME_EXISTS, exit 3, and the same form asking only `name`, its `display` saying the name is taken: ask the human again and run its `answer.rerun`) and branch (its protection is not asked: the first branch starts open, as in the terminal, unless --protected was typed), and for an existing project branch (options: that project\'s branches, never chosen for the human even when there is one), or, when that project has no branches yet, branch for its first one (default development; the rerun creates it open to the project); and, inside a git repository, share (options yes: "' + SETUP_COPY.share.shared.label + '", no: "' + SETUP_COPY.share.folderOnly.label + '"; the rerun adds --share-setup); a typed --encrypt-env no still creates nothing and leaves the .env as it is; while folder is asked its `display` only names the folder Capy runs in; otherwise its `display` is the whole summary, so after the human answers, run `answer.rerun` with no further confirmation (details: {folder?, org?, orgs?, projects?, project?, branches?, new_project_fields?, variables}; `variables` is a count). Never answer it yourself and never add --yes on your own. A finished setup can carry `warnings`, each with a `code`, a `message` and a `next` step (today ENV_IN_GIT_HISTORY: the .env was committed to Git, so its old values are still in the history; and GITIGNORE_NOT_COMMITTED: the .gitignore is left out of the commit of a shared setup (and of `git.files`), because it has changes Capy did not make): tell the human each `message` and its `next` step in your reply, and never act on it for them. CAP-960: a finished setup carries `run` ({command, message, note?}): the .env now holds ciphertext, so tell the human `message` and `command` (the command that starts the app with the decrypted .env, or null), and `note` when there is one; start the app, its tests and anything that reads the .env only that way. `scripts` ({file, wrapped, skipped}) lists the package.json scripts Capy changed; in a shared setup package.json is in `git.files` when Capy\'s change is its only one. CAP-971: discovery is yours. A finished setup whose Set up step looks for services or deployments carries `discover` in place of `summary`: follow its `instructions`. CAP-954: in agent mode Capy commits nothing and runs no gh. A setup shared through Git ("' + SETUP_COPY.share.shared.label + '") ends with `git`: `folder`, `files`, `commit_message`, `branch`, `base`, `pull_request` ({title, body}, or null with `--pr no` or no origin), `instructions` and `commands`. Follow its `instructions` with your own Git access and access to the Git host: commit exactly `files` in `folder` with `commit_message`, open `pull_request` on `base` from `branch` so it holds only those files (push the commit as `branch` only when its parent is the head of `base` on origin, else make `branch` from `base` on origin); Capy pull requests stack: with an open pull request from a `capy/` branch, open it on the newest open `capy/` branch that no other open pull request is based on, and show the human its link. Never change Git settings or identity yourself; if Git has no name or email, ask the human to set theirs. Without Git tools, run `commands` in `folder` exactly as given. `capy setup --conversation --json` asks those folder questions in a Keep conversation instead (CAP-921): it refuses with CONVERSATION_OPEN (exit 3) and a link whose `purpose` is "conversation" (show its url, fingerprint and expiry the same way, and its `preview` steps; CAP-983: except when its `opens_in_keep` is true, which means Keep is opening the conversation by itself in the tab where the human approved pairing: then do not show the link, tell the human to continue in Keep, and if a wait refuses with CONVERSATION_NOT_OPENED_IN_KEEP (exit 3, with the link as its `elicitation`) show that link the same way then), then run `answer.wait` (`capy setup --wait --folder --flow --json`, which finds the conversation from any folder) at once and again on every exit 3. When Keep can\'t hold the conversation, `capy setup --conversation` refuses with CONVERSATION_ASK_IN_CHAT (exit 3, `extra.conversation_unavailable.reason`: not_signed_in, no_transport_record, no_local_key or refused) and the same question it would have asked: tell the human its `message`, then ask the question in chat as above; its `answer.rerun` keeps `--conversation`, so the next step tries Keep again. On a machine that must pair first, the pairing\'s commands keep `--conversation`, so the questions go to Keep once it is paired. Waits: CONVERSATION_WAITING means nothing new yet; CONVERSATION_STEP_DONE means the human answered a step in Keep (`step`, `answered_in: "keep"`, `answers`, `goals`): show it as done in one line and run the wait again. Never end your turn between waits while the conversation is open: run `answer.wait` again at once after every exit 3. Nothing is lost if a wait ends or your tool stops it: answers given in Keep while no wait runs are kept and returned by the next wait. To reconnect from a fresh session, run `capy setup --wait --json` in the same folder (add `--flow ` only when more than one conversation is open there), or `capy setup --conversation --json` there, which hands back the open conversation\'s link with `resumed: true`. CAP-977: CONVERSATION_STEP_REPEATED (exit 1, `shown_in_keep: true`, `step`) means setup asked the human the exact question they had just answered; it was not posted again, Keep shows the step as failed, and the answers are kept: tell the human in one line and report it as a Capy bug, never answer it yourself. The finished setup has `conversation.code` CONVERSATION_DONE. `goals` lists every step with its status. Add `--note -` to the wait to show the human a plain-text note in Keep (piped on stdin, at most 2,000 characters, no links; it is echoed back as `note`), and `--cancel` to end the conversation. CAP-957: one wait (280 seconds by default) runs on through every step the human answers in Keep (run it in the foreground with a tool timeout of at least 6 minutes) and returns early only at the end, at a stop, or when its time is up; CONVERSATION_STEP_DONE then lists every step answered during it in `steps`. Every stop reaches Keep. A refused answer given in Keep is asked again in Keep, so you only see a wait. Any other stop comes to you as its own refusal with `shown_in_keep: true` and `answer.wait`: Keep has already told the human that this step stopped, so tell them its `message` and next step in one line, then run `answer.wait` again once it is done; the conversation carries on from its saved answers. Running `capy setup --conversation` again in a folder whose conversation is still open hands back the same link with `resumed: true`: show it again and run its `answer.wait`. You never answer a question asked in Keep, and you never see a key or a sealed record.'; + 'A refusal with exit code 3 can carry an `elicitation` next to its `code`: a question for the human, never for you. Write `display` (a markdown table) in your reply exactly as given, without shortening or reordering it and never inside the question. Then ask the short `question` as an elicitation with your question tool: one question per field, every field of the form together in one go (never one, then the next), using the field\'s own `question` followed by its `description` when it has them, and its `options` or `default` as the choices; without a question tool, end your reply with the `question` and the human answers in chat. `capy setup` adds two things to each of its stops (CAP-940): a form\'s `instructions`, written from its own fields (ask them all together, list a field with more choices than your question tool holds in chat as text, run `answer.rerun` at once), and `next`, the steps still to come (pairing, the Set up step, the project questions, the finished setup), so you never stop to ask whether to go on; follow both. kind "confirm" is a yes/no ({kind, question, details, display, answer:{yes}}): ask the human; on yes, run the command in `answer.yes`; on no, stop. kind "form" asks for values ({kind, question, details, display, fields:[{name, type, pattern, question?, default?, description?, options?:[{value, label, description?}], other?}], answer:{rerun}}): ask the human for each field, then run `answer.rerun` with the values filled in. ' + ASK_RULES_TEXT + ' `details` holds names and ids only, never a value. Today: `capy project restore` without --yes refuses with CONFIRMATION_REQUIRED and a confirm (details: {org:{id,name}, project:{id,name,deleted_at}}); `capy project delete` without --yes refuses with CONFIRMATION_REQUIRED and a confirm (details: {org:{id,name}, project:{id,name}, branches:[name], variables:[{name, branches:[name]}], live_deploy_tokens:[{deploy_id, label}], unavailable?:["branches"|"variables"]}); `capy project create` missing the name, `--branch` or `--protected` in agent mode refuses with PROJECT_NAME_REQUIRED, BRANCH_NAME_REQUIRED or BRANCH_PROTECTION_REQUIRED and a form (fields: name, branch, protected (options yes/no); details: {org:{id,name}}); `capy project delete` / `project restore` with a name several projects share refuses with PROJECT_AMBIGUOUS and a form with one `project` field whose options are the projects (details: {org:{id,name}, matches:[{id, name, created_at, variables}]}); `capy kick ` without --yes refuses with CONFIRMATION_REQUIRED and a confirm (details: {org:{id,name}, member:{email}}); `capy projects rename` with no name refuses with PROJECT_NAME_REQUIRED and a form with one `name` field (details: {org:{id,name}, project:{id,name}}); `capy secrets set` / `capy secrets deploy` with a project that is linked to more than one repo refuses with PR_REPO_AMBIGUOUS and a form with one field per such project whose options are its repos (details: {projects:[{id, name, repos:[owner/name[/folder]]}]}); pass the same `--pr-repo` again on the run with `--confirm`. `capy branch -D NAME` without --yes in agent mode refuses with CONFIRMATION_REQUIRED and a confirm (details: {branch:{name}}); `capy remove NAME...` without --yes refuses with REMOVE_NEEDS_TTY and a confirm (details: {branch, variables:[name], removing_all}); `capy system rm NAME` without --yes refuses with SYSTEM_STORE_NEEDS_TTY and a confirm (details: {name, org?}); `capy connect vercel|dokploy` with --overwrite or --discover and without --yes refuses with VERCEL_CONFIRMATION_REQUIRED or DOKPLOY_CONFIRMATION_REQUIRED (exit 3) and a confirm whose `display` lists the terminal\'s lines (details: {import, replace, clear} or {folders}); `capy connect vercel` with nobody to ask refuses with VERCEL_TEAM_REQUIRED (form, one `team` field whose options are the team slugs; details: {teams:[{id, slug}]}), VERCEL_PROJECT_REQUIRED (form, one typed `project` field; details: {}) or VERCEL_ENVIRONMENT_REQUIRED (form, one `environment` field whose options are the environments; details: {branch, environments:[name]}), all exit 3; `capy connect dokploy` refuses with DOKPLOY_TARGET_AMBIGUOUS (form, one `target` field: each option\'s label is a saved target and its value that target\'s flags; details: {targets:[name]}) or DOKPLOY_SETTINGS_MISSING (form asking only what is missing: `base_url`, then `source` (option values `--application` / `--compose`) and `service_id`; details: {}); fill the values into `answer.rerun` as they are. With nobody at a terminal, these picks refuse with a form of one field whose options are the terminal\'s choices (exit 3): `capy rotate` with no variable, ROTATE_VARIABLE_REQUIRED (field `variable`; details: {branch, variables}); `capy rotate VAR` for an unmanaged variable with several integrations, ROTATE_PROVIDER_REQUIRED (field `provider`; details: {variable, providers}); `capy invite` for a role that needs project access, INVITE_PROJECT_REQUIRED (field `project`, one project; details: {role, projects:[{id, name}]}); `capy connect stripe` with several accounts, STRIPE_ACCOUNT_REQUIRED (field `account`; details: {accounts:[{name, account_id}]}); `capy connect stripe|workos` when the key\'s variable is unclear, CONNECTOR_VAR_REQUIRED (field `var`; details: {branch, variables}). `capy rotate` has no --json, so its `answer.rerun` ends with --non-tty. A command that works on an organization (users, projects, project create|delete|restore, projects rename, secrets, invite, kick, grant-branch, revoke-branch) with several organizations, no keep.lock and no --org refuses with ORG_SELECTION_REQUIRED (exit 3) and a form with one `org` field whose options are the org ids labelled by name (details: {orgs:[{id, name}]}); its rerun adds --org. `capy agents` (or `capy agents --remove`) without --yes in agent mode refuses with AGENTS_SETUP_NEEDS_TTY and a confirm asking the terminal\'s question (details: {files:[{path, action}]}); `capy checkout NAME -b --json` without --protected or --no-protected refuses with BRANCH_PROTECTION_REQUIRED and a form with one `protected` field whose option values are the flags `--protected` and `--no-protected` (details: {branch:{name}}); its `answer.rerun` uses --non-tty, because `-b --json` only describes the route. kind "link" hands the human a page to approve on ({kind, url, code, fingerprint?, purpose, expires_at, qr?:{text?, image?:{mime_type, file, data_uri?}}, instructions, answer:{wait}}): write the `url` as a clickable link, with the `code`, the `fingerprint` (the page shows the same one) and `expires_at`, as plain text, every time a link is shown (the `qr`, as `conventions.pairing` says, is only an addition, never the only way), then run `answer.wait` at once in the foreground (it can take up to 9 minutes, so give it a tool timeout of at least 10 minutes), and run it again whenever it exits 3 with PAIR_STILL_WAITING or your tool stopped it early; when it exits 3 with PAIR_LINK_RENEWED the old link expired and the elicitation is a new link: show it to the human the same way and run its `answer.wait` again. Its `instructions` say the same. Pass `--title` and `--description` to `capy pair` and `capy setup`: your own words for what you are doing and why, which Keep shows the human on the unlock request; `capy setup` refuses to start a pairing without them (SETUP_INTENT_REQUIRED, exit 1, with `next_command`). Today `capy pair` in agent mode asks nothing up front (no email, no keys choice: on a machine with no keys it asks for them, and Keep decides after sign-in between the organization keys and a new organization); it refuses with PAIR_APPROVAL_PENDING and a link; once the human approves, the wait refuses with PAIR_CODE_REQUIRED (or PAIR_CODE_MISMATCH after a wrong code) and a form (field: code; details: {attempts_left?}) for the one-time code Keep shows the human; never fill in the code yourself. Bare `capy` in a folder that is not a project, in agent mode, with questions left refuses with INIT_INPUT_REQUIRED and one form that asks only what is unanswered: first, alone, folder when no --folder was typed (options: this folder and every subfolder that holds a .env or a package file, those with a .env first, each option\'s description saying which it holds, with `other`; when there are more choices than your question tool takes, list every option with its description in chat and let the human answer there, never dropping one; the rerun adds --folder), then org (options: the organizations; asked before the project questions when there are several, with only share beside it), then the Set up step when no --choice was typed (CAP-941: when a choice that creates a project fits, the same form also asks that new project\'s `name` and first `branch`, and `share` inside Git, so there is one round trip after the code; `details.new_project_fields` names them; they are used only by `existing` and `new`, and a rerun with `--choice import` ignores `--name`, and ignores `--branch` until the project to link is answered, so it asks the project and then its branch; question "' + SETUP_COPY.setUp.question + '"; field `choice` offers only the choices that fit: `existing` "' + SETUP_COPY.choice.options.existing.label + '" when the .env has secrets, `new` "' + SETUP_COPY.choice.options.new.label + '" when it has none, `import` "' + SETUP_COPY.choice.options.import.label + '" (link this folder to a project that already exists) when the organization has a project, and `skip` "' + SETUP_COPY.choice.options.skip.label + '"; when only one fits, `choice` is a field with that one option, already decided (`ask.in` is `decided`): show it as chosen and never ask it; fields `discover` ("' + SETUP_COPY.scope.discover.label + '") and `deployments` ("' + SETUP_COPY.scope.deployments.label + '"), options yes/no, default yes; CAP-960: when the folder\'s package.json has local scripts (dev, test and the like) also `run_scripts` ("' + SETUP_COPY.scope.runScripts.label + '"), options yes/no, default yes, its description naming the scripts (`details.scripts`); yes changes each to start with `capy run --`, never build, deploy or install scripts, and the rerun adds --run-scripts; encrypting the .env is always on and is never a field, `details.always.encrypt_line` says it; answering the step is the yes to encrypting, so no separate encrypt question follows; the rerun adds --choice, --discover and --deployments (and --run-scripts when asked); `skip` creates nothing, leaves the .env as it is and ends with `skipped: true` (`capy setup` then returns `setup: "skipped"` and writes no AGENTS block); a --choice that does not fit refuses with SETUP_CHOICE_UNAVAILABLE (exit 3, `extra.choices` lists the ones that fit: ask the human again with those); a --choice, --discover or --deployments that is not one of its values refuses with SETUP_CHOICE_INVALID or SETUP_SCOPE_INVALID; the result carries `setup_choice` and `scope`), project (for `import` only; options: the existing projects), then for a new project (`existing` or `new`) name (its default is a free name: the folder\'s, or the first free `-2` to `-9`; a name that turns out to be taken refuses with PROJECT_NAME_EXISTS, exit 3, and the same form asking only `name`, its `display` saying the name is taken: ask the human again and run its `answer.rerun`) and branch (its protection is not asked: the first branch starts open, as in the terminal, unless --protected was typed), and for an existing project branch (options: that project\'s branches, never chosen for the human even when there is one), or, when that project has no branches yet, branch for its first one (default development; the rerun creates it open to the project); and, inside a git repository, share (options yes: "' + SETUP_COPY.share.shared.label + '", no: "' + SETUP_COPY.share.folderOnly.label + '"; the rerun adds --share-setup); a typed --encrypt-env no still creates nothing and leaves the .env as it is; while folder is asked its `display` only names the folder Capy runs in; otherwise its `display` is the whole summary, so after the human answers, run `answer.rerun` with no further confirmation (details: {folder?, org?, orgs?, projects?, project?, branches?, new_project_fields?, variables}; `variables` is a count). Never answer it yourself and never add --yes on your own. A finished setup can carry `warnings`, each with a `code`, a `message` and a `next` step (today ENV_IN_GIT_HISTORY: the .env was committed to Git, so its old values are still in the history; and GITIGNORE_NOT_COMMITTED: the .gitignore is left out of the commit of a shared setup (and of `git.files`), because it has changes Capy did not make): tell the human each `message` and its `next` step in your reply, and never act on it for them. CAP-960: a finished setup carries `run` ({command, message, note?}): the .env now holds ciphertext, so tell the human `message` and `command` (the command that starts the app with the decrypted .env, or null), and `note` when there is one; start the app, its tests and anything that reads the .env only that way. `scripts` ({file, wrapped, skipped}) lists the package.json scripts Capy changed; in a shared setup package.json is in `git.files` when Capy\'s change is its only one. CAP-971: discovery is yours. A finished setup whose Set up step looks for services or deployments carries `discover` in place of `summary`: follow its `instructions`. CAP-954: in agent mode Capy commits nothing and runs no gh. A setup shared through Git ("' + SETUP_COPY.share.shared.label + '") ends with `git`: `folder`, `files`, `commit_message`, `branch`, `base`, `pull_request` ({title, body}, or null with `--pr no` or no origin), `instructions` and `commands`. Follow its `instructions` with your own Git access and access to the Git host: commit exactly `files` in `folder` with `commit_message`, open `pull_request` on `base` from `branch` so it holds only those files (push the commit as `branch` only when its parent is the head of `base` on origin, else make `branch` from `base` on origin); Capy pull requests stack: with an open pull request from a `capy/` branch, open it on the newest open `capy/` branch that no other open pull request is based on, and show the human its link. Never change Git settings or identity yourself; if Git has no name or email, ask the human to set theirs. Without Git tools, run `commands` in `folder` exactly as given. `capy setup --conversation --json` asks those folder questions in a Keep conversation instead (CAP-921): it refuses with CONVERSATION_OPEN (exit 3) and a link whose `purpose` is "conversation" (show its url, fingerprint and expiry the same way, and its `preview` steps; CAP-983: when its `opens_in_keep` is true, Keep is also opening the conversation by itself in the tab where the human approved pairing: still show the link, and say Keep should open it by itself), then run `answer.wait` (`capy setup --wait --folder --flow --json`, which finds the conversation from any folder) at once and again on every exit 3. When Keep can\'t hold the conversation, `capy setup --conversation` refuses with CONVERSATION_ASK_IN_CHAT (exit 3, `extra.conversation_unavailable.reason`: not_signed_in, no_transport_record, no_local_key or refused) and the same question it would have asked: tell the human its `message`, then ask the question in chat as above; its `answer.rerun` keeps `--conversation`, so the next step tries Keep again. On a machine that must pair first, the pairing\'s commands keep `--conversation`, so the questions go to Keep once it is paired. Waits: CONVERSATION_WAITING means nothing new yet; CONVERSATION_STEP_DONE means the human answered a step in Keep (`step`, `answered_in: "keep"`, `answers`, `goals`): show it as done in one line and run the wait again. Never end your turn between waits while the conversation is open: run `answer.wait` again at once after every exit 3. Nothing is lost if a wait ends or your tool stops it: answers given in Keep while no wait runs are kept and returned by the next wait. To reconnect from a fresh session, run `capy setup --wait --json` in the same folder (add `--flow ` only when more than one conversation is open there), or `capy setup --conversation --json` there, which hands back the open conversation\'s link with `resumed: true`. CAP-977: CONVERSATION_STEP_REPEATED (exit 1, `shown_in_keep: true`, `step`) means setup asked the human the exact question they had just answered; it was not posted again, Keep shows the step as failed, and the answers are kept: tell the human in one line and report it as a Capy bug, never answer it yourself. The finished setup has `conversation.code` CONVERSATION_DONE. `goals` lists every step with its status. Add `--note -` to the wait to show the human a plain-text note in Keep (piped on stdin, at most 2,000 characters, no links; it is echoed back as `note`), and `--cancel` to end the conversation. CAP-957: one wait (280 seconds by default) runs on through every step the human answers in Keep (run it in the foreground with a tool timeout of at least 6 minutes) and returns early only at the end, at a stop, or when its time is up; CONVERSATION_STEP_DONE then lists every step answered during it in `steps`. Every stop reaches Keep. A refused answer given in Keep is asked again in Keep, so you only see a wait. Any other stop comes to you as its own refusal with `shown_in_keep: true` and `answer.wait`: Keep has already told the human that this step stopped, so tell them its `message` and next step in one line, then run `answer.wait` again once it is done; the conversation carries on from its saved answers. Running `capy setup --conversation` again in a folder whose conversation is still open hands back the same link with `resumed: true`: show it again and run its `answer.wait`. You never answer a question asked in Keep, and you never see a key or a sealed record.'; diff --git a/tests/conversation/setupConversation.test.ts b/tests/conversation/setupConversation.test.ts index 54311707..5a4e6ffc 100644 --- a/tests/conversation/setupConversation.test.ts +++ b/tests/conversation/setupConversation.test.ts @@ -1011,7 +1011,7 @@ describe('CAP-930: each run\'s output goes to Keep, sealed, scrubbed, and before describe('CAP-983: the pairing tab opens the conversation itself (spec 3o)', () => { beforeEach(() => forgetHandoff()); - test('with this run\'s handoff secret, the conversation is tagged for the tab and the agent is told not to post the link', async () => { + test('with this run\'s handoff secret, the conversation is tagged for the tab, and the agent still shows the link', async () => { const secret = randomBytes(32); rememberHandoff(ORG, USER, secret.toString('base64url')); service.tabWaiting(true); @@ -1022,8 +1022,8 @@ describe('CAP-983: the pairing tab opens the conversation itself (spec 3o)', () // The tag the tab checks: HMAC under its secret over the id and this CLI's key. expect(service.flows.get(id)!.handoffTag).toBe(w.b64u(w.handoffTag(secret, id, w.unb64u(state.cliPub)))); expect(elicitation.opens_in_keep).toBe(true); - expect(outcome.refusal.message).toContain('Do not post the link'); - // The link is still there for the fallback, and the secret is used once: the next conversation has none. + expect(outcome.refusal.message).toContain('Still show the human the link'); + // The link is always shown (Vincent, 2026-12-02), and the secret is used once: the next conversation has none. expect(elicitation.url).toBe(`https://keep.example/flow/conversation?f=${id}#k=${state.k}`); expect(JSON.stringify(store.load(USER, id))).not.toContain(secret.toString('base64url')); await waitSetupConversation({ answers: {}, cancel: true }, deps); @@ -1046,28 +1046,12 @@ describe('CAP-983: the pairing tab opens the conversation itself (spec 3o)', () } }); - test('if Keep does not open it within 45 seconds, the wait hands the agent the link (no silent failure)', async () => { + test('a wait does not cut short when Keep opens it: it runs its whole time like any other', async () => { rememberHandoff(ORG, USER, randomBytes(32).toString('base64url')); service.tabWaiting(true); - const state = await open(); - const started = now; - const outcome = await waitSetupConversation({ answers: {} }, deps); - if (outcome.kind !== 'refusal') throw new Error('expected the fallback'); - expect(outcome.refusal.code).toBe('CONVERSATION_NOT_OPENED_IN_KEEP'); - expect(now - started).toBeLessThan(60_000); - const { elicitation } = outcome.refusal.extra as { elicitation: { url: string; fingerprint: string; answer: { wait: string } } }; - expect(elicitation.url).toBe(`https://keep.example/flow/conversation?f=${state.id}#k=${state.k}`); - expect(elicitation.answer.wait).toContain(`--flow ${state.id}`); - // Once the agent holds the link, the next wait is an ordinary one. + await open(); expect(codeOf(await wait())).toBe('CONVERSATION_WAITING'); }); - test('when Keep opens it in time, the wait goes on as usual', async () => { - rememberHandoff(ORG, USER, randomBytes(32).toString('base64url')); - service.tabWaiting(true); - const state = await open(); - fakePage(state, kLocal, service).hello(); - expect(codeOf(await wait())).not.toBe('CONVERSATION_NOT_OPENED_IN_KEEP'); - }); });