メインコンテンツへスキップ
Droidはセッション間で組み込みのメモリを持ちませんが、markdownファイル、AGENTS.mdの参照、およびフックを使用して強力なメモリシステムを作成できます。このガイドでは、永続化され成長するメモリの構築方法を説明します。
Works with Factory App: These memory patterns work identically in both CLI and Factory App—just ensure your working directory is set to your repository root.

メモリシステムアーキテクチャ

メモリシステムは3つの層で構成されます:
┌─────────────────────────────────────────────────────┐
│                    AGENTS.md                         │
│         (References and orchestrates memory)         │
└─────────────────────────────────────────────────────┘

          ┌──────────────┼──────────────┐
          ▼              ▼              ▼
┌─────────────────┐ ┌─────────────┐ ┌─────────────────┐
│ Personal Memory │ │ Project     │ │ Rules &         │
│ ~/.factory/     │ │ Memory      │ │ Conventions     │
│ memories.md     │ │ .factory/   │ │ .factory/rules/ │
│                 │ │ memories.md │ │                 │
│ • Preferences   │ │ • Decisions │ │ • Standards     │
│ • Style         │ │ • History   │ │ • Patterns      │
│ • Tools         │ │ • Context   │ │ • Guidelines    │
└─────────────────┘ └─────────────┘ └─────────────────┘

個人メモリの設定

個人メモリはすべてのプロジェクトで共有されます。

ステップ1:メモリファイルの作成

~/.factory/memories.mdを作成します:
# My Development Memory

## Code Style Preferences

### General
- I prefer functional programming patterns over OOP
- I like early returns to reduce nesting
- I use 2-space indentation (but defer to project config)

### TypeScript
- I prefer `interface` over `type` for object shapes
- I use strict mode always
- I avoid `enum` in favor of `as const` objects

### React
- Functional components only
- I prefer Zustand over Redux for state
- I use React Query for server state

## Tool Preferences
- Package manager: pnpm (prefer) > npm > yarn
- Testing: Vitest > Jest
- Formatting: Prettier with defaults
- Linting: ESLint with strict TypeScript rules

## Communication Style
- I prefer concise explanations over verbose ones
- Show me the code first, explain after if needed
- When debugging, show me your reasoning

## Past Decisions (Personal Projects)
- [2024-01] Switched from Create React App to Vite
- [2024-02] Adopted Tailwind CSS as default styling
- [2024-03] Using Supabase for personal projects

ステップ2:AGENTS.mdで参照

~/.factory/AGENTS.mdまたはプロジェクトのAGENTS.mdに追加します:
## Personal Preferences
My coding preferences and tool choices are documented in `~/.factory/memories.md`.
Refer to this file when making decisions about code style, architecture, or tooling.

プロジェクトメモリの設定

プロジェクトメモリは、コードベース固有の決定とコンテキストを記録します。

ステップ1:プロジェクトメモリの作成

プロジェクトルートに.factory/memories.mdを作成します:
# Project Memory

## Project Context
- **Name**: Acme Dashboard
- **Type**: B2B SaaS application
- **Stack**: Next.js 14, TypeScript, Prisma, PostgreSQL
- **Started**: January 2024

## Architecture Decisions

### 2024-01-15: Database Choice
**Decision**: PostgreSQL over MongoDB
**Reasoning**: Strong relational data model, ACID compliance needed for financial data
**Trade-offs**: More rigid schema, but better for reporting queries

### 2024-02-01: Authentication Approach
**Decision**: NextAuth.js with custom credentials provider
**Reasoning**: Need to integrate with existing enterprise LDAP
**Implementation**: See `src/lib/auth/` for setup

### 2024-02-20: State Management
**Decision**: Zustand for client state, React Query for server state
**Reasoning**: Simpler than Redux, better separation of concerns
**Pattern**: Store files in `src/stores/`, queries in `src/queries/`

## Known Technical Debt
- [ ] Auth refresh token logic needs refactoring (#234)
- [ ] Dashboard queries should be optimized with proper indexes
- [ ] Legacy API endpoints in `/api/v1/` need deprecation

## Domain Knowledge

### Business Rules
- Users belong to Organizations (multi-tenant)
- Subscription tiers: Free, Pro, Enterprise
- Free tier limited to 3 team members
- Data retention: 90 days for Free, unlimited for paid

### Key Entities
- `User`: Individual accounts, can belong to multiple orgs
- `Organization`: Tenant container, has subscription
- `Project`: Work container within an org
- `Task`: Work items within projects

## Team Conventions
- PR titles follow conventional commits
- All PRs need at least one approval
- Deploy to staging on merge to `develop`
- Deploy to production on merge to `main`

ステップ2:プロジェクトAGENTS.mdで参照

プロジェクトのAGENTS.mdを更新します:
## Project Memory
Architecture decisions, domain knowledge, and project history are documented in `.factory/memories.md`.
Always check this file before making significant architectural or design decisions.

メモリカテゴリ

メモリを有用なカテゴリに整理します:

設定(個人)

あなたの好みと作業方法:
## Preferences
- Code style choices
- Tool preferences  
- Communication style
- Learning style

決定(プロジェクト)

何が決定され、その理由:
## Decisions
- Architecture choices with reasoning
- Library selections with trade-offs
- Design patterns adopted
- Standards agreed upon

コンテキスト(プロジェクト)

背景情報:
## Context
- Business domain knowledge
- Key entities and relationships
- External integrations
- Performance requirements

履歴(両方)

いつ何が起こったか:
## History
- Major refactors completed
- Migrations performed
- Issues resolved
- Lessons learned

自動メモリ取得

作業中にメモリを取得するのに役立つフックを作成します。

「これを記憶」フック

「remember this:」の後にコンテンツを続けると、自動的にメモリに追加されます。 メモリキャプチャは特殊文字またはフレーズのいずれかでトリガーできます。好みに基づいて選択してください:
Trigger with # at the start of your message for quick capture.Usage:
  • “#we use the repository pattern”
  • “##I prefer early returns” (double ## for personal)
Create ~/.factory/hooks/memory-capture.py:
#!/usr/bin/env python3
"""Captures messages starting with # and appends to memories.md"""
import json, sys, os
from datetime import datetime

def main():
    try:
        data = json.load(sys.stdin)
        prompt = data.get('prompt', '').strip()
        
        if not prompt.startswith('#'):
            return
        
        # ## = personal, # = project
        if prompt.startswith('##'):
            content = prompt[2:].strip()
            mem_file = os.path.expanduser('~/.factory/memories.md')
        else:
            content = prompt[1:].strip()
            project_dir = os.environ.get('FACTORY_PROJECT_DIR', os.getcwd())
            project_factory = os.path.join(project_dir, '.factory')
            if os.path.exists(project_factory):
                mem_file = os.path.join(project_factory, 'memories.md')
            else:
                mem_file = os.path.expanduser('~/.factory/memories.md')
        
        if content:
            timestamp = datetime.now().strftime('%Y-%m-%d')
            with open(mem_file, 'a') as f:
                f.write(f"\n- [{timestamp}] {content}\n")
            
            print(json.dumps({'systemMessage': f'✓ Saved to {mem_file}'}))
    except:
        pass

if __name__ == '__main__':
    main()
実行可能にし、フックを設定します:
chmod +x ~/.factory/hooks/memory-capture.py
/hooksを使用してフック設定に追加します:
{
  "hooks": {
    "UserPromptSubmit": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "python3 ~/.factory/hooks/memory-capture.py"
          }
        ]
      }
    ]
  }
}
#プレフィックス使用:
  • “#we decided to use Zustand for state management”
  • “##I prefer early returns” (ダブル##は個人用に保存)
フレーズトリガー使用:
  • “Remember this: we decided to use Zustand for state management”
  • “Note: the auth module uses JWT with 24-hour expiration”

代替案:メモリキャプチャスキル

フックの代わりに、何かを記憶するように依頼したときにDroidが呼び出すskillを使用できます。これにより、カテゴリ化をよりインタラクティブに制御できます。 すぐに使用できる実装については、memory-capture skill exampleを参照してください。

代替案:カスタムスラッシュコマンド

手動での素早い取得には、custom slash commandを作成します: ~/.factory/commands/remember.mdを作成:
---
description: Save a memory to your memories file
argument-hint: <what to remember>
---

Add this to my memories file (~/.factory/memories.md):

$ARGUMENTS

Format it appropriately based on whether it's a preference, decision, or learning. Include today's date.
その後、/remember we chose PostgreSQL for better ACID complianceを使用してメモリをオンデマンドで取得します。
Which approach to choose?
  • Hook — Best for automatic capture without extra steps
  • Skill — Best when you want Droid to help categorize and format
  • Slash Command — Best for quick manual capture with consistent formatting

メモリメンテナンス

定期的なメンテナンスでメモリを有用に保ちます。

月次レビューチェックリスト

## Monthly Memory Review

### Personal Memory (~/.factory/memories.md)
- [ ] Remove outdated preferences (tools you no longer use)
- [ ] Update decisions that have changed
- [ ] Add new patterns you've adopted
- [ ] Archive old entries that are no longer relevant

### Project Memory (.factory/memories.md)
- [ ] Review architecture decisions - still valid?
- [ ] Update technical debt items
- [ ] Add new domain knowledge learned
- [ ] Document recent major changes

古いメモリのアーカイブ

メモリが古くなったら、アーカイブに移動します:
# memories.md

## Current Decisions
[active decisions here]

## Archive (2023)
<details>
<summary>Archived decisions from 2023</summary>

### 2023-06: Original Auth System
**Decision**: Custom JWT implementation
**Status**: Replaced by NextAuth.js in 2024-02
**Reason for change**: Maintenance burden, security updates

</details>

上級:メモリ対応スキル

メモリファイルを活用するスキルを作成します:
---
name: context-aware-implementation
description: Implement features using project memory and conventions.
---

# Context-Aware Implementation

Before implementing any feature:

1. **Check project memory** (`.factory/memories.md`):
   - What architecture decisions apply?
   - What patterns should I follow?
   - What constraints exist?

2. **Check personal preferences** (`~/.factory/memories.md`):
   - What code style does the user prefer?
   - What tools should I use?

3. **Check rules** (`.factory/rules/`):
   - What conventions apply to this file type?
   - What testing requirements exist?

Then implement following all discovered context.

クイックリファレンス

ファイル場所

メモリタイプ場所スコープ
個人設定~/.factory/memories.md全プロジェクト
プロジェクト決定.factory/memories.mdこのプロジェクト
チーム規約.factory/rules/*.mdこのプロジェクト

メモリを追加するタイミング

イベント記録内容場所
アーキテクチャ決定を行った決定 + 理由プロジェクト
設定を発見した好み個人
ドメイン知識を学んだビジネスルール、エンティティプロジェクト
ワークフローを変更した新しいツールやパターン個人
複雑な問題を解決した解決策とコンテキストプロジェクト

メモリフォーマットテンプレート

### [Date]: [Title]
**Decision/Preference**: [What]
**Reasoning**: [Why]
**Context**: [When this applies]
**Trade-offs**: [What you gave up]

次のステップ