# Factory AI Formatter

<!-- generated:start:overview -->
<!-- Auto-generated by `pnpm docs:formatters`. Do not edit manually. -->

| Property          | Value                                   |
| ----------------- | --------------------------------------- |
| **Tier**          | Custom                                  |
| **Main output**   | `AGENTS.md`                             |
| **Dot directory** | `.factory/`                             |
| **Skills**        | Yes (`.factory/skills/<name>/SKILL.md`) |
| **Agents**        | Yes (`.factory/droids/<name>.md`)       |
| **Commands**      | Yes (`.factory/commands/<name>.md`)     |
| **Local files**   | No                                      |

<!-- generated:end:overview -->

## Output Files

<!-- generated:start:output-files -->
<!-- Auto-generated by `pnpm docs:formatters`. Do not edit manually. -->

| File              | Path                              | Purpose                                                    |
| ----------------- | --------------------------------- | ---------------------------------------------------------- |
| Main instructions | `AGENTS.md`                       | Primary rule file                                          |
| Always-on rules   | `.factory/rules/**/*.md`          | Split rule files when `rulesMode: split`                   |
| Lifecycle hooks   | `.factory/hooks.json`             | Project hooks in `multifile` and `full` modes              |
| Skills            | `.factory/skills/<name>/SKILL.md` | Reusable skill definitions in `multifile` and `full` modes |
| Commands          | `.factory/commands/<name>.md`     | Slash commands                                             |
| Agents            | `.factory/droids/<name>.md`       | Agent configurations                                       |
| MCP servers       | `.factory/mcp.json`               | MCP server config in `multifile` and `full` modes          |
| Plugins           | `.factory/plugins.json`           | Plugin config in `multifile` and `full` modes              |

<!-- generated:end:output-files -->

## Supported Features

<!-- generated:start:features -->
<!-- Auto-generated by `pnpm docs:formatters`. Do not edit manually. -->

| Feature                    | Supported |
| -------------------------- | --------- |
| Markdown Output            | Yes       |
| MDC Format                 | No        |
| Code Blocks                | Yes       |
| Mermaid Diagrams           | Yes       |
| Single File Output         | Yes       |
| Multiple Rule Files        | Yes       |
| Workflow Files             | No        |
| Nested Directory Structure | Yes       |
| YAML Frontmatter           | Yes       |
| Description in Frontmatter | Yes       |
| Globs in Frontmatter       | No        |
| Activation Type            | No        |
| Glob Pattern Targeting     | No        |
| Always Apply Rules         | Yes       |
| Manual Activation          | No        |
| Auto/Model Activation      | No        |
| Structured Examples        | Yes       |
| Character Limit Validation | No        |
| Content Section Splitting  | Yes       |
| Guard Dependencies         | Yes       |
| Context File Inclusion     | No        |
| @-Mentions                 | No        |
| Tool Integration           | No        |
| Path-Specific Rules        | No        |
| Prompt Files               | No        |
| Slash Commands             | Yes       |
| Skills                     | Yes       |
| Agent Instructions         | Yes       |
| Local Memory               | No        |
| Nested Memory              | No        |

<!-- generated:end:features -->

## Limitations & Quirks

- Uses `AGENTS.md` as the main file (extends MarkdownInstructionFormatter)
- Skills go to `.factory/skills/<name>/SKILL.md`
- Agents are called "droids" - output to `.factory/droids/<name>.md`
- Droid `model` and `specModel` values become API ids such as `claude-sonnet-4-5-20250929` or `gpt-5.3-codex`; `inherit` is written as is (see [Model Catalog](https://getpromptscript.dev/reference/models/index.md#target-model-names))
- `@hooks` uses `.factory/hooks.json` with PascalCase event names in `multifile` and `full` modes. The file is keyed directly by event name (`{"PreToolUse": [...]}`); only `settings.json` wraps the map in `hooks`. A wrapped `hooks.json` from PromptScript 1.27 or earlier is read and rewritten in the bare shape
- `pre-terminal-command` maps to `PreToolUse` with the deterministic `Execute` matcher unless `targets.factory.matcher` overrides it
- Hook `matcher` values match Factory tool names (for example `Execute`, `Read`, `Edit|Write`); other targets use different tool-name vocabularies, so a matcher that works here may match nothing elsewhere
- `.factory/settings.json` remains a Factory fallback; `prs hooks install factory` migrates its unambiguous hooks. `hooksFile: settings.json` writes `@hooks` there instead (see [Hooks File](#hooks-file))
- When `@hooks` is removed or no longer emits, the CLI removes a fully PromptScript-owned `.factory/hooks.json`; directories emptied by cleanup (`.factory/rules` and its subdirectories) are pruned as well
- Three output modes: `simple`, `multifile`, `full`
- Always-on rules default to the byte-compatible `monolith` mode
- In `monolith` mode, `@standards` render as grouped `###` subsections (one per topic) under `Conventions & Patterns`, preserving the source topic structure
- Free-form text `@standards` (triple-quoted string) renders under `Conventions & Patterns` in `monolith` mode, or as `.factory/rules/standards.md` in split rules mode; embedded headings are adjusted to nest under the surrounding section (h2 downgraded to h3 in monolith, relative shift in split)
- Split rules require the `multifile` or `full` output version

PromptScript versions before 1.16 could place language-level hooks in
`.factory/settings.json`. When `.factory/hooks.json` is absent, `prs compile`
moves unambiguous legacy entries into the canonical file, preserves unrelated
settings, and refuses partial migrations when event names, handlers, or
ownership are ambiguous. `--dry-run` previews the migration, while
`--no-migrate-factory-hooks` leaves the fallback unchanged and reports
`PS4002`. `prs hooks install factory` remains available for explicit migration
and hook installation.

A legacy handler is written only once. When `@hooks` already generates the same
command for the same event and matcher, the migration drops the hand-written
copy instead of moving it next to the generated one, so Factory does not run
the hook twice. Running the migration again gives the same result.

## Hooks File

Factory reads project hooks from `.factory/hooks.json`. Only when that file is
absent does it read the `hooks` key of `.factory/settings.json`. Factory does
not merge the two files. See the
[Factory hooks reference](https://docs.factory.ai/reference/hooks-reference).

`hooksFile` picks where PromptScript writes `@hooks`:

```yaml
targets:
  - factory:
      version: multifile
      hooksFile: settings.json # default: hooks.json
```

| Value                  | Generated file                          | Notes                                                            |
| ---------------------- | --------------------------------------- | ---------------------------------------------------------------- |
| `hooks.json` (default) | `.factory/hooks.json`                   | Legacy `settings.json` hooks are migrated into it                |
| `settings.json`        | `hooks` key of `.factory/settings.json` | No legacy migration; other settings keys and user hooks are kept |

With `settings.json`, a PromptScript-owned `.factory/hooks.json` is removed by
cleanup. If a `.factory/hooks.json` with your own hooks is still there,
`prs compile` reports `PS4002`, because Factory would ignore the hooks in
`settings.json`.

## Settings

`settings` writes Factory project settings to `.factory/settings.json` in
`multifile` and `full` modes:

```yaml
targets:
  - factory:
      version: multifile
      settings:
        model: claude-sonnet-4-5
        enabledPlugins:
          code-standards@acme-plugins: true
```

Supported keys are `model` and `enabledPlugins`. Other `settings` keys
(`permissions`, `env`) are Claude only; Factory reports `PS4002` and skips
them. PromptScript merges the keys into an existing `.factory/settings.json`:
keys it does not generate stay, and for `enabledPlugins` only the listed
plugins are set. A key removed from the config is not removed from the file.

## Split Rules

Use `rulesMode: split` to keep `AGENTS.md` focused on operational context while
moving the always-on standards into rule files under `.factory/rules/`. `AGENTS.md`
links to each rule file so an agent can open the relevant one before editing
related code.

```yaml
targets:
  - factory:
      version: multifile
      rulesMode: split
```

Split mode emits one file for each non-empty `@standards` topic, plus semantic
files for git workflows, configuration, documentation, diagrams, remaining
knowledge, restrictions, and examples when those sections exist. `AGENTS.md`
contains a readable index of only the emitted files.

When `@standards` contains free-form text instead of topics, split mode emits
a single `.factory/rules/standards.md` file with the text normalized (common
indentation stripped, headings shifted relative to the shallowest one so it
becomes h2 below the `# Standards` title, capped at h6).

When a custom `outputPath` is configured for the target, the rule files still
live in `.factory/rules/` at the project root and the index links are rewritten
relative to the custom `AGENTS.md` location.

When rules are removed or the target returns to `rulesMode: monolith`, the CLI
removes obsolete files only when they carry a PromptScript generated marker.
Unmarked files and symlinks are never removed.

## Example Output

```
project-root/
├── AGENTS.md                          # Main instructions
└── .factory/
    ├── rules/
    │   ├── standards/
    │   │   ├── security.md
    │   │   └── typescript.md
    │   ├── git-workflows.md
    │   └── restrictions.md
    ├── skills/
    │   └── my-skill/
    │       └── SKILL.md
    └── droids/
        └── reviewer.md
```

## Official Documentation

- [Factory AI Documentation](https://docs.factory.ai/)
- [Factory Hooks Reference](https://docs.factory.ai/reference/hooks-reference)