-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(cli): answer workflow verbs typed at the CLI #1776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clay-good
wants to merge
4
commits into
main
Choose a base branch
from
claude/workflow-verb-cli-hint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0fbe702
fix(cli): answer workflow verbs typed at the CLI
clay-good 85624b8
fix(cli): answer the help paths and match each tool's spelling
clay-good 1ff760f
fix(cli): branch the workflow-verb hint on installed artifacts, not t…
clay-good 49cb77d
fix(cli): name the detected tool's spelling in the init answer
clay-good File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@fission-ai/openspec": patch | ||
| --- | ||
|
|
||
| Answer workflow verbs typed at the CLI with the invocation this project actually uses. `openspec propose`, `openspec explore`, `openspec apply` and the other workflow names no longer fail with a bare `unknown command`; they explain that workflows run inside the AI assistant and name the spelling each configured tool answers to, or point at `openspec init` or `openspec config profile` when the workflow is not installed. Real CLI commands (`new`, `update`, `archive`) and genuinely unknown commands are unchanged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| /** | ||
| * Workflow Verbs Typed At The CLI | ||
| * | ||
| * OpenSpec's workflows (`propose`, `explore`, `apply`, ...) run inside the | ||
| * user's AI assistant, not in the terminal. Users and agents nonetheless say | ||
| * and type "openspec propose" — it is the natural way to name the thing — and | ||
| * the bare `error: unknown command 'propose'` that came back taught them | ||
| * nothing. Agents in particular read that failure as permission to hand-build | ||
| * the artifacts with `openspec new change` plus manual file writes, bypassing | ||
| * the workflow entirely (#1221). | ||
| * | ||
| * So the verbs are registered as hidden commands whose whole job is to answer | ||
| * the question: this is a workflow, here is how *your* tools invoke it. That | ||
| * mirrors the treatment retired flags already get in the CLI — keep the name | ||
| * reachable so it can explain itself instead of failing generically. | ||
| */ | ||
|
|
||
| import type { AIToolOption } from './config.js'; | ||
| import { getAvailableTools } from './available-tools.js'; | ||
| import { getGlobalConfig, type Delivery } from './global-config.js'; | ||
| import { scanInstalledWorkflows } from './migration.js'; | ||
| import { ALL_WORKFLOWS } from './profiles.js'; | ||
| import { resolveWorkflowReference } from './command-surface.js'; | ||
|
|
||
| /** | ||
| * Workflow ids that the CLI already uses for real commands. `openspec new`, | ||
| * `openspec update`, and `openspec archive` do their own work, so those names | ||
| * are never rerouted to workflow guidance — the CLI command wins, as it | ||
| * always has. | ||
| */ | ||
| const CLI_RESERVED_WORKFLOW_IDS = new Set<string>(['new', 'update', 'archive']); | ||
|
|
||
| /** | ||
| * The workflow ids reachable as bare CLI verbs. Every workflow whose name is | ||
| * not already a CLI command; see CLI_RESERVED_WORKFLOW_IDS for the ones that | ||
| * are. | ||
| */ | ||
| export const WORKFLOW_VERBS: readonly string[] = ALL_WORKFLOWS.filter( | ||
| (workflowId) => !CLI_RESERVED_WORKFLOW_IDS.has(workflowId) | ||
| ); | ||
|
|
||
| /** | ||
| * The canonical reference every generated file is authored with. Per-tool | ||
| * spellings are rewritten from this form. | ||
| */ | ||
| function canonicalCommand(verb: string): string { | ||
| return `/opsx:${verb}`; | ||
| } | ||
|
|
||
| export interface WorkflowVerbGuidance { | ||
| /** The headline: what went wrong, in one sentence. */ | ||
| message: string; | ||
| /** Supporting lines, already ordered; may be empty. */ | ||
| details: string[]; | ||
| } | ||
|
|
||
| /** | ||
| * One invocation line per distinct spelling, labeled with the tools it serves | ||
| * when the project's tools disagree. | ||
| * | ||
| * Natural-language tools (no slash surface for skills) are grouped per tool | ||
| * rather than per reference: their line names the tool inside the sentence, so | ||
| * two such tools sharing a reference still need two lines. | ||
| */ | ||
| function invocationLines( | ||
| tools: AIToolOption[], | ||
| delivery: Delivery, | ||
| verb: string | ||
| ): string[] { | ||
| const lineToTools = new Map<string, string[]>(); | ||
| for (const tool of tools) { | ||
| const workflowReference = resolveWorkflowReference(tool.value, delivery, canonicalCommand(verb)); | ||
| if (!workflowReference) { | ||
| continue; | ||
| } | ||
| const line = workflowReference.naturalLanguage | ||
| ? `ask ${tool.name} to use ${workflowReference.reference}` | ||
| : workflowReference.reference; | ||
| lineToTools.set(line, [...(lineToTools.get(line) ?? []), tool.name]); | ||
| } | ||
| if (lineToTools.size === 1) { | ||
| return [...lineToTools.keys()]; | ||
| } | ||
| return [...lineToTools.entries()].map(([line, toolNames]) => `${line} (${toolNames.join(', ')})`); | ||
| } | ||
|
|
||
| /** | ||
| * Builds the answer for a workflow verb typed at the CLI, grounded in what is | ||
| * actually installed in this project. | ||
| * | ||
| * Three cases, in order of what the user can act on: | ||
| * - No OpenSpec tools detected: nothing is installed yet, so point at `init`. | ||
| * - Tools detected but this workflow is not among the installed ones: the | ||
| * invocation would be dead text, so point at the profile picker (#1076). | ||
| * - Otherwise: name the invocation each detected tool answers to. | ||
| * | ||
| * @param verb - A workflow id from WORKFLOW_VERBS | ||
| * @param projectPath - Directory to inspect for installed tools and workflows | ||
| */ | ||
| export function getWorkflowVerbGuidance(verb: string, projectPath: string): WorkflowVerbGuidance { | ||
| const message = `'${verb}' is an OpenSpec workflow, not a CLI command. Workflows run inside your AI assistant.`; | ||
| const tools = safeDetectTools(projectPath); | ||
|
|
||
| if (tools.length === 0) { | ||
| return { | ||
| message, | ||
| details: [ | ||
| `Fix: run 'openspec init' to install the workflows, then invoke ${canonicalCommand(verb)} in your assistant.`, | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| const installed = new Set(safeScanInstalledWorkflows(projectPath, tools)); | ||
| if (!installed.has(verb)) { | ||
| return { | ||
| message, | ||
| details: [ | ||
| `The ${verb} workflow is not installed in this project.`, | ||
| `Fix: run 'openspec config profile' to add it, then invoke ${canonicalCommand(verb)} in your assistant.`, | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| ], | ||
| }; | ||
| } | ||
|
|
||
| const delivery: Delivery = getGlobalConfig().delivery ?? 'both'; | ||
| const lines = invocationLines(tools, delivery, verb); | ||
| if (lines.length === 0) { | ||
| // Detected tools, but the delivery mode left none of them with an | ||
| // invocation to name. Stay syntax-neutral rather than invent one. | ||
| return { | ||
| message, | ||
| details: [`Fix: run 'openspec update' to regenerate this project's workflow files.`], | ||
| }; | ||
| } | ||
| if (lines.length === 1) { | ||
| return { message, details: [`Fix: run ${lines[0]} in your assistant.`] }; | ||
| } | ||
| return { | ||
| message, | ||
| details: ['Fix: run it in your assistant:', ...lines.map((line) => ` ${line}`)], | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Detection walks the project directory, and this runs on an error path: a | ||
| * permission error or an unreadable directory must not replace the guidance | ||
| * with a stack trace. An empty list degrades to the `init` wording, which is | ||
| * still true and still actionable. | ||
| */ | ||
| function safeDetectTools(projectPath: string): AIToolOption[] { | ||
| try { | ||
| return getAvailableTools(projectPath); | ||
| } catch { | ||
| return []; | ||
| } | ||
| } | ||
|
|
||
| function safeScanInstalledWorkflows(projectPath: string, tools: AIToolOption[]): string[] { | ||
| try { | ||
| return scanInstalledWorkflows(projectPath, tools); | ||
| } catch { | ||
| // Unknown rather than absent: treat every workflow as installed so the | ||
| // guidance names the invocation instead of sending the user to the | ||
| // profile picker over an unreadable directory. | ||
| return [...ALL_WORKFLOWS]; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.