## Summary
Introduces a configurable workflow state machine that replaces all hardcoded
state labels. The default workflow matches current behavior exactly, ensuring
backward compatibility.
## Architecture
### lib/workflow.ts — Core workflow engine
XState-style statechart configuration:
```typescript
type StateConfig = {
type: 'queue' | 'active' | 'hold' | 'terminal';
role?: 'dev' | 'qa';
label: string;
color: string;
priority?: number;
on?: Record<string, TransitionTarget>;
};
```
All behavior is derived from the config:
- Queue states: `type: 'queue'`, grouped by role, ordered by priority
- Active states: `type: 'active'` — worker occupied
- Transitions: defined with optional actions (gitPull, detectPr, closeIssue, reopenIssue)
- Labels and colors: derived from state.label and state.color
### Derivation functions
- `getStateLabels()` — all labels for issue tracker sync
- `getLabelColors()` — label → color mapping
- `getQueueLabels(role)` — queue labels for a role, ordered by priority
- `getActiveLabel(role)` — the active/in-progress label for a role
- `getRevertLabel(role)` — queue label to revert to on failure
- `detectRoleFromLabel()` — detect role from a queue label
- `getCompletionRule(role, result)` — derive transition rule from config
## Files Changed
- **lib/workflow.ts** — NEW: workflow engine and default config
- **lib/providers/provider.ts** — deprecate STATE_LABELS, LABEL_COLORS; derive from workflow
- **lib/providers/github.ts** — use workflow config for label operations
- **lib/providers/gitlab.ts** — use workflow config for label operations
- **lib/services/pipeline.ts** — use getCompletionRule() from workflow
- **lib/services/tick.ts** — use workflow for queue/active labels
- **lib/services/health.ts** — use workflow for active/revert labels
- **lib/tools/work-start.ts** — use workflow for target label
## Backward Compatibility
- DEFAULT_WORKFLOW matches current hardcoded behavior exactly
- Deprecated exports kept for any external consumers
- No breaking changes to tool interfaces or project state
## Future Work
- Load per-project workflow overrides from projects.json
- User-facing config in projects/workflow.json
- Tool schema generation from workflow states
This commit is contained in:
@@ -15,6 +15,7 @@ import { dispatchTask } from "../dispatch.js";
|
||||
import { findNextIssue, detectRoleFromLabel, detectLevelFromLabels } from "../services/tick.js";
|
||||
import { isDevLevel } from "../tiers.js";
|
||||
import { requireWorkspaceDir, resolveProject, resolveProvider, getPluginConfig } from "../tool-helpers.js";
|
||||
import { DEFAULT_WORKFLOW, getActiveLabel } from "../workflow.js";
|
||||
|
||||
export function createWorkStartTool(api: OpenClawPluginApi) {
|
||||
return (ctx: ToolContext) => ({
|
||||
@@ -43,6 +44,9 @@ export function createWorkStartTool(api: OpenClawPluginApi) {
|
||||
const { project } = await resolveProject(workspaceDir, groupId);
|
||||
const { provider } = await resolveProvider(project);
|
||||
|
||||
// TODO: Load per-project workflow when supported
|
||||
const workflow = DEFAULT_WORKFLOW;
|
||||
|
||||
// Find issue
|
||||
let issue: { iid: number; title: string; description: string; labels: string[]; web_url: string; state: string };
|
||||
let currentLabel: StateLabel;
|
||||
@@ -52,14 +56,14 @@ export function createWorkStartTool(api: OpenClawPluginApi) {
|
||||
if (!label) throw new Error(`Issue #${issueIdParam} has no recognized state label`);
|
||||
currentLabel = label;
|
||||
} else {
|
||||
const next = await findNextIssue(provider, roleParam);
|
||||
const next = await findNextIssue(provider, roleParam, workflow);
|
||||
if (!next) return jsonResult({ success: false, error: `No issues available. Queue is empty.` });
|
||||
issue = next.issue;
|
||||
currentLabel = next.label;
|
||||
}
|
||||
|
||||
// Detect role
|
||||
const detectedRole = detectRoleFromLabel(currentLabel);
|
||||
const detectedRole = detectRoleFromLabel(currentLabel, workflow);
|
||||
if (!detectedRole) throw new Error(`Label "${currentLabel}" doesn't map to a role`);
|
||||
const role = roleParam ?? detectedRole;
|
||||
if (roleParam && roleParam !== detectedRole) throw new Error(`Role mismatch: "${currentLabel}" → ${detectedRole}, requested ${roleParam}`);
|
||||
@@ -72,8 +76,10 @@ export function createWorkStartTool(api: OpenClawPluginApi) {
|
||||
if (getWorker(project, other).active) throw new Error(`Sequential roleExecution: ${other.toUpperCase()} is active`);
|
||||
}
|
||||
|
||||
// Get target label from workflow
|
||||
const targetLabel = getActiveLabel(workflow, role);
|
||||
|
||||
// Select level
|
||||
const targetLabel: StateLabel = role === "dev" ? "Doing" : "Testing";
|
||||
let selectedLevel: string, levelReason: string, levelSource: string;
|
||||
if (levelParam) {
|
||||
selectedLevel = levelParam; levelReason = "LLM-selected"; levelSource = "llm";
|
||||
|
||||
Reference in New Issue
Block a user