/greenfield:behavioral-spec-writingfrom greenfield
Generates per-module behavioral specifications, integration contracts, and end-to-end user journeys from architectural synthesis. Part of a layered documentation methodology.
Ships in greenfield. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Layer 3 transforms Layer 2 synthesis (module map, feature inventory, architecture doc, API surface, behavioral summaries) into specifications detailed enough that a developer can reimplement the target WITHOUT seeing the original code. This skill carries all methodology for deep-dive-analyzer, contract-extractor, behavior-documenter, and user-journey-analyzer.
digraph layer3_pipeline {
rankdir=TB;
compound=true;
"Layer 2 synthesis complete" [shape=doublecircle];
"Layer 3 complete — proceed to Gate 1" [shape=doublecircle];
subgraph cluster_phase1 {
label="Phase 1: Per-Module Deep Dives (parallel across modules)";
style=dashed;
"deep-dive-analyzer: Module A" [shape=box];
"deep-dive-analyzer: Module B" [shape=box];
"deep-dive-analyzer: Module N" [shape=box];
}
subgraph cluster_phase2 {
label="Phase 2: Cross-Cutting Documentation (parallel)";
style=dashed;
"contract-extractor: external + integration contracts" [shape=box];
"behavior-documenter: behavioral domain synthesis" [shape=box];
"user-journey-analyzer: end-to-end journeys" [shape=box];
}
"Layer 2 synthesis complete" -> "deep-dive-analyzer: Module A";
"Layer 2 synthesis complete" -> "deep-dive-analyzer: Module B";
"Layer 2 synthesis complete" -> "deep-dive-analyzer: Module N";
"deep-dive-analyzer: Module A" -> "contract-extractor: external + integration contracts" [lhead=cluster_phase2];
"deep-dive-analyzer: Module B" -> "behavior-documenter: behavioral domain synthesis" [lhead=cluster_phase2];
"deep-dive-analyzer: Module N" -> "user-journey-analyzer: end-to-end journeys" [lhead=cluster_phase2];
"contract-extractor: external + integration contracts" -> "Layer 3 complete — proceed to Gate 1";
"behavior-documenter: behavioral domain synthesis" -> "Layer 3 complete — proceed to Gate 1";
"user-journey-analyzer: end-to-end journeys" -> "Layer 3 complete — proceed to Gate 1";
}
Phase 1 runs deep-dive-analyzer in parallel across every module from the module map. Each instance produces a per-module behavioral specification.
Phase 2 runs three agents in parallel. They consume Phase 1 output plus Layer 2 synthesis to produce contracts, behavioral documentation, and user journeys.
| Path | What It Contains |
|---|---|
workspace/raw/synthesis/module-map.md | Module inventory: name, description, priority, dependencies |
workspace/raw/synthesis/features/ | Feature inventory across all sources |
workspace/raw/synthesis/architecture/ | Architecture document: component relationships |
workspace/raw/synthesis/api/ | API surface: all discovered interfaces |
workspace/raw/synthesis/behavioral-summaries/ | Merged intelligence from all Layer 1 modes |
workspace/raw/synthesis/reimplementation-essentials.md | Compact summary for the implementer: happy path, edge cases, dependency contracts |
| Path | What It Contains | Origin |
|---|---|---|
workspace/raw/source/analysis/ | Source code analysis (chunk analysis, function analysis) | RAW |
workspace/public/docs/ | Official documentation findings | PUBLIC |
workspace/public/ecosystem/ | SDK and ecosystem analysis | PUBLIC |
workspace/public/community/ | Community intelligence (forums, tutorials, issues) | PUBLIC |
workspace/raw/runtime/ | Runtime observations (CLI, web UI, behavior) | RAW |
workspace/raw/binary/ | Binary analysis findings | RAW |
Claims supported by multiple independent intelligence sources earn confirmed confidence.
This is the primary Layer 3 deliverable. Each module in the module map gets a complete behavioral specification written to workspace/raw/specs/modules/{module-name}.md.
You read source code to understand behavior. You NEVER reference source code in specs.
Even though you analyze code, your output must read as if you only observed the system externally. The test: "Can someone implement this from my spec alone, never having seen the source?"
| Contamination | Example | Why Forbidden |
|---|---|---|
| Internal function names | parseArgs(), loadConfig() | Implementation detail |
| Internal variable names | _configKey, configMap | Implementation detail |
| Internal class names | ConfigLoader, SettingsReader | Implementation detail |
| Minified identifiers | a(), x1, Qz, sp, r0 | Implementation detail |
| Line numbers | "at line 234" | Implementation detail |
| Source file paths | "in src/cli.ts" | Implementation detail |
| Code structure | "calls X then Y" | Implementation detail |
| Module counts | "52 modules", "8 components" | Structural leak |
| IPC channel names | task-completed, sync-channel | Internal messaging |
| Store property names | store.documentBody, useActiveDocument | State management internals |
| Feature flag names | FF_NEW_INDEX_FORMAT, ff_batch_commit_v2, isEnabled('feature') | Internal gating — describe what the gate controls, not its name |
| Telemetry event names | request_rate_limited, job_timeout_warning | Internal analytics — describe what is measured, not the event name |
| CSS class names | .toolbar__button, styled.Button | Styling implementation |
| Database schema details (app-owned) | CREATE TABLE sessions, column names | Storage implementation — but see External System Exception below |
| Internal filenames | auth-handler.ts, session.js | Source organization |
When the target application depends on external systems it does not own — shared databases, third-party APIs, CLI tools it shells out to, file formats imposed by other systems, hardware interfaces — the details of those systems are behavioral constraints, not implementation details.
The test: Can the reimplementor redesign this interface? If NO (it's external/shared/imposed), treat its details as external contracts and INCLUDE them. If YES (the app owns it), treat them as implementation details and EXCLUDE them.
Examples of external constraints that MUST be preserved:
Document external system contracts in dedicated files under workspace/raw/specs/contracts/ (see Contract Extraction section). These contracts flow through to the implementer unchanged.
| Behavioral Element | Example | Why Included |
|---|---|---|
| Environment variables | DATABASE_URL, DEBUG | External API |
| CLI flags | --format, --workers | External API |
| Config file keys | upstreams, log_level | External API |
| API field names | request_id, batch_size | Protocol spec |
| File paths (user-facing) | ~/.app/config.toml | Behavioral contract |
| Protocol names | SSE, gRPC, OAuth | Behavioral contract |
| Error messages | "Error: Invalid API key" | UX contract |
| HTTP headers/codes | Authorization, 200, 401 | Protocol spec |
| Dependency API contracts | esbuild.transform(code, {loader: 'ts'}) | How target talks to its dependencies |
The rule: If a user or external system needs to know it, INCLUDE it. If only the code needs to know it, EXCLUDE it.
WRONG:
Entry point: main() at src/cli.ts:45
Calls parseArgs() which returns Config object
Variable requestId = generateUUID()
RIGHT:
Entry point: Command-line invocation
Behavior:
1. Parse arguments into configuration
2. Generate session identifier (UUID v4 format)
3. Initialize modules based on config
Session ID: UUID v4, generated once at startup, immutable
Every behavioral claim gets a unique ID: SPEC-{DOMAIN}-{NNN}
Where {DOMAIN} is a short uppercase token for the behavioral domain (use tokens that describe exposed behavior, NOT internal module names) and {NNN} is a zero-padded sequential number starting at 001.
Pick tokens that describe the target's exposed behavior. The set below is a starting vocabulary; delete what doesn't apply and add tokens that do.
| Domain Token | Covers |
|---|---|
CLI | Command-line parsing, flags, subcommands, exit codes |
CONFIG | Configuration loading, merging, defaults, validation |
AUTH | API keys, OAuth, tokens, credentials |
API | Wire protocol, streaming, retries, headers, request/response handling |
OUTPUT | Terminal rendering, formatting, progress indicators, themes |
DATA | Data models, storage, serialization |
NET | Network, HTTP, WebSocket, protocols |
UI | User interface elements, layouts, interaction flows |
For any behavior the starting set doesn't cover, create a descriptive token — for example: CACHE, MIGRATE, HEALTH, LOADER, WATCH, AUDIO, PARSER, SYNC, PLUGIN, SESSION, TOOL. Tokens describe the target's actual surface; a speech-to-text app probably needs AUDIO and UI; a web service probably needs NET and DATA; a code-loading tool probably needs PARSER and CONFIG. Don't carry tokens you don't need.
If a module's behavior spans multiple domains, use multiple tokens (one per behavioral block). IDs MUST be unique across the entire spec file. Examples: SPEC-CLI-001, SPEC-CONFIG-042, SPEC-API-003, SPEC-AUDIO-007.
Every behavioral claim in the spec MUST be annotated with a requirement level:
Apply requirement levels to every entry point behavior, every decision tree outcome, every error condition, and every state transition. If a claim lacks a requirement level, it is ambiguous and must be clarified.
Each per-module spec covers the following sections. All sections are required; write "Not applicable" or "Stateless" where a section genuinely does not apply, but never omit sections.
2-3 paragraphs: what the module does from a user/system perspective, why it exists, key responsibilities.
For each capability this module makes available:
- **Capability:** [behavioral name -- what it does, not what it's called internally]
- **Trigger:** [what causes this capability to activate]
- **Preconditions:** [what MUST be true before invocation]
- **Postconditions:** [what is guaranteed after completion]
- **Error conditions:** [what errors can occur and when]
- **Requirement Level:** MUST | SHOULD | MAY
For each capability or data this module needs to function:
- **What is needed:** [capability or data description]
- **When:** [at what point this prerequisite is consumed]
- **Failure behavior:** [what happens if the prerequisite is unavailable]
CRITICAL: Do NOT name which module provides the prerequisite. Describe WHAT is needed, not WHERE it comes from. A "From module" field would be structural contamination. The implementer decides its own module boundaries.
For each way to invoke this module:
#### SPEC-{DOMAIN}-{NNN}: [Descriptive Name]
**Requirement Level:** MUST | SHOULD | MAY
### Trigger
[What causes this to be invoked -- user action, event, timer, etc.]
### Input
- Parameter 1: [type] - [what it represents]
- Parameter 2: [type] - [what it represents]
- Required state: [what must be true before invocation]
### Behavior
1. **Validation**
- Check: [what condition] -> if invalid: [error message]
- Check: [what condition] -> if invalid: [error message]
2. **Processing**
- [Step-by-step behavioral description]
- Decision: if [condition in behavioral terms]
- Then: [behavior]
- Else: [behavior]
3. **Completion**
- Output: [what is returned/emitted]
- State change: [what persists]
- Side effects: [files written, network calls, etc.]
For every significant decision, document in behavioral terms:
#### SPEC-{DOMAIN}-{NNN}: [What is being decided]
**Requirement Level:** MUST | SHOULD | MAY
### Conditions (evaluated in order)
1. If [behavioral condition]: -> [behavioral outcome]
2. Else if [behavioral condition]: -> [behavioral outcome]
3. Default: -> [behavioral outcome]
### Outcomes
- **Outcome 1**: [detailed behavioral description]
- **Outcome 2**: [detailed behavioral description]
Describe conditions by what they MEAN, not how they are coded:
if (x.length > 0 && x[0] === '-')Pay special attention to behaviors that differ based on HOW a feature was triggered. A common pattern:
When the same feature has different error handling based on whether it was explicitly requested vs. automatically discovered, document BOTH paths explicitly:
#### SPEC-{DOMAIN}-{NNN}: Configuration Error Handling
**Requirement Level:** MUST
### Conditions
1. If configuration was auto-detected AND loading fails: -> Log warning, continue without it
2. If configuration was user-specified (via flag/option) AND loading fails: -> Report error, abort
3. If configuration loads but is invalid: -> [behavior depends on which fields are invalid]
This pattern appears frequently in config file loading, plugin/extension discovery, and feature detection with fallback.
If the module maintains state, this section is MANDATORY. Every stateful module must document its states, transitions, and invariants explicitly — implementers need the state model to preserve behavior across a rewrite.
## State Model (State Box)
### State Variables
| Variable | Type | Initial Value | Description |
|----------|------|---------------|-------------|
| [name] | [type] | [initial] | [what it represents] |
### State Invariants
[What MUST always be true about the state, regardless of transitions]
### States
- **Idle**: [what this state means, invariants]
- **Processing**: [what this state means, invariants]
- **Complete**: [what this state means, invariants]
### Transitions
| From | Event | Condition | Action | To |
|------|-------|-----------|--------|-----|
| Idle | request received | valid input | begin processing | Processing |
| Processing | work complete | success | emit result | Complete |
| Processing | error occurs | - | emit error | Idle |
### State Persistence
[Where state lives (memory, disk, database), lifetime, serialization format]
### Initialization
[How the state machine starts]
### Termination
[How/when the state machine ends]
If the module is stateless, write: "Stateless -- This module maintains no state between invocations."
Error specification MUST be as detailed as normal operation. For every entry point, the error paths must have the same depth as the happy path. Incomplete error documentation is a spec gap.
For EVERY error condition:
#### SPEC-{DOMAIN}-{NNN}: [Descriptive Error Name]
**Requirement Level:** MUST | SHOULD | MAY
### Trigger
[What situation causes this error]
### Detection
[How the system knows this error occurred]
### Response
1. [First action -- e.g., "Log error details"]
2. [Second action -- e.g., "Clean up partial state"]
3. [Final action -- e.g., "Return error to caller"]
### User-Visible Message
"[Exact error text the user sees]"
### Recovery
[Can the operation be retried? Under what conditions?]
## Edge Cases
### Empty Input
- Behavior: [what happens]
- Output: [what is returned]
### Maximum Size
- Limit: [what the limit is]
- Exceeded behavior: [what happens]
### Concurrent Access
- Behavior: [how handled]
- Guarantees: [what is guaranteed]
### Interruption
- Cleanup: [what cleanup occurs]
- Resumability: [can it resume?]
How configuration values alter this module's behavior. For each relevant config key:
| Config Key / Env Var | Effect on This Module | Default | Requirement Level |
|---------------------|----------------------|---------|-------------------|
| `SOME_ENV_VAR` | Enables debug output for this module | unset (disabled) | MAY |
| `configKey` | Controls retry count | 3 | SHOULD |
## Data Format: [Name]
### Input
{
field1: string (required, 1-100 chars),
field2: number (optional, default: 0),
field3: array of strings (required, non-empty)
}
### Transformations
1. Validate all required fields present
2. Apply defaults to optional fields
3. Normalize field1 to lowercase
### Output
{
field1: string (normalized),
field2: number,
field3: array of strings,
computed: boolean (true if field2 > 0)
}
When the target delegates critical behavior to a third-party library, document the exact API contract used. These are behavioral contracts between the target and external systems -- equivalent to wire protocols -- NOT implementation details.
digraph dependency_contract_decision {
rankdir=TB;
"Target calls dependency?" [shape=diamond];
"Is behavior delegated?" [shape=diamond];
"Document API contract" [shape=box];
"Skip -- internal detail" [shape=box];
"Target calls dependency?" -> "Is behavior delegated?" [label="yes"];
"Target calls dependency?" -> "Skip -- internal detail" [label="no"];
"Is behavior delegated?" -> "Document API contract" [label="yes: critical behavior\ndepends on correct API usage"];
"Is behavior delegated?" -> "Skip -- internal detail" [label="no: wrapper only"];
}
For each critical dependency contract, document:
API Surface Used:
Failure Modes:
Version Constraints:
Example:
## Dependency Contract: esbuild Transform API
### API Surface Used
- `esbuild.transform(code, options)` -- transforms TypeScript/JSX to JavaScript
- Required option: `loader` must be set explicitly ('ts', 'tsx', 'jsx') based on source file extension
- Required option: `sourcefile` OR explicit `loader` -- without either, esbuild defaults to JavaScript parsing
- The `transform()` API receives code as a string (no filename), so it cannot infer the loader automatically
### Failure Mode
- If `loader` is 'default' and no `sourcefile` is provided: TypeScript syntax (`interface`, `enum`, type annotations) causes parse errors
- Error: "Expected ';' but found 'Identifier'"
### Version Constraint
- Requires esbuild >= 0.14.0 for stable transform API
The rule: If the target's correctness depends on calling a dependency's API with specific parameters, that is a behavioral contract. Document it.
Explicitly categorize gaps using the POSIX three-category model:
## Implementation-Defined Behavior
[Areas where the implementor has freedom to choose, with any constraints.
The implementor MUST document their choice.]
## Unspecified Behavior
[Valid behaviors the spec does not prescribe -- any correct approach is acceptable.
The implementor need not document their choice.]
## Undefined Behavior
[Inputs or states the spec does not cover -- implementation may do anything.
No guarantees are made about these scenarios.]
You MUST read every single line of code in the module. No exceptions.
Checklist before proceeding:
If you cannot check these boxes, GO BACK and read more.
Do not pursue exhaustive analysis past the point of diminishing returns. When successive analysis passes stop revealing new behavioral observations for a module, document current understanding and move on. P0 modules warrant more thoroughness than P2/P3 modules, but even P0 analysis should stop when saturated. The goal is "sufficient to reimplement," not "every conceivable edge case."
For each behavior, you must answer:
WRONG: "It validates the input" -- TOO VAGUE
RIGHT: "It checks: field X is non-empty string (error: 'X required'), field Y is positive integer (error: 'Y must be positive'), field Z matches pattern /^[a-z]+$/ (error: 'Z must be lowercase letters')" -- COMPLETE
When extraction analysis files from multiple agents exist for overlapping topics:
If you find a contradiction you cannot resolve from the source, record it with a disputed citation:
<!-- cite: source=source-code, ref=workspace/raw/source/analysis/chunk-0024.md:105, confidence=disputed, agent=deep-dive-analyzer, contradiction=workspace/raw/source/exploration/auth-layer/findings.md:23 -->
When other intelligence sources have run, consult their findings:
workspace/public/docs/ -- official documentation claimsworkspace/public/ecosystem/ -- SDK analysis findingsworkspace/public/community/ -- tutorials, reviews, forums, issue tracker observationsworkspace/raw/runtime/ -- runtime observation dataworkspace/raw/binary/ -- binary analysis findingsClaims supported by multiple independent sources earn confirmed confidence.
Every per-module spec file MUST end with this checklist:
## Verification Checklist
- [ ] All entry points documented
- [ ] All decision trees traced (every branch, including error paths)
- [ ] All state machines documented (states, transitions, triggers)
- [ ] All error conditions listed with observable symptoms
- [ ] All edge cases identified and documented
- [ ] Auto-detected vs user-specified behavior differences documented
- [ ] Zero source code identifiers in this document
- [ ] All behavioral claims have provenance citations
- [ ] Assumed claims are a small minority; most claims have direct evidence
- [ ] No sections are empty or placeholder-only
- [ ] Cross-references to other specs are valid
- [ ] Every behavioral claim has a SPEC-{DOMAIN}-{NNN} ID
- [ ] Every behavioral claim has a requirement level (MUST/SHOULD/MAY)
- [ ] Error conditions have equal depth to normal operations
- [ ] All stateful modules have State Box documentation
- [ ] Uncertainty sections (implementation-defined/unspecified/undefined) present
- [ ] Behavioral Interfaces section (Exposed Capabilities/Prerequisites) present
- [ ] Dependency API contracts documented for all critical third-party calls
- [ ] Contamination Self-Check completed (all checks pass)
HARD STOP: Review your output file BEFORE writing it. Read every line and apply the reimplementor test from the spec-sanitization skill. Do NOT write the file until all checks pass.
For every identifier, name, or reference in your spec, ask: "Could the reimplementor reasonably redesign this?"
Check each paragraph for:
External contracts to PRESERVE (not contamination):
If any implementation detail is found: rewrite the line using behavioral language, then re-check. Only write the file when the spec reads cleanly to someone who has never seen the source.
# Module: [Descriptive Name]
## Overview
[2-3 paragraphs: what it does, why it exists, key responsibilities]
## Behavioral Interfaces
### Exposed Capabilities
[For each capability: name, trigger, preconditions, postconditions, errors, req level]
### Prerequisites
[For each need: what is needed, when, failure behavior -- NO "From module" field]
## Entry Points
[Each entry point with full behavioral spec, including SPEC-{DOMAIN}-{NNN} IDs]
## Decision Logic
[All significant decision trees with SPEC IDs]
## State Model (State Box)
[State variables, invariants, transitions if stateful, or "Stateless" if not]
## Error Handling
[All error conditions with equal depth to normal operations]
## Edge Cases
[Boundary conditions]
## Configuration Effects
[How config values alter behavior]
## Data Formats
[Input/output schemas]
## Dependency API Contracts
[Third-party library contracts]
## Implementation-Defined Behavior
[Areas where the implementor has freedom to choose]
## Unspecified Behavior
[Valid behaviors the spec does not prescribe]
## Undefined Behavior
[Inputs or states the spec does not cover]
## Verification Checklist
[Self-assessment checklist -- see above]
The contract-extractor produces two categories of output: contracts that cross the analysis/implementation boundary to the implementer, and inter-module contracts that stay in analysis for verification purposes only.
Observable interfaces between the target and the outside world. These are things a user or external system can observe without seeing source code.
Document every command and subcommand, every flag, required vs optional arguments, default values, and exit codes.
## Main Command
Usage: `target [options] [command]`
### Global Flags
| Flag | Short | Type | Default | Description |
|------|-------|------|---------|-------------|
| `--help` | `-h` | boolean | false | Show help |
| `--version` | `-v` | boolean | false | Show version |
### Subcommands
#### `target init`
[Arguments, flags, exit codes]
### Exit Codes
| Code | Meaning |
|------|---------|
| 0 | Success |
| 1 | General error |
| 2 | Usage error |
Output: workspace/raw/specs/contracts/cli.md
| Variable | Purpose | Expected Values | Default |
|---|---|---|---|
API_KEY | Authentication | string | (required) |
DEBUG | Enable debug logging | true/false | false |
Output: workspace/raw/specs/contracts/environment.md
Document file paths, file formats, all keys with types and descriptions, default values, and validation rules.
Output: workspace/raw/specs/contracts/configuration.md
For HTTP APIs, WebSocket connections, gRPC protocol, or any wire protocol the target uses: document request/response formats, headers, status codes, error responses.
Output: workspace/raw/specs/contracts/{protocol}.md
When the target application depends on external systems it does not own — shared databases, third-party APIs, CLI tools, imposed file formats — the details of those systems are behavioral constraints, not implementation choices. Document each as an external contract.
When to produce: If analysis reveals the target depends on a system whose interface is imposed externally (shared database, third-party API, external CLI tool, imposed file format), produce a contract for each.
For shared/external databases the application does not own:
# External Database Contract
## Ownership
This database is NOT owned by the application. The schema is an external constraint.
The reimplementation MUST conform to this schema exactly.
## Tables
### {TableName}
| Column | Type | Nullable | Purpose |
|--------|------|----------|---------|
| {col} | {type} | {yes/no} | {behavioral purpose} |
**Cardinality:** {e.g., "Multiple rows per product — one per pricing region"}
**Primary key:** {columns}
**Used by:** {which application behaviors query this table}
### Naming Collisions
| Name | Table 1 Purpose | Table 2 Purpose | Disambiguation |
|------|----------------|----------------|----------------|
| {name} | {purpose in context A} | {purpose in context B} | {how the app distinguishes them} |
## Query-Correctness Constraints
| Constraint | Affected Behavior | Why |
|-----------|-------------------|-----|
| {e.g., "One price per product in search results"} | {Product search} | {Pricing table has multiple rows per product (one per region); naive join produces duplicates} |
## Derived/Reference Data
| Target | Source | Derivation |
|--------|--------|-----------|
| {e.g., "Category dropdown values"} | {e.g., "SELECT DISTINCT Category FROM FinancialCategory"} | {How the data is derived} |
## Stored Procedures
| Procedure | Parameters | Returns | Purpose |
|-----------|-----------|---------|---------|
| {name} | {params} | {return type} | {behavioral purpose} |
Output: workspace/raw/specs/contracts/database.md
For third-party APIs the application calls but does not own:
# External API Contract: {Service Name}
## Ownership
This API is NOT owned by the application. The reimplementation MUST call the same endpoints
with the same field names.
## Endpoints
### {METHOD} {path}
**Request:**
| Field | Type | Required | Purpose |
|-------|------|----------|---------|
| {field} | {type} | {yes/no} | {purpose} |
**Response:**
| Field | Type | Purpose |
|-------|------|---------|
| {field} | {type} | {purpose} |
**Error Responses:**
| Status | Body | Meaning |
|--------|------|---------|
| {code} | {shape} | {when returned} |
## Authentication
{Auth scheme, token format, refresh flow}
## Pagination
{Pagination scheme: cursor-based, offset, etc.}
## Rate Limits
{Rate limit rules and retry behavior}
Output: workspace/raw/specs/contracts/api-{service}.md
For external CLI tools the application invokes:
# External CLI Contract: {Tool Name}
## Ownership
This tool is NOT owned by the application. The reimplementation MUST invoke the same commands.
## Commands
### {command} {subcommand}
| Flag | Type | Purpose |
|------|------|---------|
| {flag} | {type} | {purpose} |
**Output format:** {stdout format the app parses}
**Exit codes:** {codes the app checks}
Output: workspace/raw/specs/contracts/cli-{tool}.md
For file formats imposed by external systems:
# External File Format Contract: {Format Name}
## Ownership
This format is NOT owned by the application. The reimplementation MUST read/write the same structure.
## Structure
{Field names, encoding, version headers, layout}
Output: workspace/raw/specs/contracts/format-{name}.md
Ordering, sequencing, and failure relationships expressed WITHOUT naming internal modules. The implementer receives this to understand sequencing constraints while remaining free to choose its own architecture.
Output format:
# Behavioral Integration Requirements
These requirements define ordering and failure dependencies between behavioral capabilities.
They do NOT prescribe internal architecture -- the implementer is free to organize these capabilities
however it chooses.
## BIR Table
| BIR ID | Before (prerequisite) | After (dependent capability) | Failure if Violated | Req Level |
|--------|----------------------|------------------------------|---------------------|-----------|
| BIR-001 | Configuration loaded from all sources | Session created with valid context | Fatal: no config defaults available | MUST |
| BIR-002 | Arguments parsed into structured format | Execution mode determined | Fatal: cannot route to handler | MUST |
| BIR-003 | Active session established | API requests sent to backend | Fatal: no session context | MUST |
## BIR Details
### BIR-001: Configuration Before Session
- **Before:** Configuration loaded and merged from all sources (files, env vars, defaults)
- **After:** Session created with valid configuration context
- **Failure if violated:** Session cannot initialize without configuration; fatal error, abort
- **Requirement Level:** MUST
Output: workspace/raw/specs/contracts/behavioral-integration.md
Internal wiring between the original's modules. Stays in workspace/raw/. Used ONLY for Gate 1 verification to ensure complete analysis coverage. This is structural contamination -- it encodes the original's internal module boundaries.
Read the module specs in workspace/raw/specs/modules/ and the module map at workspace/raw/synthesis/module-map.md. For every cross-module dependency, document the integration contract.
Identify cross-module calls by looking for:
Output format:
# Inter-Module Contracts (Analysis Internal -- Does NOT Cross Into Implementation)
## Call Table
| Caller Module | Callee Module | Trigger | API Used | Failure Mode |
|--------------|--------------|---------|----------|-------------|
| CLI Parsing | Session Mgmt | startup | createSession() | fatal: abort |
| Session Mgmt | Config | session init | loadConfig() | warn: use defaults |
## Contract Details
### CLI Parsing -> Session Mgmt
- **Trigger:** Application startup, after argument parsing
- **API:** Create a new session or resume an existing one
- **Input:** Parsed CLI arguments, environment context
- **Output:** Active session handle
- **Failure behavior:** If session creation fails, application MUST abort with error message
- **Requirement Level:** MUST
Output: workspace/raw/specs/contracts/inter-module.md
The behavior-documenter is a pure synthesis agent. It does NOT read source code or run the target. It consumes the output of agents that did and synthesizes findings into unified behavioral documents.
digraph behavior_synthesis {
rankdir=TB;
"Gather all Layer 1 and Phase 1 evidence" [shape=box];
"Group claims by behavioral domain" [shape=box];
"Corroborate: multiple sources agree?" [shape=diamond];
"Assign confirmed confidence" [shape=box];
"Propagate original confidence" [shape=box];
"Sources disagree?" [shape=diamond];
"Apply resolution hierarchy" [shape=box];
"Flag as disputed" [shape=box];
"Write synthesized behavioral spec per domain" [shape=box];
"All domains documented" [shape=doublecircle];
"Gather all Layer 1 and Phase 1 evidence" -> "Group claims by behavioral domain";
"Group claims by behavioral domain" -> "Corroborate: multiple sources agree?";
"Corroborate: multiple sources agree?" -> "Assign confirmed confidence" [label="yes"];
"Corroborate: multiple sources agree?" -> "Propagate original confidence" [label="single source"];
"Corroborate: multiple sources agree?" -> "Sources disagree?" [label="conflict"];
"Sources disagree?" -> "Apply resolution hierarchy" [label="resolvable"];
"Sources disagree?" -> "Flag as disputed" [label="unresolvable"];
"Assign confirmed confidence" -> "Write synthesized behavioral spec per domain";
"Propagate original confidence" -> "Write synthesized behavioral spec per domain";
"Apply resolution hierarchy" -> "Write synthesized behavioral spec per domain";
"Flag as disputed" -> "Write synthesized behavioral spec per domain";
"Write synthesized behavioral spec per domain" -> "All domains documented";
}
Read all available input sources. For each behavioral domain (state management, error handling, networking, etc.), collect claims from all modes:
## Evidence Collection: [Domain]
| Claim | Source Mode | Source File | Confidence |
|-------|-----------|------------|------------|
| Session timeout is 30 min | source-code | chunk-0031.md:51 | inferred |
| Session timeout is 30 min | runtime-observation | cli/timeout-test.md:5 | confirmed |
| Session timeout is 30 min | official-docs | claims-by-topic.md:12 | inferred |
For each claim:
confirmeddisputed confidenceOrganize by behavioral domain, NOT by module. Group related behaviors. Remove all source code identifiers. Focus on observable behavior, not implementation.
For each behavioral domain, produce:
# [Domain] Behavior
## Overview
[2-3 paragraphs: what it does, why it exists, key responsibilities]
## Triggers
- [What causes this behavior to activate]
- [Events it responds to]
- [Inputs it accepts]
## Normal Behavior
1. When [trigger], the system [does X]
<!-- cite: source=source-code, ref=..., confidence=confirmed, agent=behavior-documenter, corroborated_by=runtime-observation -->
2. It then [does Y]
<!-- cite: source=source-code, ref=..., confidence=inferred, agent=behavior-documenter -->
## State
- Maintains: [what state it keeps]
- Initial state: [starting conditions]
- Terminal states: [end conditions]
## Error Behavior
- When [error condition]: [what happens]
- Error recovery: [how it recovers]
## Observable Outputs
- [What the user sees]
- [What gets written]
You MUST produce behavioral documentation.
Output: workspace/raw/specs/behavioral-docs/
End-to-end user workflows that exercise multiple modules. Component specs explain the pieces. User journeys explain how pieces connect.
| Journey Type | What It Covers | Examples |
|---|---|---|
| Happy path | Normal successful workflows | First run, normal startup, primary workflow completion |
| Error recovery | What happens when things go wrong | Auth failure, network timeout, invalid input |
| First-time setup | Initial configuration and onboarding | OAuth flow, config creation, first interaction |
| Power user workflows | Advanced multi-step operations | Resumable operations, piped input, scripted usage |
| Interruption handling | Mid-operation cancellation | Ctrl+C at various points, terminal close |
For each journey, write a complete trace:
## Journey: [Name]
### Trigger
[What initiates this journey -- user action, event, timer]
### Preconditions
- [What must be true before this journey can happen]
- [Required state, config, etc.]
### Step-by-Step Flow
**Step 1: [Name]**
- Action: [what the user does]
- Expected Response: [what the system does in response]
- What user sees: [exact UI/output text]
- State Changes: [what changes in system state]
- Errors Possible: [what can go wrong at this step]
**Step 2: [Name]**
- Action: [what the user does or what the system does next]
- Expected Response: [system response]
- What user sees: [exact UI/output text]
- State Changes: [state changes]
- Errors Possible: [error conditions]
[Continue for all steps...]
### Completion
- Final state: [what is different after this journey]
- User feedback: [what user sees at the end]
### Error Paths
- If [condition at step N]: [what happens, what user sees, recovery options]
- If [condition at step M]: [what happens, what user sees, recovery options]
### Alternative Paths
- With flag X: [how the journey differs]
- In state Y: [how the journey differs]
### Journey Provenance
| Step | Primary Source | Confidence |
|------|---------------|------------|
| Step 1 | source-code | inferred |
| Step 2 | runtime-observation + source-code | confirmed |
For each step, document:
For each journey, ask: "If I only had this document, could I build UI that looks and feels identical?"
If NO -- you are missing UX details. Go deeper.
Before documenting journeys, discover ALL entry points:
When runtime observation output exists at workspace/raw/runtime/, incorporate actual observed journeys rather than inferring them from code. Runtime-observed journeys have higher confidence because they represent actual behavior, not inferred behavior.
Output: workspace/raw/specs/journeys/{journey-name}.md
CRITICAL for all Layer 3 output. Every Layer 3 agent must enforce these rules.
Ask: Can a developer implement this spec without knowing ANYTHING about the original's code?
digraph implementation_boundary {
rankdir=LR;
subgraph cluster_crosses {
label="FLOWS to implementation";
style=filled;
fillcolor="#e8f5e9";
"Per-module behavioral specs" [shape=box];
"External contracts (CLI, env, config, protocol)" [shape=box];
"Behavioral Integration Requirements (BIR table)" [shape=box];
"Behavioral domain documentation" [shape=box];
"User journey specs" [shape=box];
}
subgraph cluster_stays {
label="STAYS in analysis (raw/)";
style=filled;
fillcolor="#ffebee";
"Inter-module integration contracts" [shape=box];
"Source code analysis artifacts" [shape=box];
"Raw runtime observation logs" [shape=box];
}
}
Every behavioral claim MUST have an inline provenance citation immediately after the claim:
- Sessions expire after 30 minutes of inactivity
<!-- cite: source=source-code, ref=workspace/raw/source/analysis/chunk-0007.md:88, confidence=confirmed, agent=deep-dive-analyzer, corroborated_by=runtime-observation -->
| Field | Type | Description |
|---|---|---|
source | enum | Source type: official-docs, public-api, sdk-analysis, community-knowledge, runtime-observation, source-code, binary-analysis, inferred |
ref | string | Specific location: URL, workspace/ file path with optional :line, or session timestamp |
confidence | enum | confirmed, inferred, or assumed |
agent | string | Your agent name |
| Field | Type | Description |
|---|---|---|
corroborated_by | comma-separated list | Other source types that independently confirm this claim |
contradiction | string | Path to contradicting evidence (for disputed confidence) |
| Situation | Confidence |
|---|---|
| Claim supported by source code analysis only | inferred |
| Claim supported by source + one other mode (docs, runtime, SDK) | confirmed |
| Claim is agent's reasoned interpretation of ambiguous code | assumed |
| Claim involves exact algorithm, constant, or field name verified in source | inferred (upgrade to confirmed if corroborated) |
| Multiple Layer 1 sources independently agree | confirmed |
| Agent reasoning with no direct evidence | assumed |
Per spec file:
Layer 3 agents preserve original Layer 1 citations. When multiple sources agree, add corroboration notes:
- Network retries use exponential backoff with jitter
<!-- cite: source=source-code, ref=workspace/raw/source/analysis/chunk-0015.md:89, confidence=confirmed, agent=behavior-documenter, corroborated_by=runtime-observation -->
No behavioral claim may exist without a citation. If you cannot cite a claim, it is assumed -- mark it honestly. Unrecorded assumptions look like confirmed facts to downstream agents and the implementer.
workspace/raw/specs/
modules/ # Per-module behavioral specs (deep-dive-analyzer)
{module-name}.md # SPEC-{DOMAIN}-{NNN} claims, full spec template
contracts/
cli.md # External CLI contract (flows to implementation)
environment.md # External environment contract (flows to implementation)
configuration.md # External configuration contract (flows to implementation)
{protocol}.md # External protocol contracts (flows to implementation)
behavioral-integration.md # BIR table (flows to implementation)
inter-module.md # ANALYSIS ONLY -- does NOT cross into implementation
behavioral-docs/ # Pure behavioral documentation by domain (behavior-documenter)
behavior-{domain}.md # Synthesized behavioral spec per domain
journeys/
{journey-name}.md # End-to-end user journeys (user-journey-analyzer)
workspace/raw/specs/modules/{module-name}.md<!-- cite: --> provenance citationsworkspace/raw/specs/contracts/<!-- cite: --> provenance citationsworkspace/raw/specs/behavioral-docs/<!-- cite: --> provenance citationsworkspace/raw/specs/journeys/<!-- cite: --> provenance citationsAll Layer 3 agents MUST actually invoke the Write tool to produce output files. Do NOT:
If you show file contents in your response without calling Write, THE DATA IS LOST. Every finding gets written to a file IMMEDIATELY.
What SKILL.md sets; muted values are Claude Code's defaults
greenfield@prime-radiant-marketplace is listed by prime-radiant-inc/prime-radiant-marketplace — review the source before installing
npx claudepluginhub prime-radiant-inc/prime-radiant-marketplace --plugin greenfield22 skills in this plugin
/analysis-pipelineReverse engineering - multi-source product intelligence analysis with provenance tracking. Master methodology for all analysis agents./autonomous-discoveryLayer 1 intelligence source discovery - auto-detect available sources, search for public information, negotiate with user, produce inventory manifest/binary-analysisLayer 1 methodology for extracting behavioral intelligence from compiled binaries, bytecode archives, managed assemblies, and bundled applications. Covers artifact identification, string extraction strategy, decompilation workflows, provenance requirements, and handoff to source code mode./community-intelligenceLayer 1 skill for community intelligence gathering. Search channels, extraction methodology, consensus analysis, version-aware behavioral changes, structural contamination guard. Loaded by the analyzer agent for community intelligence gathering./container-executionInfrastructure skill for containerized target execution. Runtime detection, container lifecycle, security restrictions, interaction patterns./contract-detectionLayer 1 skill for parsing machine-readable API contracts. OpenAPI/Swagger, GraphQL, Protobuf/gRPC, and JSON Schema detection, extraction, and behavioral claim generation. Loaded by the analyzer agent during Layer 1.Other plugins' skills for the same job