pilotswarm-cli-builder
Use when creating or updating a plugin-driven CLI/TUI app on top of PilotSwarm. Covers plugin.json branding, agent/skill layout, worker modules, keybinding/help sync, and the DevOps sample structure.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 16
- Forks
- 10
01 前言 Front Matter
- name
- pilotswarm-cli-builder
- description
- Use when creating or updating a plugin-driven CLI/TUI app on top of PilotSwarm. Covers plugin.json branding, agent/skill layout, worker modules, keybinding/help sync, and the DevOps sample structure.
02 资源文件 1
- 脚本scripts/extract.py7.5 KB
03 SKILL.md 正文
PilotSwarm CLI Builder
Build layered CLI/TUI apps on top of the shipped PilotSwarm interface.
Canonical References
- Source quickstart:
https://github.com/microsoft/PilotSwarm/blob/main/docs/quickstart/local.md - CLI guide:
https://github.com/microsoft/PilotSwarm/blob/main/docs/developer/building/cli-apps.md - CLI agent guide:
https://github.com/microsoft/PilotSwarm/blob/main/docs/developer/building/cli-agents.md - Keybindings:
https://github.com/microsoft/PilotSwarm/blob/main/docs/user-guide/keybindings.md - DevOps sample:
https://github.com/microsoft/PilotSwarm/tree/main/examples/devops-command-center
Preferred Structure
my-app/
├── .gitignore
├── .env.example
├── .model_providers.example.json
├── package.json
├── plugin/
│ ├── plugin.json
│ ├── agents/ # optional named workflows
│ ├── skills/
│ ├── .mcp.json
│ └── session-policy.json
├── scripts/
│ ├── run.sh
│ └── cleanup-local-db.js
├── worker-module.js
└── README.md
Workflow
- Identify whether the app should use the shipped TUI rather than a custom UI.
- Run a guided intake before scaffolding.
- Create
plugin/plugin.jsonwhen the user wants app branding. - Put reusable methods in
plugin/skills, executable actions in worker tools or MCP servers, and useplugin/agents/*.agent.mdonly for complex authored workflows or durable named entry points. Packages without agents remain valid and are progressively discoverable by Base Agent V2 sessions. - Every generated
.agent.mdmust includeschemaVersion: 1and aversionstring. Useversion: 1.0.0for new agents by default. When editing an existing agent, bump itsversionaccording to the app's versioning style; prefer SemVer when the app uses it. - Treat
plugin/agents/default.agent.mdas the app-wide default overlay under PilotSwarm's embedded framework base. It is not a selectable session agent — PilotSwarm excludes it from the agent picker, the client rejectscreateSessioncalls withagentId: "default", and the worker never adds it toallowedAgentNames. Do not name any other agent filedefault. - Put reusable domain knowledge in
plugin/skills/*/SKILL.md. - Put runtime tool handlers in
worker-module.js. - Add
session-policy.jsonif the user does not want generic sessions. The policy is enforced in both local and remote modes — the TUI reads it from the plugin directory even when there are no embedded workers. If the app should expose SDK-bundled optional agents, add them undercreation.bundledAgents, for example"bundledAgents": ["generic-crawler"]; remote-mode picker metadata expands those names into creatable agents. - Build
.env.exampleand a gitignored.envby copying/adapting the PilotSwarm repo's example env shape when the user wants runnable scaffolding. - Build
.model_providers.example.jsonand a gitignored.model_providers.jsonby copying/adapting the PilotSwarm repo's example model-catalog shape when the scaffold needs a custom model catalog. - Add checked-in scripts for launch and database cleanup (both local and remote modes).
- Make generated scripts executable and verify the executable bit.
- Add a README with local run instructions.
- When agents need durable structured memory or shared coordination state, use PilotSwarm's built-in facts tools (
store_fact,read_facts,delete_fact) as the primary memory layer. They are available to every agent session by default, including system agents, so do not build a separate fact table unless the app truly requires it. - When agents need recurring autonomous work, use durable timers:
cron(seconds=N, reason="...")for fixed intervals,cron_at(minute=M, hour=H, tz="Area/City", reason="...")for wall-clock schedules, andcron(action="cancel")/cron_at(action="cancel")to stop. Do not build wall-clock jobs by waking every N minutes to check the clock. - When generated agents delegate work, teach them to set
contract.wakeOn:anyfor chatty work,material_changefor finite task results and watcher changes, andcompletiononly for actual terminal lifecycle outcomes. A finite child's ordinary final reply leaves it alive and idle, so generated parents validate the result and close it explicitly withcomplete_agent. Parent coordination is reactive: qualifying updates wake the parent automatically, so never generate a parentwait/cronloop whose only action ischeck_agents. - Agents can read their context usage (current tokens, token limit) from the session status. The TUI displays this in the status bar. Use this for agents that need to manage context window budgets or trigger compaction.
- If the app relies on downloadable files, document the shipped files inspector behavior: binary artifacts download intact, browser previews are download-only for non-text files, and the shared files browser supports download/delete/open flows.
Guided Intake Questions
Before generating files, ask:
- Should the app allow generic sessions under the default agent, or should usage be steered into named agents through a restrictive session policy?
- Should local startup use a bootstrap
GITHUB_TOKEN, or will the first runtime provider be created through Admin Console/management API? - What should be used for
DATABASE_URLin.env? - What local database name should the scaffold use? If unspecified, default it explicitly to the workspace name.
- If the user has not specified the agent roster, what workflows should the app support so you can derive the first agent set?
- Which topology should the scaffold target?
- local-only, using Docker Postgres
- standard remote topology using AKS + PostgreSQL + Blob storage
- custom topology supplied by the user
Do not guess these answers when the user has not provided them. Offer the standard topology choices explicitly so the guided experience stays fast.
Env File Guidance
- Treat
DATABASE_URLas the canonical PostgreSQL connection input for LOCAL mode (embedded workers). Remote attach needs only the portal URL:pilotswarm remote --api-url <url>(auto Entra sign-in;--device-codefor headless hosts). - If the app needs a custom model catalog, check in a type-only
.model_providers.example.jsonand create the real.model_providers.jsonlocally from it. Add provider instances/credentials through Admin orPilotSwarmManagementClient, and configuresetModelDefault/setSystemModelDefault; do not put credentials ordefaultModelin new catalogs. - Do not copy a sample
toolCatalogopt-in without validating the target Chat Completions endpoint. Omit it by default; router names do not enable overflow dispatch. Put an approved policy on the model entry in its provider-type catalog, not in a prompt or environment flag. - For local-first scaffolds, offer GitHub Copilot as the first runtime provider type unless the user asks for another; do not hard-code a provider instance or credential into the catalog.
- For local-first scaffolds, do not include
LLM_PROVIDER_TYPE,LLM_ENDPOINT,LLM_API_KEY, orLLM_API_VERSIONby default. - Do not generate redundant
PGHOST,PGPORT,PGUSER,PGPASSWORD, orPGDATABASEentries unless the user explicitly needs them. - Prefer a checked-in
.env.exampleplus a local gitignored.env. - Prefer a checked-in
.model_providers.example.jsonplus a local gitignored.model_providers.json. - Add both
.envand.model_providers.jsonto.gitignorein runnable scaffolds. - Align the variable set with the chosen topology rather than blindly copying every sample env field.
- For local-first scaffolds, the default env surface should usually be
DATABASE_URL; addGITHUB_TOKENonly when using bootstrap compatibility. - Add optional storage or deployment variables only when the topology requires them.
- Only copy secrets from another repo or local file after the user explicitly asks for that behavior.
Database Cleanup Guidance
- Generate a single cleanup script (
scripts/cleanup-local-db.js) that handles both local and remote modes:node scripts/cleanup-local-db.js— uses.env(local)node scripts/cleanup-local-db.js remote— uses.env.remote
- Parse
sslmodefrom theDATABASE_URLand passssl: { rejectUnauthorized: false }to thepgclient when connecting to Azure PostgreSQL. Follow the pattern in the DevOps sample's cleanup script. - Query session IDs from CMS (
copilot_sessions.sessions) before dropping schemas. - In local mode, also remove local files for each session:
- Artifact directories at
~/.copilot/artifacts/<sessionId>/ - Session state dirs at
~/.copilot/session-state/<sessionId>/ - Session store archives at
~/.copilot/session-store/<sessionId>.tar.gzand.meta.json
- Artifact directories at
- In remote mode, skip local file cleanup (artifacts live in blob storage).
- Drop
duroxideandcopilot_sessionsschemas. - In remote mode, print the
kubectl rollout restartcommand to recreate schemas. - Wire
package.jsonscripts:"cleanup": "node scripts/cleanup-local-db.js""cleanup:remote": "node scripts/cleanup-local-db.js remote"
- Follow the pattern in PilotSwarm's DevOps sample
scripts/cleanup-local-db.js.
Launcher Script Guidance
- Generate a single
scripts/run.shthat supports both local and remote modes:./scripts/run.shor./scripts/run.sh local— local mode with embedded workers./scripts/run.sh remote— remote mode connecting to AKS workers
- Wire
package.jsonscripts to point atrun.sh:"start": "./scripts/run.sh"for local"start:remote": "./scripts/run.sh remote"for remote
- Use
.envfor local mode and.env.remotefor remote mode. The script selects the right file based on the mode argument. - Include preflight checks (env file exists, plugin dir exists, worker module exists for local).
- Use
exec pilotswarm ...for local andexec pilotswarm remote ...for remote. - Make the script executable and verify the executable bit after creation.
- Keep compatibility workarounds in the launcher or
postinstallscripts, not scattered across README steps. - A programmatic launcher can use
import { startTuiApp } from "pilotswarm"withstartTuiApp({ ...config, logFile: applicationLogPath })to give each application process its own diagnostic file. Custom paths create parent directories and truncate on startup; invalid paths or tracing setup failures reject, with no shared-log fallback. Omission keeps the legacy default. This is an API option, not a CLI flag; see the CLI guide's Programmatic TUI Hosts section for configuration and process-lifecycle details.
Validation Guidance
- When the user wants runnable scaffolding, do more than write files: install dependencies and run a smoke test.
- Do not treat
--helpoutput as proof that the app actually starts; prefer the real startup path when practical. - Check the declared runtime requirements and compare them against the current machine.
- If scripts are intended to be run directly, verify direct execution rather than only
node script.js. - If the scaffold defaults or inferred decisions matter, record them in the generated README.
Compatibility Guidance
- If the generated app hits a known dependency issue during setup, isolate the workaround in setup or launcher scripts and explain why it exists.
- Prefer deterministic fixes that can be re-applied after reinstall, such as
postinstallor a verified pre-launch patch step, over one-off manual instructions. - Remove or simplify compatibility shims once the upstream dependency is fixed.
Agent Derivation Guidance
- If the user names agents, scaffold those agents directly.
- If the user only describes workflows, derive a starter agent set from those workflows and explain the mapping.
- Keep the first scaffold minimal but coherent; do not invent a large agent roster without justification.
plugin.json Guidance
Use plugin.json for metadata and TUI branding.
Example:
{
"name": "devops",
"description": "DevOps Command Center",
"version": "1.0.0",
"tui": {
"title": "DevOps Command Center",
"splashFile": "./tui-splash.txt"
}
}
Guardrails
- Do not put tool implementations into agent markdown files.
- Do not model developer-facing builder behavior as runtime system agents.
- Keep prompts, skills, tool handlers, and branding in separate layers.
- If you add or change TUI keybindings, update help/keybinding surfaces together.
- Treat system-agent
initialPromptas bootstrap startup content, not a user-authored chat line. - Assume apps consume
pilotswarmandpilotswarm-sdk; built-in PilotSwarm plugins are embedded in those packages, not copied into the app repo. - Assume PostgreSQL-backed apps can opt into the built-in facts tools with agent
toolslists instead of re-implementing fact storage from scratch. - Install the matching
pilotswarm,pilotswarm-sdkand optional provider tarballs from public GitHub Releases usinghttps://github.com/microsoft/PilotSwarm/blob/main/docs/quickstart/packages.md. Preserve lock integrity and restore ignored downloads beforenpm ci. Use installed binaries instead of registry-auto-fetchingnpx -pcommands. - If the scaffold teaches artifact workflows, do not describe them as markdown-only; explain the shared binary-download contract too.
04 同仓库更多 Skills
pilotswarm-three-tier
Reference for adding a Tier 3 worker AKS cluster to a PilotSwarm deployment. Covers provisioning, identity, Dockerfile changes, entrypoint, manifests, and verification.
pilotswarm-sdk-builder
Use when creating or updating an SDK-first app on top of PilotSwarm. Covers the client/worker split, plugin layering, tool registration, tests, and the DevOps sample structure.
pilotswarm-portal-builder
Use when creating or updating a browser portal on top of PilotSwarm. Covers portal branding, plugin.json.portal, named-agent exposure, auth add-ons, and remote deployment wiring.
pilotswarm-knowledge-harvester
Use when an SDK or CLI app needs to ingest external sources into durable, searchable knowledge and an open knowledge graph. Covers enabling the EnhancedFactStore + GraphStore providers, authoring a crawler:true agent, the crawl→graph→reader flow, ACL/scopeKey evidence, and tests.
pilotswarm-hybrid-datastore
Use when a PilotSwarm app needs stock PostgreSQL for runtime storage plus HorizonDB for enhanced facts, semantic/lexical search, and the knowledge graph. Covers env topology, horizonConfigFromEnv wiring, harvester agents, Azure secret/resource guidance, and the rule that Docker defaults remain stock Postgres.
pilotswarm-duroxide-versioning
Use when changing PilotSwarm durable orchestration behavior, continue-as-new state, or replay-sensitive control flow.