KB-45F5 rev 3

23-P3D3 — Notification Context + Directus Exposure Design — Prompt (rev3)

8 min read Revision 3
p3d3promptcontextdirectusdesignnotificationrev3

23-P3D3 — Notification Context + Directus Exposure Design — Prompt (rev3)

Date: 2026-05-08 Status: PROMPT rev3 — chờ GPT/User final review. CHƯA dispatch. Report: knowledge/dev/laws/dieu44-trien-khai/reports/23-p3d3-notification-context-directus-exposure-report.md Scope: KB document updates only. NO PG/Directus/Nuxt changes. Rev1→Rev2: Fix next_required_pack naming + add explicit Directus exposure boundary. Rev2→Rev3: Fix P3D5 wording, add no-Nuxt-page-commitment, clarify human vs AI access path.


Hard Boundaries

  • ❌ No PG schema/function/trigger changes
  • ❌ No Directus config mutation
  • ❌ No Nuxt code
  • ❌ No Nuxt page commitment — any display must try existing Directus/Nuxt assembly first
  • ❌ No Hermes production start
  • ❌ Do not implement Directus exposure yet. P3D3 is context + design note only. Directus exposure requires later GPT/User reviewed approval.
  • ✅ KB document create/update only

Objectives

Agent must create/update 2 KB documents, verify both by reading back.


Document 1: Update Context Pack

Path: knowledge/dev/laws/dieu44-trien-khai/context-packs/iu-agent-front-door-context.md Action: Update (upsert) Title: IU Agent Front-Door Context Tags: iu, agent, context, fn_iu_save, fn_iu_comment, notification

Content:

# IU Agent Front-Door Context

> AI/Agent: hướng dẫn hệ thống Information Unit.
> Không cần nhớ quy trình.

## Tạo hoặc sửa nội dung

```sql
SELECT fn_iu_save('địa-chỉ', 'nội dung', 'actor');
  • Địa chỉ mới → phiên bản 1 chính thức.
  • Địa chỉ đã có → nháp chờ duyệt (policy=require_review).
  • Nội dung giống → no_change.
  • fn_iu_save(addr, body, actor, title, reason, 'draft') → luôn nháp.

Góp ý

SELECT fn_iu_comment('địa-chỉ', 'actor', 'comment', 'general', 'agent', '{}'::jsonb);

Tự do, không phê duyệt.

Phê duyệt nháp (reviewer)

SELECT fn_iu_apply_edit_draft('draft-id', 'reviewer', 'ghi chú');

Kiểm tra hộp thư (notification)

-- Có gì mới chưa đọc?
SELECT * FROM fn_iu_unread('actor');

-- Lọc theo stream: 'comment', 'review', 'update'
SELECT * FROM fn_iu_unread('actor', 'review');

-- Đánh dấu đã xem
SELECT fn_iu_mark_read(ARRAY['event-id-1','event-id-2']::uuid[], 'actor');

-- Bảng tổng hợp: ai đọc gì, ai chưa đọc
SELECT * FROM fn_iu_notification_board('actor');

Read-state semantics

  • Per-actor: GPT đọc rồi chỉ ẩn với GPT. Opus/User chưa đọc vẫn thấy.
  • Implicit self-read: Opus tạo event → Opus mặc nhiên đã đọc, không cần báo lại.
  • read_status_source: implicit_self (tự tạo) | explicit_read (đã mark) | unread (chưa đọc).
  • latest_readers: board trả danh sách 5 actor gần nhất đã đọc.
  • Actionable board: draft đã applied/stale thì ẩn khỏi review inbox. History vẫn lưu.

UI boundary

PG là source of truth. Directus expose PG. Nuxt chỉ đọc từ Directus qua existing assembled screens/components. Không thêm Nuxt business logic. Không kết nối PG trực tiếp từ Nuxt.

Quy tắc

  • KHÔNG ghi trực tiếp vào information_unit / unit_version.
  • Nháp chưa apply ≠ bản chính.
  • Mọi status trả về có guidance + next_action.
  • Actor nên ổn định: gpt, opus, agent:codex, reviewer:gpt, user:huyen.
  • Rollback policy phải qua reviewed pack. Không raw UPDATE.
  • Hermes production chưa bật.

---

## Document 2: Create Directus/Nuxt Exposure Design Note

**Path:** `knowledge/dev/laws/dieu44-trien-khai/design/23-p3d3-user-notification-board-directus-exposure-design.md`
**Action:** Create (new)
**Title:** P3D3 — User Notification Board — Directus Exposure Design
**Tags:** p3d3, design, notification, directus, nuxt, user-board

**Content:**

```markdown
# P3D3 — User Notification Board — Directus Exposure Design

> Date: 2026-05-08
> Status: DESIGN — chờ review. Chưa implement.

## 1. Mục tiêu

User (anh Huyên) cần xem cùng bảng thông báo mà AI dùng:
- Comment mới trên miếng nào
- Draft nào cần review
- Update/apply mới
- AI/agent nào đã đọc, ai chưa đọc

## 2. Kiến trúc boundary

PG (source of truth) ├── iu_notification_event ├── iu_notification_read ├── fn_iu_unread / fn_iu_mark_read / fn_iu_notification_board └── PG view (nếu cần) ↓ Directus (exposure layer) ├── Collection / custom endpoint backed by PG view/table ├── Permissions per role └── API endpoint ↓ Nuxt (render only) ├── Đọc từ Directus API ├── Không business logic └── Không kết nối PG trực tiếp


## 3. Đường truy cập theo vai trò

- **AI/Agent** truy cập trực tiếp qua PG functions (fn_iu_unread, fn_iu_mark_read, fn_iu_notification_board). SQL là giao diện chính.
- **Human user** truy cập qua Directus/Nuxt exposure sau này. User không cần và không nên được kỳ vọng chạy SQL.
- Hai đường khác nhau, cùng một source of truth (PG).

## 4. PG exposure primitive — so sánh

| Option | Ưu | Nhược |
|---|---|---|
| **PG View** | Directus tự discover, collection-like, permissions dễ | Khó truyền actor param |
| **PG Function qua Directus custom endpoint** | Linh hoạt, truyền actor param | Cần Directus extension hoặc custom flow |
| **Directus Flow + PG query** | Không cần extension | Performance, maintenance |

**Khuyến nghị Phase 1:** PG View cho board overview (không per-actor filter). Directus custom endpoint cho per-actor unread/board.

## 5. Actor identity convention

| Actor | Ý nghĩa |
|---|---|
| gpt | GPT-5.5 Thinking |
| opus | Claude Opus |
| agent:codex | Codex agent |
| reviewer:gpt | GPT as reviewer |
| user:huyen | Anh Huyên |

Tất cả dùng chung read-state model. Human read state cũng per-actor.

## 6. Human user experience

- User xem board → thấy tất cả events
- User thấy: "GPT đã đọc, Opus chưa đọc, tôi chưa đọc"
- User mark read → chỉ user:huyen hết unread
- AI actors không bị ảnh hưởng

## 7. Chưa implement trong P3D3

- ❌ PG view chưa tạo
- ❌ Directus collection/endpoint chưa config
- ❌ Nuxt component chưa code
- ❌ Hermes chưa bật
- ✅ Design note này là blueprint cho P3D4+

This design does not commit to a new Nuxt page. Any human-facing display must first try existing Directus/Nuxt assembly and requires later review.

## 8. Next steps

| Pack | Nội dung |
|---|---|
| P3D4 | Directus exposure design review + implementation (nếu approved) |
| P3D5 | Optional display assembly review — no code-first Nuxt work |
| Hermes | Reviewer automation (separate review) |

Verification

Agent must:

  1. Upload/update context pack → read back → confirm content present
  2. Upload exposure design note → read back → confirm content present
  3. Report:
    • context_pack_upload=PASS|FAIL
    • exposure_design_upload=PASS|FAIL
    • phase_status=PASS only if both uploads verified
    • no_pg_mutation=true
    • no_directus_mutation=true
    • no_nuxt_code=true
    • no_nuxt_page_commitment=true
    • no_directus_exposure_implementation=true
    • next_required_pack=P3D4_DIRECTUS_EXPOSURE_DESIGN_OR_IMPLEMENTATION_REVIEW

P3D3 rev3 | KB documents only | context update + exposure design | CHƯA dispatch | Chờ GPT/User final review

Back to Knowledge Hub knowledge/dev/laws/dieu44-trien-khai/prompts/23-p3d3-notification-context-directus-exposure-prompt.md