@dv.nghiem/flowdeck 0.3.9 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +13 -21
  2. package/dist/agents/code-explorer.d.ts.map +1 -1
  3. package/dist/agents/mapper.d.ts.map +1 -1
  4. package/dist/agents/orchestrator.d.ts.map +1 -1
  5. package/dist/agents/planner.d.ts.map +1 -1
  6. package/dist/agents/specialist.d.ts.map +1 -1
  7. package/dist/dashboard/server.mjs +12 -2
  8. package/dist/hooks/compaction-hook.d.ts +1 -2
  9. package/dist/hooks/compaction-hook.d.ts.map +1 -1
  10. package/dist/hooks/file-tracker.d.ts +6 -0
  11. package/dist/hooks/file-tracker.d.ts.map +1 -1
  12. package/dist/hooks/notifications.d.ts +73 -8
  13. package/dist/hooks/notifications.d.ts.map +1 -1
  14. package/dist/hooks/notifications.test.d.ts +14 -0
  15. package/dist/hooks/notifications.test.d.ts.map +1 -0
  16. package/dist/hooks/session-idle-hook.d.ts +5 -3
  17. package/dist/hooks/session-idle-hook.d.ts.map +1 -1
  18. package/dist/hooks/session-start.d.ts.map +1 -1
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +822 -796
  21. package/dist/lib/completion-validator.d.ts +51 -0
  22. package/dist/lib/completion-validator.d.ts.map +1 -0
  23. package/dist/lib/recommended-question.d.ts +24 -0
  24. package/dist/lib/recommended-question.d.ts.map +1 -0
  25. package/dist/lib/research-gate.d.ts +97 -0
  26. package/dist/lib/research-gate.d.ts.map +1 -0
  27. package/dist/lib/research-gate.test.d.ts +2 -0
  28. package/dist/lib/research-gate.test.d.ts.map +1 -0
  29. package/dist/mcp/index.d.ts +12 -2
  30. package/dist/mcp/index.d.ts.map +1 -1
  31. package/dist/services/codegraph.d.ts +36 -0
  32. package/dist/services/codegraph.d.ts.map +1 -0
  33. package/dist/services/codegraph.test.d.ts +2 -0
  34. package/dist/services/codegraph.test.d.ts.map +1 -0
  35. package/dist/services/question-guard.d.ts +4 -0
  36. package/dist/services/question-guard.d.ts.map +1 -1
  37. package/dist/services/recommended-question.test.d.ts +2 -0
  38. package/dist/services/recommended-question.test.d.ts.map +1 -0
  39. package/dist/services/supervisor-binding.d.ts +3 -1
  40. package/dist/services/supervisor-binding.d.ts.map +1 -1
  41. package/dist/tools/codebase-index.d.ts +30 -0
  42. package/dist/tools/codebase-index.d.ts.map +1 -0
  43. package/dist/tools/codebase-index.test.d.ts +2 -0
  44. package/dist/tools/codebase-index.test.d.ts.map +1 -0
  45. package/dist/tools/codegraph-tool.d.ts +3 -0
  46. package/dist/tools/codegraph-tool.d.ts.map +1 -0
  47. package/dist/tools/planning-state-lib.d.ts +23 -0
  48. package/dist/tools/planning-state-lib.d.ts.map +1 -1
  49. package/docs/agents/index.md +154 -0
  50. package/docs/commands/fd-ask.md +71 -39
  51. package/docs/commands/fd-checkpoint.md +63 -8
  52. package/docs/commands/fd-deploy-check.md +166 -9
  53. package/docs/commands/fd-design.md +101 -0
  54. package/docs/commands/fd-discuss.md +87 -20
  55. package/docs/commands/fd-doctor.md +100 -13
  56. package/docs/commands/fd-done.md +215 -0
  57. package/docs/commands/fd-execute.md +104 -0
  58. package/docs/commands/fd-fix-bug.md +144 -24
  59. package/docs/commands/fd-map-codebase.md +85 -21
  60. package/docs/commands/fd-multi-repo.md +155 -40
  61. package/docs/commands/fd-new-feature.md +63 -19
  62. package/docs/commands/fd-plan.md +80 -27
  63. package/docs/commands/fd-quick.md +143 -29
  64. package/docs/commands/fd-reflect.md +81 -13
  65. package/docs/commands/fd-resume.md +65 -8
  66. package/docs/commands/fd-status.md +80 -12
  67. package/docs/commands/fd-suggest.md +114 -0
  68. package/docs/commands/fd-translate-intent.md +69 -9
  69. package/docs/commands/fd-verify.md +71 -14
  70. package/docs/commands/fd-write-docs.md +121 -8
  71. package/docs/concepts/architecture.md +163 -0
  72. package/docs/concepts/governance.md +242 -0
  73. package/docs/concepts/intelligence.md +145 -0
  74. package/docs/concepts/multi-repo.md +227 -0
  75. package/docs/concepts/workflows.md +205 -0
  76. package/docs/configuration/index.md +208 -0
  77. package/docs/configuration/opencode-settings.md +98 -0
  78. package/docs/getting-started/first-project.md +126 -0
  79. package/docs/getting-started/installation.md +73 -0
  80. package/docs/getting-started/quick-start.md +74 -0
  81. package/docs/index.md +36 -72
  82. package/docs/reference/hooks.md +176 -0
  83. package/docs/reference/rules.md +109 -0
  84. package/docs/skills/code-review.md +47 -0
  85. package/docs/skills/index.md +148 -0
  86. package/docs/skills/planning.md +39 -0
  87. package/package.json +1 -1
  88. package/src/commands/fd-discuss.md +74 -10
  89. package/src/commands/fd-done.md +196 -0
  90. package/src/commands/fd-execute.md +43 -6
  91. package/src/commands/fd-fix-bug.md +43 -6
  92. package/src/commands/fd-map-codebase.md +99 -19
  93. package/src/commands/fd-new-feature.md +14 -5
  94. package/src/commands/fd-plan.md +38 -1
  95. package/src/commands/fd-quick.md +1 -1
  96. package/src/commands/fd-resume.md +1 -1
  97. package/src/commands/fd-status.md +1 -1
  98. package/src/commands/fd-verify.md +16 -2
  99. package/src/commands/fd-write-docs.md +30 -5
  100. package/src/skills/context-load/SKILL.md +1 -1
  101. package/dist/hooks/memory-hook.d.ts +0 -28
  102. package/dist/hooks/memory-hook.d.ts.map +0 -1
  103. package/dist/services/memory-store.d.ts +0 -73
  104. package/dist/services/memory-store.d.ts.map +0 -1
  105. package/dist/services/memory-store.test.d.ts +0 -2
  106. package/dist/services/memory-store.test.d.ts.map +0 -1
  107. package/dist/tools/memory-search.d.ts +0 -3
  108. package/dist/tools/memory-search.d.ts.map +0 -1
  109. package/dist/tools/memory-status.d.ts +0 -3
  110. package/dist/tools/memory-status.d.ts.map +0 -1
  111. package/docs/USER_GUIDE.md +0 -20
  112. package/docs/agents.md +0 -544
  113. package/docs/best-practices.md +0 -47
  114. package/docs/commands/fd-new-project.md +0 -24
  115. package/docs/commands.md +0 -557
  116. package/docs/configuration.md +0 -325
  117. package/docs/design-first-workflow.md +0 -94
  118. package/docs/feature-integration-architecture.md +0 -227
  119. package/docs/installation.md +0 -123
  120. package/docs/intelligence.md +0 -370
  121. package/docs/memory.md +0 -69
  122. package/docs/multi-repo.md +0 -201
  123. package/docs/notifications.md +0 -170
  124. package/docs/optimization-baseline.md +0 -21
  125. package/docs/quick-start.md +0 -197
  126. package/docs/rules.md +0 -432
  127. package/docs/skills.md +0 -417
  128. package/docs/workflows.md +0 -134
  129. package/src/commands/fd-new-project.md +0 -114
@@ -1,18 +1,75 @@
1
- ---
2
- description: Review code quality, security, and conventions — runs parallel @reviewer + @security-auditor agents
3
- argument-hint: "[file-pattern|dir|stage number]"
4
- ---
1
+ # /fd-verify
5
2
 
6
- Run the FlowDeck code review workflow. Reviews can target:
7
- - **Specific files or directories** — `fd-verify src/services/`
8
- - **Git staged changes** — `fd-verify staged`
9
- - **Full project** — `fd-verify`
3
+ **Purpose:** Full verification pipeline after feature implementation — runs tests, code review, security scan, and deploy check; updates STATE.md to `verified` on full pass.
10
4
 
11
- ## What Next?
5
+ ## Usage
12
6
 
13
- 1. **Fix issues found** → `/fd-fix-bug [issue]`
14
- 2. **Create deployment checkpoint** → `/fd-checkpoint`
15
- 3. **Deploy to production** → `/fd-deploy-check`
16
- 4. **View project dashboard** → `/fd-dashboard`
7
+ /fd-verify [--phase=N] [--env=staging|production]
17
8
 
18
- Type the number or command to proceed.
9
+ ## What Happens
10
+
11
+ 1. **Pre-flight checks.**
12
+ - Verify `.planning/` and STATE.md exist
13
+ - Read current phase N from STATE.md
14
+ - Warn if `steps_complete` is empty (no steps executed yet)
15
+
16
+ 2. **Gather scope.**
17
+ - Collect changed files via `git diff --name-only HEAD`
18
+ - If no changes, use all files in the current phase directory
19
+ - Run `codegraph action=check` — if available, use `codegraph_impact` on changed files to surface dependent modules not caught by `git diff`
20
+
21
+ 3. **Run four checks in parallel:**
22
+
23
+ - **Tests (@tester):** `npm test` — all tests must pass, no failures or unexplained skips
24
+
25
+ - **Code Review (@reviewer):** Review all changed files — security (secrets, injection, auth gaps), quality (critical bugs, error handling, TDD discipline), conventions (naming, patterns, import style), >= 80% test coverage for changed files. If UI-heavy: design fidelity review against approved design artifact
26
+
27
+ - **UI Design Review (@design):** If UI-heavy — compare implemented UI to approved design artifact, report on hierarchy, spacing, CTA flow, responsiveness, accessibility, and missing state coverage. Fail verification on severe design fidelity mismatch
28
+
29
+ - **Security Scan (@security-auditor):** No hardcoded secrets, input validation at trust boundaries, auth/authz on all protected routes, no CRITICAL/HIGH vulnerabilities
30
+
31
+ - **Deploy Check:** `npm audit --audit-level=high` and `npm run build` — no HIGH/CRITICAL CVEs, build must succeed
32
+
33
+ 4. **Aggregate results.** Present consolidated table with pass/fail status for each check.
34
+
35
+ 5. **Go/No-Go decision.**
36
+
37
+ **VERIFIED (all checks pass):**
38
+ - Update STATE.md: `status: verified`, `last_action: "Phase N verified — all checks passed"`, `verified_at: <timestamp>`
39
+ - Report next steps (deploy, increment phase, etc.)
40
+
41
+ **NOT VERIFIED (one or more checks fail):**
42
+ - List required fixes
43
+ - Do NOT update STATE.md to verified status
44
+ - Report suggested next step (run `/fd-execute` for fixes, then `/fd-verify` again)
45
+
46
+ 6. **No-Go conditions (automatic NOT VERIFIED):** test failures, CRITICAL security vulnerability, unpatched HIGH/CRITICAL CVE, build error, CRITICAL code review finding.
47
+
48
+ ## Output / State
49
+
50
+ STATE.md on verified:
51
+ ```yaml
52
+ status: verified
53
+ last_action: "Phase N verified — all checks passed"
54
+ verified_at: "<timestamp>"
55
+ ```
56
+
57
+ ## Examples
58
+
59
+ ```
60
+ /fd-verify
61
+ ```
62
+
63
+ Run full verification pipeline for the current phase.
64
+
65
+ ```
66
+ /fd-verify --phase=2 --env=staging
67
+ ```
68
+
69
+ Verify phase 2 and run deploy check against staging environment.
70
+
71
+ ## Related Commands
72
+
73
+ - `/fd-execute` — implement the feature before verification
74
+ - `/fd-plan` — create the plan that was verified against
75
+ - `/fd-resume` — reload state after making fixes
@@ -1,10 +1,123 @@
1
- ---
2
- description: Write documentation — explore public APIs, writer drafts, reviewer accuracy check
3
- ---
4
- Run the FlowDeck write-docs workflow to generate accurate project documentation.
1
+ # /fd-write-docs
5
2
 
6
- ## What Next?
3
+ **Purpose:** Explore APIs and generate accurate, up-to-date documentation from the codebase.
7
4
 
8
- 1. **Review documentation** → `/fd-verify staged`
9
- 2. **Deploy check** → `/fd-deploy-check`
10
- 3. **Create checkpoint** → `/fd-checkpoint`
5
+ ## Usage
6
+
7
+ /fd-write-docs [--scope=path] [--format=api,guide,readme]
8
+
9
+ ## Arguments
10
+
11
+ - `--scope=path` (optional) — limit documentation scope to a specific path
12
+ - `--format=api|guide|readme` (optional) — output format: `api` (API reference), `guide` (usage guide), `readme` (README). Default: all formats
13
+
14
+ ## What Happens
15
+
16
+ ### Step 1: CodeGraph Intelligence Check
17
+
18
+ Before any file exploration, check if codegraph provides a pre-built symbol index:
19
+ ```
20
+ codegraph action=check
21
+ ```
22
+
23
+ - **If codegraph indexed (fresh)**: Use `codegraph_search`, `codegraph_explore`, `codegraph_node` to enumerate exported symbols and API entry points. Log: "codegraph available — using symbol index for API discovery".
24
+ - **If codegraph absent or stale**: Fall through to @mapper-based exploration.
25
+
26
+ ### Step 2: Explore APIs
27
+
28
+ **If codegraph is available:**
29
+ ```
30
+ codegraph_search("export ") # exported symbols
31
+ codegraph_explore("<scope or src/>") # survey module structure
32
+ codegraph_context("<key entry points>") # full context per area
33
+ ```
34
+
35
+ **If codegraph is not available:**
36
+ Spawn `@mapper` to:
37
+ - Find all exported functions, classes, and types
38
+ - Identify public API entry points
39
+ - Map key workflows and integration points
40
+
41
+ Fallback commands:
42
+ ```bash
43
+ grep -rn "export " src/ --include="*.ts"
44
+ grep -rn "export interface\|export type\|export class" src/ --include="*.ts"
45
+ ```
46
+
47
+ ### Step 3: Draft Documentation
48
+
49
+ Spawn `@writer` to produce:
50
+
51
+ **API Reference:**
52
+ ```markdown
53
+ ## functionName(param: Type): ReturnType
54
+
55
+ Description of what the function does.
56
+
57
+ **Parameters:**
58
+ - `param` (Type) — description
59
+
60
+ **Returns:** description
61
+
62
+ **Example:**
63
+ \`\`\`typescript
64
+ const result = functionName(value);
65
+ \`\`\`
66
+ ```
67
+
68
+ **Usage Guide:**
69
+ - Step-by-step workflow with examples
70
+ - Common patterns and best practices
71
+ - Configuration options
72
+
73
+ **Troubleshooting:**
74
+ - Common errors and their solutions
75
+
76
+ ### Step 4: Review for Accuracy
77
+
78
+ Spawn `@reviewer` to verify:
79
+ - Every documented function/method actually exists
80
+ - Parameter types match the actual signatures
81
+ - Examples are syntactically correct
82
+ - No outdated API references
83
+
84
+ If codegraph is available: use `codegraph_node` to verify specific function signatures against documentation.
85
+
86
+ ### Step 5: Finalize
87
+
88
+ Writer incorporates feedback and writes final docs to:
89
+ - `README.md` — project overview and quick start
90
+ - `docs/API.md` — complete API reference
91
+ - `docs/USER_GUIDE.md` — detailed usage guide
92
+
93
+ ## Output / State
94
+
95
+ Updated documentation files:
96
+ - `README.md` — project overview and quick start
97
+ - `docs/API.md` — complete API reference
98
+ - `docs/USER_GUIDE.md` — detailed usage guide
99
+
100
+ Report: files written/updated, public APIs documented, any gaps found, codegraph used status.
101
+
102
+ ## Examples
103
+
104
+ **Generate all documentation formats:**
105
+ ```
106
+ /fd-write-docs
107
+ ```
108
+
109
+ **Generate only API reference for a specific scope:**
110
+ ```
111
+ /fd-write-docs --scope=src/api --format=api
112
+ ```
113
+
114
+ **Generate README for the project root:**
115
+ ```
116
+ /fd-write-docs --format=readme
117
+ ```
118
+
119
+ ## Related Commands
120
+
121
+ - `/fd-map-codebase` — generate the codebase documentation that informs API exploration
122
+ - `/fd-discuss` — explore before writing to understand what matters most
123
+ - `/fd-verify` — validate documentation accuracy after generation
@@ -0,0 +1,163 @@
1
+ # Architecture
2
+
3
+ FlowDeck is a plugin that runs inside OpenCode. It layers a structured multi-agent orchestration system on top of the base OpenCode runtime, contributing commands, specialist agents, runtime services, and event-driven hooks.
4
+
5
+ ## Layering
6
+
7
+ ```
8
+ OpenCode
9
+ └── FlowDeck Plugin
10
+ ├── Commands (CLI entry points)
11
+ ├── Agents (25 specialists, delegated by orchestrator)
12
+ ├── Services (governance, intelligence, council)
13
+ └── Hooks (session-start, compaction, shell-env, etc.)
14
+ ```
15
+
16
+ **OpenCode** provides the underlying runtime: tool execution, file I/O, shell access, MCP integrations, and the conversation UI.
17
+
18
+ **FlowDeck** adds the workflow layer on top. It does not replace OpenCode's core — it extends it with opinionated orchestration, persistent state, and AI safety services.
19
+
20
+ ## Four Subsystems
21
+
22
+ ### Commands
23
+
24
+ Commands are the user-facing entry points. They are registered as slash commands in the OpenCode CLI (e.g., `/fd-map-codebase`, `/fd-new-feature`, `/fd-plan`, `/fd-execute`). Each command:
25
+
26
+ 1. Reads current planning or codebase state
27
+ 2. Invokes the appropriate specialist agents via the `delegate` or `run-pipeline` tools
28
+ 3. Writes results back to `.planning/` state files
29
+ 4. Optionally triggers hooks to react to the state change
30
+
31
+ Commands are implemented as Markdown templates with frontmatter metadata in `src/commands/`. The plugin loader reads them and registers them at startup.
32
+
33
+ ### Agents
34
+
35
+ FlowDeck ships 25 specialist agents, each responsible for a narrow domain:
36
+
37
+ | Agent | Role |
38
+ |-------|------|
39
+ | `@orchestrator` | Coordinates the workflow; delegates to specialists |
40
+ | `@architect` | Designs system structure and component boundaries |
41
+ | `@planner` | Breaks features into wave-structured tasks |
42
+ | `@coder` | Implements features; follows TDD discipline |
43
+ | `@tester` | Writes and maintains tests |
44
+ | `@reviewer` | Reviews code quality and style |
45
+ | `@debugger` | Diagnoses and fixes failures |
46
+ | `@risk-analyst` | Identifies technical risk in plans |
47
+ | `@policy-enforcer` | Validates compliance with project rules |
48
+ | `@discusser` | Runs structured pre-planning Q&A |
49
+ | `@designer` | UI/UX design decisions |
50
+ | ... and 15 more | |
51
+
52
+ The orchestrator is the default agent. All other agents are invoked via the `delegate` tool or `run-pipeline` tool. Every agent inherits the currently active OpenCode model by default; individual agents can be overridden in `flowdeck.json`.
53
+
54
+ ### Services
55
+
56
+ Services are runtime components that run continuously, not as part of a linear workflow:
57
+
58
+ - **Governance services** — validate agent contracts, enforce delegation budgets, detect loops, and score workflow quality
59
+ - **Intelligence services** — compute patch trust scores, volatility maps, failure replays, and regression predictions
60
+ - **Council service** — synthesizes consensus from multiple specialized agents via the `council` tool
61
+
62
+ Services are invoked by hooks (before/after tool execution) or by commands that need on-demand analysis.
63
+
64
+ ### Hooks
65
+
66
+ Hooks are event handlers registered with OpenCode's plugin API. FlowDeck registers the following hooks:
67
+
68
+ | Hook | Trigger | Purpose |
69
+ |------|---------|---------|
70
+ | `session.started` | New session begins | Initialize planning state, load config |
71
+ | `session.idle` | Session idle detected | Generate idle summary, auto-learn |
72
+ | `experimental.session.compacting` | Context window near full | Compact session state |
73
+ | `tool.execute.before` | Before any tool runs | Patch trust, guard rails, telemetry, supervisor preflight |
74
+ | `tool.execute.after` | After any tool completes | Telemetry, supervisor post-execution review |
75
+ | `file.edited` | File changed on disk | Track file modifications |
76
+ | `shell.env` | Shell command runs | Inject FlowDeck state into shell |
77
+ | `todo.updated` | Todo list changes | Sync todo state |
78
+
79
+ ## State Flow
80
+
81
+ State flows through the system in a one-way pipeline:
82
+
83
+ ```
84
+ Commands
85
+ │ (invoke agents via delegate / run-pipeline)
86
+
87
+ Agents
88
+ │ (produce artifacts, write state)
89
+
90
+ Services (governance + intelligence)
91
+ │ (validate, score, predict — write to .codebase/)
92
+
93
+ Hooks
94
+ │ (react to tool events, trigger re-entry)
95
+
96
+ State files
97
+ ├── .planning/
98
+ │ STATE.md — current workflow phase, active feature, checkpoint
99
+ │ PLAN.md — wave-structured execution plan
100
+ │ PROJECT.md — project overview and constraints
101
+ │ ROADMAP.md — feature roadmap
102
+ │ FEATURE.md — current feature context
103
+ │ DISCUSS.md — pre-planning decisions
104
+ │ multi-repo/ — multi-repo coordination state
105
+ └── .codebase/
106
+ AGENT_SPANS.jsonl — causal delegation spans
107
+ BUDGETS.json — delegation budget consumption
108
+ DEADLOCK_SIGNALS.jsonl — loop/bounce detections
109
+ SCORECARDS.jsonl — per-run quality scores
110
+ CODEGRAPH.json — codebase structure index
111
+ VOLATILITY.json — change-frequency map
112
+ ```
113
+
114
+ Commands read from and write to `.planning/`. Services write to `.codebase/`. Hooks read both directories and may trigger re-entry into the command pipeline.
115
+
116
+ ## Model-Agnostic Design
117
+
118
+ FlowDeck makes no model assumptions. Every agent call passes through the active OpenCode model unless overridden per-agent in `flowdeck.json`:
119
+
120
+ ```json
121
+ {
122
+ "agents": {
123
+ "planner": { "model": "anthropic/claude-opus-4" },
124
+ "tester": { "model": "openai/gpt-4o-mini" }
125
+ }
126
+ }
127
+ ```
128
+
129
+ Agents not listed inherit the global model. Override at the agent level, not the system level.
130
+
131
+ ## Tool Map
132
+
133
+ FlowDeck registers these tools for use by agents and commands:
134
+
135
+ | Tool | Purpose |
136
+ |------|---------|
137
+ | `planning-state` | Read/write `.planning/STATE.md` |
138
+ | `codebase-state` | Read/write `.codebase/` state files |
139
+ | `workspace-state` | Snapshot workspace files and git status |
140
+ | `run-pipeline` | Execute a defined pipeline of agent steps |
141
+ | `delegate` | Invoke a named specialist agent |
142
+ | `council` | Run multiple agents and synthesize consensus |
143
+ | `volatility-map` | Compute change frequency per file |
144
+ | `failure-replay` | Reproduce and trace a prior failure |
145
+ | `decision-trace` | Record and replay decision rationale |
146
+ | `hash-edit` | Compute a content hash for an edit |
147
+ | `policy-engine` | Evaluate agent actions against project rules |
148
+ | `repo-memory` | Persistent memory across sessions |
149
+ | `context-generator` | Generate focused context summaries |
150
+ | `codegraph` | Query codebase structure from indexed graph |
151
+
152
+ ## Plugin Initialization
153
+
154
+ On startup, the plugin:
155
+
156
+ 1. Reads `flowdeck.json` from the project directory
157
+ 2. Registers all slash commands from `src/commands/`
158
+ 3. Registers all agents from `src/agents/`
159
+ 4. Registers all hooks with the OpenCode plugin API
160
+ 5. Registers tools, MCP servers, and skills directories
161
+ 6. Sets `default_agent` to `orchestrator` if not already configured
162
+
163
+ The plugin is passive until a user invokes a FlowDeck command or an OpenCode event triggers a hook.
@@ -0,0 +1,242 @@
1
+ # Governance
2
+
3
+ FlowDeck's governance layer makes multi-agent execution trustworthy and auditable. It consists of six runtime services that run continuously, intercepting agent tool calls, tracking delegation, enforcing budgets, and scoring workflow quality.
4
+
5
+ Governance is transparent — every service writes its output to a machine-readable file in `.codebase/` so runs can be audited after the fact.
6
+
7
+ ---
8
+
9
+ ## 1. Agent Contract Registry
10
+
11
+ Every agent type has a **contract**: a declarative specification of what it is allowed to do and what it must not do.
12
+
13
+ A contract defines:
14
+
15
+ - **allowed-tools** — the list of tools the agent may call
16
+ - **forbidden-tools** — tools the agent may never call
17
+ - **required-inputs** — fields that must be present in the delegation call
18
+ - **success-criteria** — conditions that must be true after execution
19
+
20
+ Example contract for `@coder`:
21
+
22
+ ```json
23
+ {
24
+ "agent": "coder",
25
+ "allowed-tools": ["read", "edit", "write", "bash", "run-pipeline"],
26
+ "forbidden-tools": ["delete", "remove", "drop"],
27
+ "required-inputs": ["prompt", "files"],
28
+ "success-criteria": [
29
+ "all edited files pass linter",
30
+ "no test coverage decrease"
31
+ ]
32
+ }
33
+ ```
34
+
35
+ Contracts are defined in `src/agents/` as part of each agent's configuration. The registry is consulted by the Agent Validator before and after every agent invocation.
36
+
37
+ ---
38
+
39
+ ## 2. Agent Validator
40
+
41
+ The Agent Validator checks every agent call against the agent's contract. It operates in three modes:
42
+
43
+ | Mode | Behavior |
44
+ |------|----------|
45
+ | `off` | No checking — governance overhead is zero |
46
+ | `advisory` | Logs violations; execution continues |
47
+ | `strict` | Throws an error and halts execution on violation |
48
+
49
+ **Before invocation checks:**
50
+
51
+ - The agent name resolves to a known contract
52
+ - All `required-inputs` are present in the delegation call
53
+ - No forbidden tools are in the call
54
+
55
+ **After invocation checks:**
56
+
57
+ - `success-criteria` conditions are evaluated against the execution result
58
+ - Violations are logged to `.codebase/AGENT_SPANS.jsonl` under the span's metadata
59
+
60
+ Configuration in `flowdeck.json`:
61
+
62
+ ```json
63
+ {
64
+ "governance": {
65
+ "validator": { "mode": "advisory" }
66
+ }
67
+ }
68
+ ```
69
+
70
+ ---
71
+
72
+ ## 3. Inter-Agent Trace Graph
73
+
74
+ Every delegation — the orchestrator invoking a specialist, or a specialist invoking a sub-agent — is recorded as a **causal span** in `.codebase/AGENT_SPANS.jsonl`.
75
+
76
+ Each span records:
77
+
78
+ ```json
79
+ {
80
+ "span_id": "s1a2b3c",
81
+ "parent_id": "s0a1b2c",
82
+ "agent": "coder",
83
+ "tool": "delegate",
84
+ "prompt": "Implement user authentication",
85
+ "files": ["src/auth/login.ts"],
86
+ "started_at": "2026-05-26T10:00:00Z",
87
+ "finished_at": "2026-05-26T10:05:00Z",
88
+ "violations": [],
89
+ "result": "success"
90
+ }
91
+ ```
92
+
93
+ Spans form a tree rooted at the orchestrator. This trace is used by:
94
+
95
+ - The Deadlock Detector to identify circular delegation
96
+ - The Workflow Scorecard to measure delegation depth
97
+ - Post-session audits to reconstruct exactly what ran
98
+
99
+ ---
100
+
101
+ ## 4. Delegation Budget
102
+
103
+ Every run has a **delegation budget** — per-run limits that prevent runaway agent chains. Budgets are tracked in `.codebase/BUDGETS.json`.
104
+
105
+ ```json
106
+ {
107
+ "run_id": "run-2026-05-26-001",
108
+ "limits": {
109
+ "maxToolCalls": 200,
110
+ "maxDepth": 8,
111
+ "maxSameStepRetries": 3,
112
+ "maxSubAgentDelegations": 40
113
+ },
114
+ "consumed": {
115
+ "toolCalls": 47,
116
+ "depth": 3,
117
+ "sameStepRetries": 1,
118
+ "subAgentDelegations": 12
119
+ }
120
+ }
121
+ ```
122
+
123
+ When a budget limit is reached, the agent receives an error and must stop or request user approval to continue.
124
+
125
+ Configuration:
126
+
127
+ ```json
128
+ {
129
+ "governance": {
130
+ "delegationBudget": {
131
+ "maxToolCalls": 200,
132
+ "maxDepth": 8,
133
+ "maxSameStepRetries": 3
134
+ }
135
+ }
136
+ }
137
+ ```
138
+
139
+ ---
140
+
141
+ ## 5. Deadlock / Loop Detector
142
+
143
+ The Deadlock Detector monitors spans and budget consumption for patterns that indicate an agent chain is stuck:
144
+
145
+ | Pattern | Detection |
146
+ |---------|-----------|
147
+ | **Bounce loop** | Same task delegated back to the same agent 3+ times |
148
+ | **Circular delegation** | Span tree contains a cycle (A → B → A) |
149
+ | **Step retry loop** | Same plan step attempted 3+ times without progress |
150
+ | **Stage stall** | No span completion for a configured time threshold |
151
+
152
+ When a pattern is detected, a signal is written to `.codebase/DEADLOCK_SIGNALS.jsonl`:
153
+
154
+ ```json
155
+ {
156
+ "signal_id": "dl-001",
157
+ "type": "bounce_loop",
158
+ "agent": "coder",
159
+ "task": "Implement user authentication",
160
+ "bounce_count": 3,
161
+ "last_span": "s1a2b3c",
162
+ "detected_at": "2026-05-26T10:15:00Z",
163
+ "auto_stop": false
164
+ }
165
+ ```
166
+
167
+ If `auto_stop` is `true` in the config, the orchestrator halts execution. Otherwise, it logs the signal and continues, notifying the user.
168
+
169
+ Configuration:
170
+
171
+ ```json
172
+ {
173
+ "governance": {
174
+ "deadlockDetection": {
175
+ "enabled": true,
176
+ "bounceThreshold": 3,
177
+ "autoStop": false
178
+ }
179
+ }
180
+ }
181
+ ```
182
+
183
+ ---
184
+
185
+ ## 6. Workflow Scorecard
186
+
187
+ After each `/fd-verify` run, a 10-dimension quality scorecard is written to `.codebase/SCORECARDS.jsonl`.
188
+
189
+ | Dimension | Description |
190
+ |-----------|-------------|
191
+ | `tdd_discipline` | Tests written before implementation |
192
+ | `design_first` | Discuss and plan completed before execute |
193
+ | `approval_gated` | Critical steps required explicit CONFIRM |
194
+ | `budget_efficiency` | Tool calls and depth used vs. limits |
195
+ | `conflict_resolved` | Merge conflicts resolved without force |
196
+ | `rule_compliance` | Project rules and contracts respected |
197
+ | `rollback_ready` | Every task had a rollback plan |
198
+ | `context_preserved` | No context loss between phases |
199
+ | `safety_gated` | Phase gating enforced throughout |
200
+ | `governance_traced` | All agent calls have spans |
201
+
202
+ Each dimension scores 0.0–1.0. The overall score is the weighted average. Scorecards enable post-hoc comparison of runs and identification of process regressions.
203
+
204
+ ---
205
+
206
+ ## Complete Configuration Example
207
+
208
+ Here is a fully annotated `flowdeck.json` section covering all governance options:
209
+
210
+ ```json
211
+ {
212
+ "governance": {
213
+ // Agent Validator — checks agent calls against contracts
214
+ "validator": {
215
+ "mode": "advisory" // "off" | "advisory" | "strict"
216
+ },
217
+
218
+ // Delegation Budget — per-run limits
219
+ "delegationBudget": {
220
+ "maxToolCalls": 200, // total tool calls allowed
221
+ "maxDepth": 8, // max delegation chain depth
222
+ "maxSameStepRetries": 3, // retries of the same plan step
223
+ "maxSubAgentDelegations": 40 // sub-agent calls per orchestrator call
224
+ },
225
+
226
+ // Deadlock / Loop Detector
227
+ "deadlockDetection": {
228
+ "enabled": true,
229
+ "bounceThreshold": 3, // bounces before signal fires
230
+ "circularThreshold": 2, // circular spans before signal fires
231
+ "autoStop": false // halt execution on first signal
232
+ },
233
+
234
+ // Workflow Scorecard
235
+ "scorecard": {
236
+ "enabled": true
237
+ }
238
+ }
239
+ }
240
+ ```
241
+
242
+ The governance layer adds measurable overhead only when set to `advisory` or `strict` mode. In `off` mode, no contract checks are performed and no spans are written (though deadlock detection still runs if enabled).