---
phase: 03-manage
plan: 02
type: execute
wave: 1
depends_on: []
files_modified:
  - possession/tui/screens/main.py
  - possession/tui/widgets/quickadd.py
autonomous: true
requirements:
  - QADD-01
  - QADD-02
  - QADD-03

must_haves:
  truths:
    - "User presses 'a' anywhere in the TUI and a quick-add bar appears at the bottom"
    - "User types 'drill / Garage / Tool Cabinet' and presses Enter — item is saved with name=drill, room=Garage, container=Tool Cabinet"
    - "Partial entry with only name is accepted — all other fields default to NULL"
    - "Typing a room name that does not exist triggers a Y/n prompt before creating it"
    - "Pressing Escape dismisses the quick-add bar without saving"
    - "After saving, the DataTable refreshes to show the new item"
  artifacts:
    - path: "possession/tui/widgets/quickadd.py"
      provides: "QuickAddBar widget with parse logic"
      contains: "class QuickAddBar"
    - path: "possession/tui/screens/main.py"
      provides: "Quick-add integration: 'a' binding, QuickAddBar mount, result handling"
      contains: "action_open_quickadd"
  key_links:
    - from: "possession/tui/screens/main.py"
      to: "possession/tui/widgets/quickadd.py"
      via: "yield QuickAddBar in compose()"
      pattern: "QuickAddBar"
    - from: "possession/tui/widgets/quickadd.py"
      to: "possession/models.py"
      via: "from possession.models import create_item, create_room, create_container, list_rooms, list_containers"
      pattern: "create_item|create_room|create_container"
---

<objective>
Implement the quick-add bar for frictionless item creation (QADD-01, QADD-02, QADD-03).

Purpose: Users should be able to add items without leaving the keyboard or navigating menus. A single 'a' keypress opens a bar where they type a slash-separated entry and press Enter to save.
Output: QuickAddBar widget in possession/tui/widgets/quickadd.py and integration in MainScreen.
</objective>

<execution_context>
@/Users/paritoshpatil/.claude/get-shit-done/workflows/execute-plan.md
@/Users/paritoshpatil/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/STATE.md
@.planning/ROADMAP.md
@possession/tui/screens/main.py
@possession/tui/app.py
@possession/models.py
</context>

<tasks>

<task type="auto">
  <name>Task 1: Implement QuickAddBar widget with parse logic and confirmation flow</name>
  <files>possession/tui/widgets/quickadd.py</files>
  <action>
Create possession/tui/widgets/quickadd.py with a QuickAddBar widget.

**Widget class:**
```python
class QuickAddBar(Widget):
```

The widget composes two child widgets stacked vertically:
1. An `Input` widget (id="quickadd-input") with placeholder `"name / description / room / container / category / purchase_date / cost"` for the main entry line
2. An `Input` widget (id="quickadd-confirm", classes="hidden") with placeholder `"Room 'X' not found. Create it? [y/N]"` used for the yes/no confirmation step

The entire QuickAddBar widget is hidden by default (add CSS class `"hidden"` in compose or via DEFAULT_CSS).

**Parsing (implement as module-level function `_parse_quickadd(text: str) -> dict`):**
Split on `/`, strip whitespace from each part. Map positional fields:
- Index 0: name (required)
- Index 1: description
- Index 2: room (name string)
- Index 3: container (name string)
- Index 4: category (name string)
- Index 5: purchase_date
- Index 6: cost (convert to float if present, else None)

Return a dict with keys: name, description, room, container, category, purchase_date, cost. Missing fields default to None. If name is empty string after strip, return None (invalid entry).

**Public API:**
- `open(db_path: Path) -> None`: Remove hidden class, focus input, store db_path
- `close() -> None`: Add hidden class, clear inputs
- Post a custom message `QuickAddBar.ItemSaved` (subclass of `Message`) when an item is successfully saved, so MainScreen can reload the DataTable.

**On Enter in quickadd-input (on_input_submitted):**
1. Parse the input text with `_parse_quickadd`.
2. If name is empty: dismiss without saving.
3. Look up room name in `list_rooms(db_path)`. If room provided but not found: show confirm widget with message `f"Room '{room_name}' not found. Create it? [y/N] "`, focus confirm widget, store pending state. Return (wait for confirm response).
4. If room found: resolve room_id. Look up container name in `list_containers(db_path, room_id=room_id)`. If container provided but not found: show confirm widget with container creation prompt. Wait for confirm.
5. If all lookups resolve (or fields were empty): call `_save_item()` directly.

**On Enter in quickadd-confirm:**
- If user typed 'y' or 'Y': proceed with creation (create_room or create_container as appropriate), then continue resolution and eventually call `_save_item()`.
- Otherwise: close bar without saving.

**_save_item():** Resolve category_id via `list_categories` (import from models). Call `create_item(db_path, name=..., description=..., room_id=..., container_id=..., category_id=..., purchase_date=..., cost=...)`. Post `QuickAddBar.ItemSaved()` message. Close bar.

**Imports needed:** Path (typing/pathlib), Optional (typing), textual.app.ComposeResult, textual.widgets.Input, textual.widget.Widget, textual.message.Message. Models: create_item, create_room, create_container, list_rooms, list_containers, list_categories.

Use Python 3.9 compatible type hints throughout (Optional[X] not X | None).
  </action>
  <verify>
    <automated>cd /Users/paritoshpatil/Personal/claude-projects/possession-terminal-2 && python3 -c "from possession.tui.widgets.quickadd import QuickAddBar, _parse_quickadd; r = _parse_quickadd('drill / cordless / Garage / Tool Cabinet / Tools'); assert r['name'] == 'drill'; assert r['room'] == 'Garage'; print('OK')"</automated>
  </verify>
  <done>QuickAddBar importable, _parse_quickadd correctly maps positional fields, partial entries work (missing fields are None)</done>
</task>

<task type="auto">
  <name>Task 2: Integrate QuickAddBar into MainScreen</name>
  <files>possession/tui/screens/main.py</files>
  <action>
Integrate QuickAddBar into MainScreen in possession/tui/screens/main.py.

**Changes to compose():**
Add `from possession.tui.widgets.quickadd import QuickAddBar` import inside compose() (follow the same deferred-import pattern used for Breadcrumb). Yield a `QuickAddBar(id="quickadd-bar")` after the DataTable and filter-input yield statements.

**New binding:**
Add `("a", "open_quickadd", "Add")` to the BINDINGS list.

**New action method:**
```python
def action_open_quickadd(self) -> None:
    """Open the quick-add bar."""
    self.query_one("#quickadd-bar", QuickAddBar).open(self.app.db_path)
```

**New message handler:**
```python
def on_quick_add_bar_item_saved(self, event) -> None:
    """Reload the DataTable after a quick-add save."""
    self._load_view()
```

The message handler name follows Textual convention: `on_{widget_class_snake}_{message_class_snake}`. QuickAddBar.ItemSaved → `on_quick_add_bar_item_saved`.

**No other changes** to existing MainScreen logic (filter bar, drill-down state machine, breadcrumb, cursor actions all stay untouched).

Make sure QuickAddBar import reference inside compose() is also available in action_open_quickadd — either import at top of file or use a helper. Keep consistent with existing pattern of deferred imports used for Breadcrumb (import inside the method that needs it).
  </action>
  <verify>
    <automated>cd /Users/paritoshpatil/Personal/claude-projects/possession-terminal-2 && python3 -c "from possession.tui.screens.main import MainScreen; print('OK')"</automated>
  </verify>
  <done>MainScreen imports without error, 'a' binding present in BINDINGS, action_open_quickadd and on_quick_add_bar_item_saved methods exist</done>
</task>

</tasks>

<verification>
Run import checks:
```
cd /Users/paritoshpatil/Personal/claude-projects/possession-terminal-2
python3 -c "from possession.tui.widgets.quickadd import QuickAddBar, _parse_quickadd; print('widget OK')"
python3 -c "from possession.tui.screens.main import MainScreen; print('screen OK')"
python3 -m pytest tests/ -x -q
```
All existing tests pass. No import errors.
</verification>

<success_criteria>
- QuickAddBar widget exists in possession/tui/widgets/quickadd.py
- _parse_quickadd handles 1-7 fields correctly (missing fields → None)
- QuickAddBar.ItemSaved message posted on successful save
- 'a' key opens quick-add bar from MainScreen
- QADD-03 confirmation flow: unknown room or container triggers Y/n prompt before create
- All existing tests still pass
</success_criteria>

<output>
After completion, create `.planning/phases/03-manage/03-02-SUMMARY.md`
</output>
