| name | db-upsert |
| description | Create a new document or update an existing one. If the topic already exists, updates the document. If it's new, creates the document and adds it to the index. Use this when the user wants to store or update information. |
Upsert Document
Create a new document or update an existing one in the database.
Use TaskCreate to create a task for each step below, then execute them in order. Mark each task in_progress when starting and completed when done using TaskUpdate.
Step 1: Verify Database
Use the Skill tool to invoke the db-verify skill.
If verification fails:
- Use the Skill tool to invoke
db-init to initialize the database
- Then proceed to the next step
Step 2: Determine Topic and Content
Analyze the user's input to determine:
- Topic: A short, lowercase, hyphenated name for the document (e.g., "pets", "favorite-movies", "work-contacts")
- Content: The information to store
If the topic or content is unclear, ask the user for clarification before proceeding.
Step 3: Check If Document Exists
Use the Read tool to read database/index.md.
Search the index for an existing entry matching the topic.
Note whether this is an INSERT (new document) or UPDATE (existing document).
Step 4: Write Document
Construct the document content as markdown:
# [Topic Title]
[Content organized in a clear, readable format]
---
*Last updated: [current date]*
If INSERT (new document):
Use the Write tool to create database/<topic>.md with the content.
If UPDATE (existing document):
Use the Read tool to read the existing document first.
Merge the new information with existing content appropriately.
Use the Write tool to update database/<topic>.md with the merged content.
Step 5: Update Index
If INSERT (new document):
Use the Read tool to read database/index.md.
Use the Edit tool to update the index:
- If the index contains "No documents yet.", remove that line
- Add a new entry in the Documents section:
- [Topic](topic.md) - Brief description
If UPDATE:
The index entry already exists. Check if the description needs updating.
If so, use the Edit tool to update the description.
Step 6: Verify and Report
Use the Read tool to verify:
- The document exists at
database/<topic>.md
- The index contains an entry for the document
Report to the user:
- What was created/updated
- The topic name for future reference
Example: "Stored your pet information in 'pets'. You can ask me about your pets anytime."