diff --git a/reports/month-01/week-02-local-storage.md b/reports/month-01/week-02-local-storage.md index f3bfdf1..23821f0 100644 --- a/reports/month-01/week-02-local-storage.md +++ b/reports/month-01/week-02-local-storage.md @@ -2,11 +2,11 @@ Add one block for every fellow who contributed. Keep each block short. -## Fellow 1: Full Name +## Fellow 1: Alain Chan -- **Topic:** Topic worked on -- **What I did:** Describe the work you completed, the result you achieved, how you verified it, one challenge you addressed, and the main lesson you learned this week. Use at least 20 words. -- **Public output:** [Post title](https://example.com/post) - Medium, X, LinkedIn, or another public platform +- **Topic:** Capture / Create Context +- **What I did:** I implemented the `create_context_item` API for the Local Context Store. It validates context type, title, content, source, tags, and importance before saving a new context item into SQLite. I verified it with the Week 2 storage test script and learned that useful local-first AI memory starts with clean, structured context capture. +- **Public output:** [Why Local-First AI Starts With Good Context Capture](https://dev.to/alaindevs/why-local-first-ai-starts-with-good-context-capture-3d9g) - Dev.to ## Fellow 2: Full Name diff --git a/src/python/local_first_ai/storage/create_context.py b/src/python/local_first_ai/storage/create_context.py new file mode 100644 index 0000000..d2260ea --- /dev/null +++ b/src/python/local_first_ai/storage/create_context.py @@ -0,0 +1,58 @@ +from __future__ import annotations + +from collections.abc import Iterable + +from local_first_ai.storage.db_contract import ( + database_connection, + normalize_optional_text, + normalize_tags, + utc_now, + validate_context_type, + validate_importance, + validate_required_text, +) + + +def create_context_item( + context_type: str, + title: str, + content: str, + source: str | None = None, + tags: str | Iterable[str] | None = None, + importance: int = 1, +) -> int: + context_type = validate_context_type(context_type) + title = validate_required_text(title, "title") + content = validate_required_text(content, "content") + source = normalize_optional_text(source, "source") + tags = normalize_tags(tags) + importance = validate_importance(importance) + timestamp = utc_now() + + with database_connection() as connection: + cursor = connection.execute( + """ + INSERT INTO context_items ( + context_type, + title, + content, + source, + tags, + importance, + created_at, + updated_at + ) + VALUES (?, ?, ?, ?, ?, ?, ?, ?) + """, + ( + context_type, + title, + content, + source, + tags, + importance, + timestamp, + timestamp, + ), + ) + return int(cursor.lastrowid) diff --git a/tests/python/storage/week_02_test_report.md b/tests/python/storage/week_02_test_report.md index 86d5e89..972eb57 100644 --- a/tests/python/storage/week_02_test_report.md +++ b/tests/python/storage/week_02_test_report.md @@ -2,7 +2,7 @@ > Think of this report as the Week 2 checklist: what works, what is still waiting, and exactly what to fix. -**Generated:** 2026-07-03T05:47:06+00:00 +**Generated:** 2026-07-05T20:27:50+00:00 ## Where We Are @@ -12,7 +12,7 @@ The shared base works. The remaining checks are waiting for the four fellow-owne | Passed | Waiting | Failed | Errors | |---:|---:|---:|---:| -| 4 | 19 | 0 | 0 | +| 7 | 16 | 0 | 0 | ### What the labels mean @@ -33,14 +33,14 @@ The shared base works. The remaining checks are waiting for the four fellow-owne - **PASS:** Schema contains the shared columns and indexes - All assertions passed. (`test_schema_contains_the_shared_columns_and_indexes`) - **PASS:** Shared validation helpers - All assertions passed. (`test_shared_validation_helpers`) -### Fellow 1 - Create context - WAITING +### Fellow 1 - Create context - PASS - **File:** `src/python/local_first_ai/storage/create_context.py` -- **Status:** File not added. +- **Status:** All available asserted cases passed. -- **WAITING:** Create rejects empty title and content - Not active yet. (`test_create_rejects_empty_title_and_content`) -- **WAITING:** Create rejects invalid context type - Not active yet. (`test_create_rejects_invalid_context_type`) -- **WAITING:** Create returns unique IDs and stores complete items - Not active yet. (`test_create_returns_unique_ids_and_stores_complete_items`) +- **PASS:** Create rejects empty title and content - All assertions passed. (`test_create_rejects_empty_title_and_content`) +- **PASS:** Create rejects invalid context type - All assertions passed. (`test_create_rejects_invalid_context_type`) +- **PASS:** Create returns unique IDs and stores complete items - All assertions passed. (`test_create_returns_unique_ids_and_stores_complete_items`) ### Fellow 2 - Read context - WAITING @@ -90,7 +90,6 @@ No implemented test case is failing right now. These are the next pieces to build. They are not broken tests: -- **Fellow 1 - Create context:** `src/python/local_first_ai/storage/create_context.py` - file not added. - **Fellow 2 - Read context:** `src/python/local_first_ai/storage/read_context.py` - file not added. - **Fellow 3 - Search context:** `src/python/local_first_ai/storage/search_context.py` - file not added. - **Fellow 4 - Manage context:** `src/python/local_first_ai/storage/manage_context.py` - file not added.