Back to skills
SKILL.md
Flow
ASecurityProgrammable cross-harness workflows via cospan (`cospan_flow` MCP or `cospan flow` CLI) using `agent`, `synthesize`, `orchestrate`, and `refine` primitives.
- 181 stars
- 0 votes
- 0 copies
- 0 views
- Added December 3, 2026
Works with
Security analysis
100/100npx -y skills add keli-wen/cospan --skill flow --agent claude-codeAre you the author of Flow?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/keli-wen-flow)---
name: flow
description: Programmable cross-harness workflows via cospan (`cospan_flow` MCP or `cospan flow` CLI) using `agent`, `synthesize`, `orchestrate`, and `refine` primitives.
---
# $cospan:flow — Cross-Harness Programmable Workflows
Run saved flows — workspace-first (`<workspace>/.cospan/flows/<name>/flow.mjs`, default for repo workflows and shadowing global `~/.cospan/flows/<name>/flow.mjs`, or single-file `<name>.mjs`) — or pass an explicit `.mjs` file / flow directory path via `cospan_flow` (preferred) or CLI:
- **MCP**: `cospan_flow({ cwd, flow: "<name-or-path>", prompt: "<prompt>" })` -> `cospan_wait({ cwd, id: "<flow-id>", timeout: "30m" })`
- **CLI fallback**: `node "<skill-dir>/../../bin/cospan.mjs" flow <name-or-path> --prompt "<prompt>"` -> `node "<skill-dir>/../../bin/cospan.mjs" wait <flow-id> --timeout 30m` (profile: `node "<skill-dir>/../../bin/cospan.mjs" flow trace [<flow-id>] [--markdown|--json]`)
## Four Orthogonal Primitives (`import { agent, synthesize, orchestrate, refine } from 'cospan/flow'`)
Mapped directly to Anthropic's effective agent workflow patterns:
1. **`agent('<harness>/<model-id>', options)` (Chaining / Routing / Parallelism)**: Stateless preset using globally unique `<harness>/<exact-model-id>` (e.g. `codex/gpt-6.2-sol`, `agy/gemini-4-neon`, `claude/claude-sonnet-5-5`, `dsh/<provider>/<model>`, `grok/grok-4.7`), with optional `{ effort, readonly, timeout, cwd, instructions, description, schema, role }`. Compose with plain JS `await`, `if`, `Promise.all`, and `session.touches(globs)`. Calling `await coderAgent.run(prompt, turnOpts?)` (optionally passing `{ cwd }` for worktree-isolated parallelism) returns a resumable `Session` (`{ text, data, resumable, cwd, baseHead, touchedFiles, touches(globs), diff, turnDiff, continue(nextPrompt, turnOpts?) }`).
2. **`synthesize(prompt, { agents, synthesizer, stage? })` (Blind Parallel Analysis & Synthesis)**: Runs `agents` independently in parallel under `readonly: true`, then synthesizes consensus and trade-offs via `synthesizer`.
3. **`orchestrate(prompt, { lead, workers, isolation?, stage? })` (Dynamic Orchestrator-Workers)**: Pass `workers: { explorer: explorerAgent, coder: coderAgent }` (or `{ agent, description }` entries to populate the lead's Worker Selection Table); `lead` dynamically spawns `0..N` parallel workers via `cospan flow spawn` and collects batches via `cospan wait <id1> <id2> ...`, returning `lead`'s resumable `Session` (`leadSession`) so subsequent `refine()` or `.continue()` talks directly to `lead` while retaining access to the worker roster. `isolation` (`"auto"` default | `"shared"` | `"worktree"`) is a prompt-level coordination suggestion injected into `lead` (not runtime-enforced).
4. **`refine(session, { evaluator, criteria?, maxRounds = 2, stage? })` (General `Session -> Session` Evaluator-Optimizer)**: Accepts any `Session` handle (`agent.run`, `orchestrate`, or prior `refine`) and returns a chainable `Session` with `.passed`, `.blocked`, `.verdict` (`'pass' | 'revise' | 'blocked'`), `.rounds` (fix cycles executed, `0..=maxRounds`), `.summary`, `.feedback`, and `.evaluations`. `evaluator` accepts an `agent(...)` preset (`readonly: true`, L0 git workspace pointer with `baseHead` and evaluator session reuse via `.continue()`) or a JS function `(session, { round, stage, criteria }) => { pass, summary?, feedback? }` for deterministic shell/test checks. Set `maxRounds: 0` for one-shot evaluation without rework.
## Core Flow Principles
1. **Default to `<workspace>/.cospan/flows/<name>/` when authoring flows**: Save any workflow that references repo docs, verification gates, or branch conventions (`AGENTS.md`, `REVIEW.md`, `SIMPLIFY.md`, test commands) inside `<workspace>/.cospan/flows/<name>/flow.mjs` so it stays version-controlled and shared with the repo (workspace flows automatically shadow same-named global flows). Reserve `~/.cospan/flows/<name>/` strictly for personal, repo-agnostic utilities.
2. **Keep `.mjs` pure orchestration & never wrap repo docs**: Reference repo-native guides directly via path pointers (`Follow AGENTS.md`, `Follow REVIEW.md`, `Follow SIMPLIFY.md`)—never restate them into duplicate wrapper `.md` files. Only colocate a `.md` file alongside `flow.mjs` for genuinely flow-specific prompt text and import it via `import taskPrompt from './task.md'` (`.md` and `.txt` resolve to UTF-8 strings natively).
3. **Progressive disclosure over prompt stuffing**: Pass compact L0 pointers/manifests (issue ID, `baseHead`, changed/untracked file list, `diff --stat`) and let agents fetch diffs and files via commands on demand instead of pasting raw diffs or full manuals.
4. **Closed session pipelines**: Chain `let coderSession = await coderAgent.run(...); coderSession = await refine(coderSession, ...); return await coderSession.continue(...)` directly with zero wrapper unwrapping.
5. **Occam's Razor on primitives**: Use plain JS `await` / `if` / `Promise.all` for simple chaining, branching, and fan-out; reach for `synthesize`, `orchestrate`, or `refine` only when blind deliberation, dynamic fan-out, or stateful evaluation-optimization loops add real value.
6. **Progress-first resilience — never downgrade unresolved review blockers**: Reserve early aborts for `session.blocked` (true P0 hazards: broken invariants, security/data-loss risk, or missing human decision). When a correctness `review` loop exhausts `maxRounds` with real `revise` blockers still open, keep the deliverable moving but surface them prominently as **Unresolved Review Blockers requiring human/host sign-off**—never relabel them as `non-blocking`. Reserve non-blocking `FYI` downgrades strictly for optional polish passes such as `simplify` (capped at `maxRounds: 1`).
7. **Parallelize independent work; chain dependent passes**: Fan out genuinely independent read-only lenses (via `Promise.all` or `synthesize`, e.g. a standalone multi-lens review report) and partition parallel writers by core conflict domain instead of serializing unrelated work. Keep dependent review-fix passes (e.g. correctness `review` -> post-fix `simplify`) cleanly chained with native `refine()` instead of hand-rolling custom JS evaluators around LLM agents.
8. **Verify locally before external side effects**: Run fast targeted checks during iteration, then complete full gates and isolated interactive/smoke verification *before* preview deployments, PR publication, or external notifications so defects are caught before triggering repeated build-and-deploy cycles.
9. **Keep machine facts out of LLM copy-paste**: Prefer deterministic tool/JS ground truth over asking LLMs to transcribe structured payloads or regex-parsing their prose—`refine()` builds L0 git manifests automatically, and post-step telemetry (such as attaching `trace.toMarkdown()` / `trace.upsertIn(body)` to a PR/MR via `gh pr edit`) should run in best-effort JS (`try/catch`) *after* the publishing turn finishes so the timeline is complete, verbatim, and never fails delivery.
10. **Self-evident, unabbreviated names in `.mjs`**: Since `.mjs` has no static type annotations, avoid abbreviations or vague names (`work`, `task`, `note`, `res`) in the core loop—name agents by role (`coderAgent`, `codeReviewer`, `diffSimplifier`), resumable handles `...Session` (`coderSession`), model inputs `...Prompt` / `...Instructions` (`issuePrompt`, `openPrPrompt`), and intermediate data by full domain nouns (`unresolvedBlockers`).
## Chainable Example (`.cospan/flows/dev/flow.mjs`)
```js
import { agent, refine } from 'cospan/flow';
// Prefer globally unique `<harness>/<exact-model-id>` identifiers for version determinism:
const coderAgent = agent('agy/gemini-4-neon', {
effort: 'high',
instructions: 'Follow AGENTS.md and run targeted checks before finishing.',
});
const codeReviewer = agent('codex/gpt-6.2-sol', { effort: 'high', readonly: true });
const diffSimplifier = agent('agy/gemini-4-neon', { effort: 'high', readonly: true });
export default async ({ prompt: issuePrompt, cwd, trace }) => {
let coderSession = await coderAgent.run(issuePrompt, { stage: 'dev' });
const unresolvedBlockers = [];
const simplificationNotes = [];
coderSession = await refine(coderSession, {
evaluator: codeReviewer,
criteria: 'Follow REVIEW.md.',
maxRounds: 2,
stage: 'review',
});
if (coderSession.blocked) return coderSession; // halt only on true P0 blockers
if (!coderSession.passed) {
unresolvedBlockers.push(coderSession.feedback || coderSession.summary);
}
coderSession = await refine(coderSession, {
evaluator: diffSimplifier,
criteria: 'Follow SIMPLIFY.md.',
maxRounds: 1,
stage: 'simplify',
});
if (coderSession.blocked) return coderSession;
if (!coderSession.passed) {
simplificationNotes.push(coderSession.feedback || coderSession.summary);
}
const blockerSuffix = unresolvedBlockers.length
? `\n\n## Unresolved Review Blockers (Requires Human/Host Sign-Off — Do Not Auto-Merge)\n- ${unresolvedBlockers.join('\n- ')}`
: '';
const simplifySuffix = simplificationNotes.length
? `\n\n## Optional Simplification Notes (non-blocking)\n- ${simplificationNotes.join('\n- ')}`
: '';
const openPrPrompt =
`Run verification checks and open the PR.${blockerSuffix}${simplifySuffix}`;
const publishedSession = await coderSession.continue(openPrPrompt, { stage: 'pr' });
// Best-effort post-step: attach trace.upsertIn(prBody) via JS/gh after `pr` finishes
return publishedSession;
};
```
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.