Otter
Recipes
Otter
Upstream Recipe Tested
Personal Task Manager Application Recipe
Complete CLI task tracking application with persistent JSON storage and formatted listings.
Architecture & Runtime Preview
Otter >=1.0.1The recipe combines `otter-official/file-helpers` for JSON persistence with `otter-official/text-utils` for padded column formatting. State is represented as a list of Task objects, serialized to disk on mutation.
- 1init-storage: Initialize file persistence layer and read existing tasks JSON file (otter-official/file-helpers)
- 2format-display: Format table rows with text padding and alignment (otter-official/text-utils)
Source Code (4 files)
{
"schemaVersion": 1,
"id": "otter-official/task-tracker",
"version": "1.0.0",
"title": "Personal Task Manager Application",
"summary": "Complete CLI task tracking application with persistent JSON storage and formatted listings.",
"target": "console",
"requiresOtter": ">=1.0.1",
"capabilities": ["files"],
"packs": [
{ "id": "otter-official/file-helpers", "version": "1.0.1" },
{ "id": "otter-official/text-utils", "version": "1.0.1" }
],
"blueprints": [
{ "id": "otter-official/file-settings", "version": "1.0.0" }
],
"configuration": [
{ "id": "appName", "title": "Application Name", "type": "text", "default": "My Tasks", "description": "Title shown on CLI header" },
{ "id": "maxTasks", "title": "Maximum Tasks", "type": "number", "default": 50, "description": "Maximum number of active tasks allowed" }
],
"steps": [
{
"id": "init-storage",
"kind": "pack-call",
"description": "Initialize file persistence layer and read existing tasks JSON file",
"source": "otter-official/file-helpers",
"inputs": [{ "name": "path", "type": "text" }],
"outputs": [{ "name": "tasks", "type": "list" }]
},
{
"id": "format-display",
"kind": "pack-call",
"description": "Format table rows with text padding and alignment",
"source": "otter-official/text-utils",
"inputs": [{ "name": "rawText", "type": "text" }],
"outputs": [{ "name": "formattedText", "type": "text" }]
}
],
"generatedFiles": [
{ "path": "src/tasks.ot", "template": "templates/tasks.ot.tmpl" }
],
"tests": [
"tests/test.ot"
],
"explanations": {
"beginner": "This application lets you track your daily to-do tasks from the command line. When you add a task, it gets saved to a file on your disk so it stays there even after you close the program.",
"intermediate": "The recipe combines `otter-official/file-helpers` for JSON persistence with `otter-official/text-utils` for padded column formatting. State is represented as a list of Task objects, serialized to disk on mutation.",
"advanced": "Implements an ACID-like file save pattern using `writeSafe`. Tasks are held in an in-memory list of typed objects and persisted as JSON. Column formatting uses deterministic spacing."
}
}
# ==============================================================================
# Generated by Otter Application Recipe: task-tracker 1.0.0
# Target: Console Task Manager Application with Persistent Storage
# ==============================================================================
use "${import:otter-official/file-helpers}"
use "${import:otter-official/text-utils}"
a TaskItem has
id
title
done
.
to createTask tid title
t is a TaskItem
id of t is tid
title of t is title
done of t is "pending"
return t
.
to completeTask tasks targetId
updated are empty
for each t in tasks
tid is id of t
if tid is targetId
done of t is "completed"
.
add t to updated
.
return updated
.
to deleteTask tasks targetId
remaining are empty
for each t in tasks
tid is id of t
if tid is not targetId
add t to remaining
.
.
return remaining
.
to filterTasksByStatus tasks targetStatus
filtered are empty
for each t in tasks
s is done of t
if s is targetStatus
add t to filtered
.
.
return filtered
.
to displayTasks items headerTitle
say "=== " plus headerTitle plus " ==="
countVal is length of items
if countVal is 0
say "(No tasks found)"
return false
.
for each t in items
status is done of t
desc is title of t
tid is id of t
statusPadded is padRight status 12 " "
descPadded is padRight desc 30 " "
lineParts are
"#"
tid
": ["
statusPadded
"] "
descPadded
.
join lineParts with "" into line
say line
.
return true
.
to saveTasksToFile tasks filePath
convert tasks to json into rawJson
writeSafe filePath rawJson
return true
.
to loadTasksFromFile filePath
raw is readOrFallback filePath "[]"
loaded is a thing
convert raw from json into loaded
return loaded
.
# ------------------------------------------------------------------------------
# Application Execution
# ------------------------------------------------------------------------------
storeFile is "tasks_store.json"
tasks is loadTasksFromFile storeFile
taskCount is length of tasks
if taskCount is 0
say "Initializing default tasks for: ${config:appName}"
t1 is createTask 1 "Review project specification"
add t1 to tasks
t2 is createTask 2 "Implement composable recipes"
add t2 to tasks
t3 is createTask 3 "Verify test suite execution"
add t3 to tasks
saveTasksToFile tasks storeFile
.
displayTasks tasks "${config:appName} (All Tasks)"
# Complete second task
tasks is completeTask tasks 2
saveTasksToFile tasks storeFile
activeList is filterTasksByStatus tasks "pending"
displayTasks activeList "Active Tasks"
completedList is filterTasksByStatus tasks "completed"
displayTasks completedList "Completed Tasks"
say "Task operation complete. Total stored:"
say length of tasks
# ==============================================================================
# Test: Task Manager Application
# ==============================================================================
use "../../../../packs/otter-official/file-helpers/src/main.ot"
use "../../../../packs/otter-official/text-utils/src/main.ot"
a TaskItem has
id
title
done
.
to createTask tid title
t is a TaskItem
id of t is tid
title of t is title
done of t is "pending"
return t
.
to completeTask tasks targetId
updated are empty
for each t in tasks
tid is id of t
if tid is targetId
done of t is "completed"
.
add t to updated
.
return updated
.
to deleteTask tasks targetId
remaining are empty
for each t in tasks
tid is id of t
if tid is not targetId
add t to remaining
.
.
return remaining
.
to filterTasksByStatus tasks targetStatus
filtered are empty
for each t in tasks
s is done of t
if s is targetStatus
add t to filtered
.
.
return filtered
.
to saveTasksToFile tasks filePath
convert tasks to json into rawJson
writeSafe filePath rawJson
return true
.
to loadTasksFromFile filePath
raw is readOrFallback filePath "[]"
loaded is a thing
convert raw from json into loaded
return loaded
.
# Test 1: Task creation
task1 is createTask 101 "Write recipe unit test"
if id of task1 is not 101
say "FAIL: expected task id 101"
.
if done of task1 is not "pending"
say "FAIL: expected task status pending"
.
# Test 2: Task list and completion
taskList are empty
add task1 to taskList
task2 is createTask 102 "Implement task persistence"
add task2 to taskList
if length of taskList is not 2
say "FAIL: expected task list count 2"
.
taskList is completeTask taskList 101
activeTasks is filterTasksByStatus taskList "pending"
completedTasks is filterTasksByStatus taskList "completed"
if length of activeTasks is not 1
say "FAIL: expected 1 active task"
.
if length of completedTasks is not 1
say "FAIL: expected 1 completed task"
.
# Test 3: Task deletion
taskList is deleteTask taskList 102
if length of taskList is not 1
say "FAIL: expected 1 task after deletion"
.
# Test 4: Persistence across restart
testStore is "test_tasks_store.json"
saveTasksToFile taskList testStore
loadedList is loadTasksFromFile testStore
if length of loadedList is not 1
say "FAIL: expected 1 task loaded from disk"
.
writeSafe testStore ""
say "Task-tracker tests passed."
# ==============================================================================
# Demo: Task Manager Application
# ==============================================================================
use "../../../../packs/otter-official/file-helpers/src/main.ot"
use "../../../../packs/otter-official/text-utils/src/main.ot"
a TaskItem has
id
title
done
.
to createTask tid title
t is a TaskItem
id of t is tid
title of t is title
done of t is "pending"
return t
.
to completeTask tasks targetId
updated are empty
for each t in tasks
tid is id of t
if tid is targetId
done of t is "completed"
.
add t to updated
.
return updated
.
to deleteTask tasks targetId
remaining are empty
for each t in tasks
tid is id of t
if tid is not targetId
add t to remaining
.
.
return remaining
.
to filterTasksByStatus tasks targetStatus
filtered are empty
for each t in tasks
s is done of t
if s is targetStatus
add t to filtered
.
.
return filtered
.
to displayTasks items headerTitle
say "=== " plus headerTitle plus " ==="
countVal is length of items
if countVal is 0
say "(No tasks found)"
return false
.
for each t in items
status is done of t
desc is title of t
tid is id of t
statusPadded is padRight status 12 " "
descPadded is padRight desc 30 " "
lineParts are
"#"
tid
": ["
statusPadded
"] "
descPadded
.
join lineParts with "" into line
say line
.
return true
.
# 1. Initialize task collection
tasks are empty
t1 is createTask 1 "Review project specification"
add t1 to tasks
t2 is createTask 2 "Implement composable recipes"
add t2 to tasks
t3 is createTask 3 "Verify test suite execution"
add t3 to tasks
displayTasks tasks "Initial Tasks"
# 2. Mark task 2 completed
tasks is completeTask tasks 2
# 3. Filter and display
activeList is filterTasksByStatus tasks "pending"
displayTasks activeList "Active Tasks"
completedList is filterTasksByStatus tasks "completed"
displayTasks completedList "Completed Tasks"
# 4. Delete task 1
tasks is deleteTask tasks 1
displayTasks tasks "After Deleting Task #1"
say "Task-tracker demo finished successfully."
Installation & Usage
otter recipe inspect otter-official/task-tracker
otter recipe apply otter-official/task-tracker --project ./my-app
This application lets you track your daily to-do tasks from the command line. When you add a task, it gets saved to a file on your disk so it stays there even after you close the program.