console: a rake task with the store open
Assisted-by: GLM-5.3 via pi
diff --git a/AGENTS.md b/AGENTS.md
index 3b7d92d..7663869 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -24,6 +24,8 @@ rake db:dump # Write the cards, birthdays, and groups to data/dump
rake dev # Dev server, seeded from test/fixtures/cards into a
# throwaway tmpdir on every start, reloading on change
# (needs fd and entr)
+rake console # irb with the store open on the configured database
+ # (console.rb loads it; the operations no screen has)
rake import:macos:plan # Plan importing this Mac's iCloud contacts
# (LIMIT=n; reads Contacts, so leave it to the user)
rake import:macos:remove # Delete from this Mac the contacts the oldest
diff --git a/console.rb b/console.rb
new file mode 100644
index 0000000..46421d2
--- /dev/null
+++ b/console.rb
@@ -0,0 +1,13 @@
+# What a `rake console` session loads: the app's store half and one
+# already open on the configured database, so the session starts ready
+# for the operations no screen has — `store.contacts`,
+# `store.delete(id)`, `store.delete_group(id)`. PRO_TACTS_DATABASE
+# points it at another database, the same way the tasks under tasks/
+# are pointed. A method rather than a local because a required file
+# cannot set the session's own.
+require "pro_tacts"
+require "pro_tacts/store"
+
+def store
+ @store ||= ProTacts::Store.at(ProTacts.config.database_path)
+end
diff --git a/tasks/console.rake b/tasks/console.rake
new file mode 100644
index 0000000..96a3342
--- /dev/null
+++ b/tasks/console.rake
@@ -0,0 +1,9 @@
+# For the operations no screen has: deleting a contact outright,
+# dissolving a group. The session loads console.rb at the root, which
+# opens the store; exec rather than sh, so the console is the process
+# the terminal talks to and Ctrl-D ends it rather than a rake around
+# it.
+desc "Open an irb console on the configured database (console.rb loads it)"
+task :console do
+ exec "bundle", "exec", "irb", "-I", "lib", "-r", "./console"
+end