stagent-setup
Bootstrap a dev workflow session (for /stagent:start): parse flags, derive a topic from the task description, call setup-workflow.sh, and hand off to the…
Create a new workflow suite from a natural-language description, or edit an existing one when --flow=<path> is passed. Dispatches the create-workflow stagent (plan → write → validate loop) — does not write files directly.
$ npx -y skills add jie-worldstatelabs/stagent --skill create-workflow --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/create-workflowContext preview
The summary Claude sees to decide when to auto-load this skill.
Create a new workflow suite from a natural-language description, or edit an existing one when --flow=<path> is passed. Dispatches the create-workflow stagent (plan → write → validate loop) — does not write files directly.
name: create description: "Create a new workflow suite from a natural-language description, or edit an existing one when --flow=<path> is passed. Dispatches the create-workflow stagent (plan → write → validate loop) — does not write files directly."
This skill **dispatches a stagent** that creates or edits a stagent definition. It does NOT write workflow files itself — the stagent's state machine (`planning → writing → validating`) does that, with validator-driven retry until `✓ Workflow validated` prints.
Both modes dispatch the same stagent at `$P/skills/create-workflow/workflow`. The difference is a single env var (`CREATE_WORKFLOW_CONTEXT`) passed at dispatch time.
<CRITICAL>
</CRITICAL>
`$CLAUDE_PLUGIN_ROOT` is NOT set in agent Bash-tool env. Use the session-cached path:
P=$(cat ~/.config/stagent/plugin-root 2>/dev/null) [[ -n $P && -d $P/scripts ]] || P=$(ls -d ~/.claude/plugins/cache/*/stagent/*/ 2>/dev/null | head -1)
Re-derive `$P` inside every Bash-tool call — shell vars don't persist across calls.
P=$(cat ~/.config/stagent/plugin-root 2>/dev/null)
[[ -n $P && -d $P/scripts ]] || P=$(ls -d ~/.claude/plugins/cache/*/stagent/*/ 2>/dev/null | head -1)
eval "$("$P/scripts/parse-workflow-flags.sh" '$ARGUMENTS')" || exit 1
"$P/scripts/print-create-banner.sh" "$MODE" "$WORKFLOW_FLAG" "$WF_TYPE"Values set by the parser:
Relay the banner to the user. If the parser emitted errors, hard stop.
if [[ "$MODE" == "cloud" ]]; then P=$(cat ~/.config/stagent/plugin-root 2>/dev/null) [[ -n $P && -d $P/scripts ]] || P=$(ls -d ~/.claude/plugins/cache/*/stagent/*/ 2>/dev/null | head -1) source "$P/scripts/lib.sh" cloud_is_logged_in && echo LOGGED_IN || echo NOT_LOGGED_IN fi
`NOT_LOGGED_IN` → hard stop: tell the user to run `/stagent:login` first. Do not dispatch.
For `$MODE == local`, skip this step — no login needed.
Skip this entire sub-step if `$WORKFLOW_FLAG` is empty (Create mode). Otherwise:
For `$WF_TYPE == local`:
if [[ -n "$WORKFLOW_FLAG" && "$WF_TYPE" == "local" ]]; then
SOURCE_DIR="${WORKFLOW_FLAG/#\~/$HOME}"
SOURCE_DIR="${SOURCE_DIR//\$HOME/$HOME}"
[[ -f "$SOURCE_DIR/workflow.json" ]] || { echo "No workflow.json at $SOURCE_DIR"; exit 1; }
fiFor `$WF_TYPE == cloud`: verify ownership, then download.
P=$(cat ~/.config/stagent/plugin-root 2>/dev/null) [[ -n $P && -d $P/scripts ]] || P=$(ls -d ~/.claude/plugins/cache/*/stagent/*/ 2>/dev/null | head -1) "$P/scripts/check-workflow-ownership.sh" "$WORKFLOW_FLAG"
Exit code is always 0; branch on the stdout token.
SOURCE_DIR="${HOME}/.config/stagent/workflows/${_WF_NAME}"
mkdir -p "$SOURCE_DIR"
cloud_fetch_workflow_from_name "$_WF_NAME" "$SOURCE_DIR"The stagent has a `setup_context` run_file that captures this env var. It's how the `planning` stage gets (a) whether this is create or edit, (b) the user's original description, and (c) the source dir for edit mode.
**Note:** `setup-workflow.sh` has no positional-argument slot for description — putting it in this env var is the only channel through which the planning stage receives it.
`publish_intent` mirrors `$MODE` and tells the stagent's `publishing` stage whether to push to the hub (`cloud`) or skip (`local`).
export CREATE_WORKFLOW_CONTEXT="$(jq -nc --arg desc "$DESCRIPTION" --arg pi "$MODE" \
'{mode:"create", description:$desc, publish_intent:$pi}')" export CREATE_WORKFLOW_CONTEXT="$(jq -nc --arg d "$SOURCE_DIR" --arg desc "$DESCRIPTION" --arg pi "$MODE" \
'{mode:"edit", source_dir:$d, description:$desc, publish_intent:$pi}')"Just a short kebab-case label for THIS stagent run's session (NOT the generated workflow's suffix — planning chooses that). Derive something from `$DESCRIPTION` (first few words kebabed), e.g. `create-lint-wf`, `edit-python-lib`.
Branch on `$MODE` to pick BOTH the right workflow source AND the session-mode for `setup-workflow.sh`:
P=$(cat ~/.config/stagent/plugin-root 2>/dev/null)
[[ -n $P && -d $P/scripts ]] || P=$(ls -d ~/.claude/plugins/cache/*/stagent/*/ 2>/dev/null | head -1)
"$P/scripts/setup-workflow.sh" \
--mode=cloud \
--topic="<slug-from-step-3>" \
--flow="cloud://create-template"A Claude Code plugin that runs config-driven development workflows as a state machine. You declare stages, transitions, and inputs in a single workflow.json; the plugin's hooks and scripts drive the loop.
Repo: jie-worldstatelabs/stagent
Bootstrap a dev workflow session (for /stagent:start): parse flags, derive a topic from the task description, call setup-workflow.sh, and hand off to the…
Drive the dev workflow state machine: read state.md, execute the current stage (inline or subagent), transition via update-status.sh, loop until terminal.…