soma.cell

Task Tracker

A project task tracker with priorities and assignment.

Example 085 of the basic Soma programs: a small, commented program that teaches one thing. Every output below was printed by soma 3.2.4 when this page was built.

How it is built

The cell TaskTracker keeps 2 memory slots: tasks (Map<String, String>, persistent and consistent) and meta (Map<String, Int>, persistent and consistent). Handlers: create (line 25), list_all (line 39) and demo (line 48).

Generated from soma describe on this file.

The source

085_task_tracker.cell

// ============================================================================
// 085 — Task Tracker
// ============================================================================
// A project task tracker with priorities and assignment.
//
// Run:   soma run 085_task_tracker.cell demo
// Expect:
//   Created: Setup CI/CD (high)
//   Created: Write docs (low)
//   Created: Fix auth bug (critical)
//   Created: Add tests (medium)
//   === Tasks by Priority ===
//   critical: 1 task(s)
//   high: 1 task(s)
//   medium: 1 task(s)
//   low: 1 task(s)

cell TaskTracker {

    memory {
        tasks: Map<String, String> [persistent, consistent]
        meta: Map<String, Int> [persistent, consistent]
    }

    on create(title: String, priority: String, assignee: String) {
        let current = meta.get("next_id")
        if current == () {
            meta.set("next_id", 1)
        }
        let id = meta.get("next_id")
        meta.set("next_id", id + 1)
        let id_str = to_string(id)

        let task = map("id", id, "title", title, "priority", priority, "assignee", assignee, "status", "open")
        tasks.set(id_str, to_json(task))
        return task
    }

    on list_all() {
        let keys = tasks.keys()
        let result = list()
        for key in keys {
            result = list(result, from_json(tasks.get(key)))
        }
        return result
    }

    on demo() {
        let t1 = create("Setup CI/CD", "high", "Alice")
        print("Created: {t1.title} ({t1.priority})")

        let t2 = create("Write docs", "low", "Bob")
        print("Created: {t2.title} ({t2.priority})")

        let t3 = create("Fix auth bug", "critical", "Alice")
        print("Created: {t3.title} ({t3.priority})")

        let t4 = create("Add tests", "medium", "Carol")
        print("Created: {t4.title} ({t4.priority})")

        // Group by priority
        let all = list_all()
        let by_priority = all |> agg("priority", "title:count")

        print("=== Tasks by Priority ===")
        let priorities = list("critical", "high", "medium", "low")
        for p in priorities {
            let count = count_by(all, "priority", p)
            print("{p}: {count} task(s)")
        }

        return "done"
    }
}

What the toolchain says

$ soma check 085_task_tracker.cell
✓ All checks passed.
$ soma run 085_task_tracker.cell demo
Created: Setup CI/CD (high)
Created: Write docs (low)
Created: Fix auth bug (critical)
Created: Add tests (medium)
=== Tasks by Priority ===
critical: 1 task(s)
high: 1 task(s)
medium: 1 task(s)
low: 1 task(s)
done