omnifocus_mcp 1.0.1 → 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -1
  3. data/README.md +17 -13
  4. data/bin/omnifocus-mcp +0 -1
  5. data/docs/superpowers/plans/2026-11-17-server-gap-fixes.md +192 -0
  6. data/lib/omnifocus_mcp/infrastructure/apple_script.rb +83 -19
  7. data/lib/omnifocus_mcp/infrastructure/script_runner.rb +6 -8
  8. data/lib/omnifocus_mcp/json_rpc_compat.rb +1 -2
  9. data/lib/omnifocus_mcp/logger.rb +1 -0
  10. data/lib/omnifocus_mcp/resources/base.rb +2 -37
  11. data/lib/omnifocus_mcp/resources/stats_resource.rb +1 -1
  12. data/lib/omnifocus_mcp/tools/database_stats.rb +3 -157
  13. data/lib/omnifocus_mcp/tools/definitions/{add_omnifocus_task_tool.rb → add_omni_focus_task_tool.rb} +8 -4
  14. data/lib/omnifocus_mcp/tools/definitions/add_project_tool.rb +4 -1
  15. data/lib/omnifocus_mcp/tools/definitions/batch_add_items_tool.rb +5 -3
  16. data/lib/omnifocus_mcp/tools/definitions/date_formatter.rb +8 -7
  17. data/lib/omnifocus_mcp/tools/definitions/edit_item_tool.rb +25 -6
  18. data/lib/omnifocus_mcp/tools/definitions/key_normalizer.rb +21 -1
  19. data/lib/omnifocus_mcp/tools/definitions/query_omnifocus_tool.rb +1 -2
  20. data/lib/omnifocus_mcp/tools/generators/{add_omnifocus_task.rb → add_omni_focus_task.rb} +8 -13
  21. data/lib/omnifocus_mcp/tools/generators/add_project.rb +4 -6
  22. data/lib/omnifocus_mcp/tools/generators/database_stats.rb +133 -3
  23. data/lib/omnifocus_mcp/tools/generators/edit_item.rb +39 -56
  24. data/lib/omnifocus_mcp/tools/generators/note_edit.rb +108 -0
  25. data/lib/omnifocus_mcp/tools/generators/query_omnifocus.rb +32 -26
  26. data/lib/omnifocus_mcp/tools/generators/remove_item.rb +1 -1
  27. data/lib/omnifocus_mcp/tools/messages/{add_omnifocus_task.rb → add_omni_focus_task.rb} +5 -3
  28. data/lib/omnifocus_mcp/tools/operations/{add_omnifocus_task.rb → add_omni_focus_task.rb} +6 -4
  29. data/lib/omnifocus_mcp/tools/operations/add_project.rb +3 -3
  30. data/lib/omnifocus_mcp/tools/operations/batch_add_items/bulk_executor.rb +2 -2
  31. data/lib/omnifocus_mcp/tools/operations/batch_add_items/planner.rb +1 -0
  32. data/lib/omnifocus_mcp/tools/operations/batch_add_items.rb +6 -4
  33. data/lib/omnifocus_mcp/tools/operations/batch_remove_items.rb +4 -2
  34. data/lib/omnifocus_mcp/tools/operations/database_stats.rb +3 -3
  35. data/lib/omnifocus_mcp/tools/operations/edit_item.rb +3 -3
  36. data/lib/omnifocus_mcp/tools/operations/list_perspectives.rb +1 -1
  37. data/lib/omnifocus_mcp/tools/operations/remove_item.rb +3 -3
  38. data/lib/omnifocus_mcp/tools/params/mcp_boundary.rb +4 -2
  39. data/lib/omnifocus_mcp/tools/params.rb +2 -2
  40. data/lib/omnifocus_mcp/tools/presenters/query_results.rb +12 -6
  41. data/lib/omnifocus_mcp/utils/blank.rb +4 -0
  42. data/lib/omnifocus_mcp/utils/date_filter.rb +1 -2
  43. data/lib/omnifocus_mcp/version.rb +1 -1
  44. data/lib/omnifocus_mcp.rb +6 -7
  45. metadata +8 -10
  46. data/lib/omnifocus_mcp/tools/batch_report.rb +0 -9
  47. data/lib/omnifocus_mcp/tools/generators/.keep +0 -1
  48. data/lib/omnifocus_mcp/tools/query_omnifocus_formatter.rb +0 -9
  49. data/lib/omnifocus_mcp/utils/date_formatting.rb +0 -9
@@ -7,6 +7,7 @@ require_relative "../../utils/blank"
7
7
  require_relative "../../result"
8
8
  require_relative "../../infrastructure/script_runner"
9
9
  require_relative "../params"
10
+ require_relative "note_edit"
10
11
 
11
12
  module OmnifocusMcp
12
13
  module Tools
@@ -39,16 +40,15 @@ module OmnifocusMcp
39
40
  # Generate pure AppleScript for item editing. Dates are constructed
40
41
  # outside the `tell` block then referenced from within.
41
42
  class << self
43
+ # rubocop:disable-next Metrics/AbcSize
42
44
  def generate_apple_script(params)
43
45
  params = Params::McpBoundary.coerce(Params::EditItemParams, params)
44
46
  return missing_identifier_error if Utils::Blank.blank?(params.id, params.name)
45
47
 
46
- id = Infrastructure::AppleScript.escape(params.id.to_s)
47
48
  name = Infrastructure::AppleScript.escape(params.name.to_s)
48
49
  item_type = params.item_type.to_s
49
-
50
+ id = Infrastructure::AppleScript.escape(params.id.to_s)
50
51
  date_pre_scripts, date_assignments = collect_date_assignments(params)
51
-
52
52
  [
53
53
  date_pre_scripts.join("\n\n"),
54
54
  Infrastructure::AppleScript.tell_document(document_body(item_type, id, name, params, date_assignments))
@@ -67,7 +67,7 @@ module OmnifocusMcp
67
67
  def run_script(script)
68
68
  stdout, stderr, status = Infrastructure::ScriptRunner.execute_applescript(script)
69
69
 
70
- OmnifocusMcp.logger.warn("[edit_item] AppleScript stderr: #{stderr}") if stderr && !stderr.empty?
70
+ OmnifocusMcp.logger.warn("[edit_item] AppleScript stderr: #{stderr}") if Utils::Blank.present?(stderr)
71
71
  return OmnifocusMcp::Result.error(applescript_run_failure(stderr:, status:)) unless status.success?
72
72
 
73
73
  parse_result(stdout)
@@ -88,7 +88,7 @@ module OmnifocusMcp
88
88
  def applescript_run_failure(stderr:, status:)
89
89
  exit_code = status.respond_to?(:exitstatus) ? status.exitstatus : status
90
90
  message = "osascript failed (exit #{exit_code})"
91
- message += ": #{stderr.strip}" unless stderr.nil? || stderr.empty?
91
+ message += ": #{stderr.strip}" unless Utils::Blank.blank?(stderr)
92
92
  message
93
93
  end
94
94
 
@@ -139,16 +139,18 @@ module OmnifocusMcp
139
139
  "set itemId to id of foundItem as string",
140
140
  "set changedProperties to {}"
141
141
  ]
142
+ steps << NoteEdit.guard_step(params)
142
143
  steps.concat(property_update_steps(item_type, params, date_assignments).compact)
143
144
  steps << finalize_and_return
144
145
 
145
- steps.join("\n\n")
146
+ steps.compact.join("\n\n")
146
147
  end
147
148
 
148
149
  def property_update_steps(item_type, params, date_assignments)
149
150
  [
150
151
  update_string_property("name", params, :new_name),
151
- update_string_property("note", params, :new_note),
152
+ update_string_property("note", params, :new_note, escaper: :multiline_string),
153
+ NoteEdit.apply_step(params),
152
154
  update_date_step("due date", date_assignments["due date"]),
153
155
  update_date_step("defer date", date_assignments["defer date"]),
154
156
  update_date_step("planned date", date_assignments["planned date"]),
@@ -178,10 +180,10 @@ module OmnifocusMcp
178
180
  end
179
181
 
180
182
  # `set foo of foundItem to "escaped string"` + changedProperties bump.
181
- def update_string_property(label, params, key)
183
+ def update_string_property(label, params, key, escaper: :escape)
182
184
  return nil unless param_provided?(params, key)
183
185
 
184
- value = Infrastructure::AppleScript.escape(params.public_send(key).to_s)
186
+ value = Infrastructure::AppleScript.public_send(escaper, params.public_send(key).to_s)
185
187
  <<~APPLESCRIPT.chomp
186
188
  -- Update #{label}
187
189
  set #{label} of foundItem to "#{value}"
@@ -223,7 +225,7 @@ module OmnifocusMcp
223
225
  end repeat
224
226
 
225
227
  -- Return success with details
226
- return "{\\"success\\":true,\\"id\\":\\"" & itemId & "\\",\\"name\\":\\"" & itemName & "\\",\\"changedProperties\\":\\"" & changedPropsText & "\\"}"
228
+ return "{\\"success\\":true,\\"id\\":\\"" & itemId & "\\",\\"name\\":\\"" & my jsonEscape(itemName) & "\\",\\"changedProperties\\":\\"" & changedPropsText & "\\"}"
227
229
  APPLESCRIPT
228
230
  end
229
231
 
@@ -231,10 +233,14 @@ module OmnifocusMcp
231
233
  return nil unless param_provided?(params, :new_status)
232
234
 
233
235
  case params.new_status.to_s
234
- when "completed" then task_status_completed
235
- when "dropped" then task_status_dropped
236
- when "skipped" then task_status_skipped
237
- when "incomplete" then task_status_incomplete
236
+ when "completed"
237
+ task_status_completed
238
+ when "dropped"
239
+ task_status_dropped
240
+ when "skipped"
241
+ task_status_skipped
242
+ when "incomplete"
243
+ task_status_incomplete
238
244
  end
239
245
  end
240
246
 
@@ -300,73 +306,50 @@ module OmnifocusMcp
300
306
 
301
307
  def non_empty?(value) = value && !value.empty?
302
308
 
303
- # rubocop:disable Metrics/MethodLength
304
309
  def tag_replace_block(tags)
305
- tags_list = tags.map { |t| %("#{Infrastructure::AppleScript.escape(t.to_s)}") }.join(", ")
306
310
  <<~APPLESCRIPT.chomp
307
- -- Replace all tags
308
- set tagNames to {#{tags_list}}
311
+ -- Replace all tags: first clear the existing ones
309
312
  set existingTags to tags of foundItem
310
-
311
- -- First clear all existing tags
312
313
  repeat with existingTag in existingTags
313
314
  remove existingTag from tags of foundItem
314
315
  end repeat
315
316
 
316
- -- Then add new tags
317
- repeat with tagName in tagNames
318
- set tagObj to missing value
319
- try
320
- set tagObj to first flattened tag where name = (tagName as string)
321
- on error
322
- -- Tag doesn't exist, create it
323
- set tagObj to make new tag with properties {name:(tagName as string)}
324
- end try
325
- if tagObj is not missing value then
326
- add tagObj to tags of foundItem
327
- end if
328
- end repeat
317
+ #{add_tag_lines(tags)}
329
318
  set end of changedProperties to "tags (replaced)"
330
319
  APPLESCRIPT
331
320
  end
332
- # rubocop:enable Metrics/MethodLength
333
321
 
334
322
  def tag_add_block(tags)
335
- tags_list = tags.map { |t| %("#{Infrastructure::AppleScript.escape(t.to_s)}") }.join(", ")
336
323
  <<~APPLESCRIPT.chomp
337
324
  -- Add tags
338
- set tagNames to {#{tags_list}}
339
- repeat with tagName in tagNames
340
- set tagObj to missing value
341
- try
342
- set tagObj to first flattened tag where name = (tagName as string)
343
- on error
344
- -- Tag doesn't exist, create it
345
- set tagObj to make new tag with properties {name:(tagName as string)}
346
- end try
347
- if tagObj is not missing value then
348
- add tagObj to tags of foundItem
349
- end if
350
- end repeat
325
+ #{add_tag_lines(tags)}
351
326
  set end of changedProperties to "tags (added)"
352
327
  APPLESCRIPT
353
328
  end
354
329
 
355
330
  def tag_remove_block(tags)
356
- tags_list = tags.map { |t| %("#{Infrastructure::AppleScript.escape(t.to_s)}") }.join(", ")
357
- <<~APPLESCRIPT.chomp
358
- -- Remove tags
359
- set tagNames to {#{tags_list}}
360
- repeat with tagName in tagNames
331
+ removals = tags.map do |tag|
332
+ lookup = Infrastructure::AppleScript.tag_lookup(var: "theTag", tag_path: tag.to_s, create: false)
333
+ <<~APPLESCRIPT.chomp
361
334
  try
362
- set tagObj to first flattened tag where name = (tagName as string)
363
- remove tagObj from tags of foundItem
335
+ #{Infrastructure::AppleScript.indent(text: lookup, prefix: " ")}
336
+ if theTag is not missing value then remove theTag from tags of foundItem
364
337
  end try
365
- end repeat
338
+ APPLESCRIPT
339
+ end
340
+
341
+ <<~APPLESCRIPT.chomp
342
+ -- Remove tags
343
+ #{removals.join("\n")}
366
344
  set end of changedProperties to "tags (removed)"
367
345
  APPLESCRIPT
368
346
  end
369
347
 
348
+ def add_tag_lines(tags)
349
+ tags.map { |tag| Infrastructure::AppleScript.tag_assignment(item_var: "foundItem", tag_path: tag.to_s) }
350
+ .join("\n")
351
+ end
352
+
370
353
  def apply_new_project_name(params)
371
354
  return nil unless param_provided?(params, :new_project_name)
372
355
 
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ require_relative "../../infrastructure/apple_script"
6
+
7
+ module OmnifocusMcp
8
+ module Tools
9
+ module Generators
10
+ # AppleScript steps for `edit_item`'s `noteReplacements` and `appendNote`.
11
+ #
12
+ # Both edit the note's rich text through Omni Automation (`noteText`),
13
+ # so links, attachments and styles outside the changed text survive.
14
+ # Setting `note of foundItem` from AppleScript would flatten the note.
15
+ module NoteEdit
16
+ # Called as (itemId, mode, startText, replacements, appendText).
17
+ # mode "check" returns "" or an error; mode "apply" edits the note.
18
+ # `startText` is the newNote value when one is set in the same call.
19
+ SCRIPT = <<~'JS'.lines.map(&:strip).join(" ")
20
+ ((id, mode, start, reps, append) => {
21
+ const project = Project.byIdentifier(id);
22
+ const item = Task.byIdentifier(id) || (project ? project.task : null);
23
+ if (!item) return "Item not found";
24
+ if (mode === "check") {
25
+ let s = start === null ? item.noteText.string : start;
26
+ for (const r of reps) {
27
+ if (!s.includes(r.find)) return "Note text not found: " + r.find;
28
+ s = s.split(r.find).join(r.replace);
29
+ }
30
+ return "";
31
+ }
32
+ const text = item.noteText;
33
+ const mark = "";
34
+ const swap = (from, to, times) => {
35
+ for (let i = 0; i < times; i++) {
36
+ const range = text.find(from, null, null);
37
+ if (!range) break;
38
+ text.replace(range, new Text(to, text.style));
39
+ }
40
+ };
41
+ for (const r of reps) {
42
+ const count = text.string.split(r.find).length - 1;
43
+ swap(r.find, mark, count);
44
+ swap(mark, r.replace, count);
45
+ }
46
+ if (append !== null) {
47
+ text.append(new Text((text.string.length > 0 ? "\n" : "") + append, text.style));
48
+ }
49
+ return "";
50
+ })
51
+ JS
52
+ private_constant :SCRIPT
53
+
54
+ class << self
55
+ # Fails the edit before anything changes when a `find` is missing.
56
+ def guard_step(params)
57
+ return nil if replacements(params).empty?
58
+
59
+ <<~APPLESCRIPT.chomp
60
+ -- Check every note replacement can apply before changing anything
61
+ #{evaluate("noteCheck", params, mode: "check")}
62
+ if noteCheck is not "" then
63
+ return "{\\"success\\":false,\\"error\\":\\"" & my jsonEscape(noteCheck) & "\\"}"
64
+ end if
65
+ APPLESCRIPT
66
+ end
67
+
68
+ # Applies replacements, then the append, after any newNote.
69
+ def apply_step(params)
70
+ changes = []
71
+ changes << "note (replaced text)" unless replacements(params).empty?
72
+ changes << "note (appended)" unless params.append_note.nil?
73
+ return nil if changes.empty?
74
+
75
+ labels = changes.map { |label| %(set end of changedProperties to "#{label}") }
76
+ <<~APPLESCRIPT.chomp
77
+ -- Edit the note's rich text in place
78
+ #{evaluate("noteEdit", params, mode: "apply")}
79
+ #{labels.join("\n")}
80
+ APPLESCRIPT
81
+ end
82
+
83
+ private
84
+
85
+ def replacements(params) = Array(params.note_replacements)
86
+
87
+ # `set <var> to evaluate javascript (...)`, with the item id spliced
88
+ # in from the AppleScript variable `itemId`.
89
+ def evaluate(var, params, mode:)
90
+ prefix = Infrastructure::AppleScript.escape(%[#{SCRIPT}(])
91
+ suffix = Infrastructure::AppleScript.escape(%[, #{js_args(params, mode).join(", ")})])
92
+ %(tell application "OmniFocus" to set #{var} to evaluate javascript ) +
93
+ %{("#{prefix}" & quote & itemId & quote & "#{suffix}")}
94
+ end
95
+
96
+ def js_args(params, mode)
97
+ pairs = replacements(params).map { |r| { find: normalize(r[:find]), replace: normalize(r[:replace]) } }
98
+ [
99
+ mode, normalize(params.new_note), pairs, normalize(params.append_note)
100
+ ].map { |arg| JSON.generate(arg) }
101
+ end
102
+
103
+ def normalize(value) = value&.to_s&.gsub(/\r\n?/, "\n")
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -59,6 +59,7 @@ module OmnifocusMcp
59
59
  # JSON.parse hands us String keys; pattern matching wants Symbols. A
60
60
  # non-Hash response (e.g. raw stdout from a parse failure) becomes
61
61
  # +nil+ here so the +in nil+ arm can surface it as an error.
62
+ # rubocop:disable-next Metrics/CyclomaticComplexity
62
63
  def classify_response(response:, summary:)
63
64
  shape = response.is_a?(Hash) ? response.transform_keys(&:to_sym) : nil
64
65
 
@@ -82,27 +83,27 @@ module OmnifocusMcp
82
83
  def build_match(items:, count:, summary:) = Match.new(items: summary ? nil : items, count: count)
83
84
 
84
85
  # Build the full JXA query script for the given params.
86
+ # rubocop:disable-next Metrics/AbcSize
85
87
  def generate_query_script(params)
86
88
  params = Params::McpBoundary.coerce(Params::QueryOmnifocusParams, params)
89
+
87
90
  entity = params.entity.to_s
88
- filters = params.filters || {}
89
- fields = params.fields
90
- limit = params.limit
91
- sort_by = params.sort_by
92
- sort_order = params.sort_order
93
- include_completed = params.include_completed == true
94
- summary = params.summary == true
95
91
 
92
+ filters = params.filters || {}
96
93
  filter_conditions = generate_filter_conditions(entity:, filters:)
97
- field_mapping = generate_field_mapping(entity, fields:)
98
- sort_property = resolve_sort_field(sort_by)
99
- sort_logic = sort_property ? generate_sort_logic(sort_property, sort_order:) : ""
94
+
95
+ field_mapping = generate_field_mapping(entity:, fields: params.fields)
96
+
97
+ sort_property = resolve_sort_field(params.sort_by)
98
+ sort_logic = sort_property ? generate_sort_logic(sort_property, sort_order: params.sort_order) : ""
99
+
100
+ limit = params.limit
100
101
  limit_logic = limit.is_a?(Integer) && limit.positive? ? "filtered = filtered.slice(0, #{limit});" : ""
101
102
 
102
103
  build_query_script(
103
104
  entity: entity,
104
- include_completed: include_completed,
105
- summary: summary,
105
+ include_completed: params.include_completed == true,
106
+ summary: params.summary == true,
106
107
  filter_conditions: filter_conditions,
107
108
  field_mapping: field_mapping,
108
109
  sort_logic: sort_logic,
@@ -159,7 +160,7 @@ module OmnifocusMcp
159
160
  # Build the per-item field-projection block. With no `fields` array
160
161
  # (nil or empty), returns the default field set for the entity.
161
162
  # Otherwise builds explicit mappings for each requested field.
162
- def generate_field_mapping(entity, fields: nil)
163
+ def generate_field_mapping(entity:, fields: nil)
163
164
  if fields.nil? || fields.empty?
164
165
  return default_task_mapping if entity == "tasks"
165
166
  return default_project_mapping if entity == "projects"
@@ -197,7 +198,7 @@ module OmnifocusMcp
197
198
  JS
198
199
  end
199
200
 
200
- # rubocop:disable Metrics/MethodLength
201
+ # rubocop:disable-next Metrics/MethodLength
201
202
  def apply_task_id_filters(filters:, conditions:)
202
203
  if filters[:project_id]
203
204
  safe_id = escape_jxa(filters[:project_id])
@@ -229,15 +230,9 @@ module OmnifocusMcp
229
230
  }
230
231
  JS
231
232
  end
232
- # rubocop:enable Metrics/MethodLength
233
233
 
234
234
  def apply_tag_status_filters(filters:, conditions:, entity:)
235
- if entity == "tasks" && filters[:tags] && !filters[:tags].empty?
236
- tag_condition = filters[:tags].map do |tag|
237
- %(item.tags.some(t => t.name === "#{escape_jxa(tag)}"))
238
- end.join(" || ")
239
- conditions << "if (!(#{tag_condition})) return false;"
240
- end
235
+ conditions << tag_filter_condition(filters[:tags]) if filtering_tasks_by_tags?(filters:, entity:)
241
236
 
242
237
  return unless filters[:status] && !filters[:status].empty?
243
238
 
@@ -250,6 +245,18 @@ module OmnifocusMcp
250
245
  conditions << "if (!(#{status_condition})) return false;"
251
246
  end
252
247
 
248
+ def filtering_tasks_by_tags?(filters:, entity:)
249
+ entity == "tasks" && filters[:tags] && !filters[:tags].empty?
250
+ end
251
+
252
+ def tag_filter_condition(tags)
253
+ tag_condition = tags.map do |tag|
254
+ %(item.tags.some(t => t.name === "#{escape_jxa(tag)}"))
255
+ end.join(" || ")
256
+ "if (!(#{tag_condition})) return false;"
257
+ end
258
+
259
+ # rubocop:disable-next Metrics/AbcSize
253
260
  def apply_task_date_filters(filters:, conditions:)
254
261
  conditions << "if (item.flagged !== #{filters[:flagged]}) return false;" unless filters[:flagged].nil?
255
262
 
@@ -260,12 +267,11 @@ module OmnifocusMcp
260
267
  push_same_day(conditions:, field: "dueDate", value: filters[:due_on])
261
268
  push_same_day(conditions:, field: "deferDate", value: filters[:defer_on])
262
269
  push_same_day(conditions:, field: "plannedDate", value: filters[:planned_on])
263
-
264
- push_within_past(conditions:, field: "added", value: filters[:added_within])
265
270
  push_same_day(conditions:, field: "added", value: filters[:added_on])
271
+ push_same_day(conditions:, field: "completionDate", value: filters[:completed_on])
266
272
 
273
+ push_within_past(conditions:, field: "added", value: filters[:added_within])
267
274
  push_within_past(conditions:, field: "completionDate", value: filters[:completed_within])
268
- push_same_day(conditions:, field: "completionDate", value: filters[:completed_on])
269
275
  end
270
276
 
271
277
  def apply_task_misc_filters(filters:, conditions:)
@@ -279,7 +285,7 @@ module OmnifocusMcp
279
285
 
280
286
  unless filters[:has_note].nil?
281
287
  conditions << <<~JS
282
- const hasNote = item.note && item.note.trim().length > 0;
288
+ const hasNote = (item.note || "").trim().length > 0;
283
289
  if (hasNote !== #{filters[:has_note]}) return false;
284
290
  JS
285
291
  end
@@ -506,7 +512,7 @@ module OmnifocusMcp
506
512
  const entityType = "#{entity}";
507
513
 
508
514
  if (entityType === "tasks") {
509
- items = flattenedTasks;
515
+ items = flattenedTasks.filter(task => task.project === null);
510
516
  } else if (entityType === "projects") {
511
517
  items = flattenedProjects;
512
518
  } else if (entityType === "folders") {
@@ -48,7 +48,7 @@ module OmnifocusMcp
48
48
  delete foundItem
49
49
 
50
50
  -- Return success
51
- return "{\\"success\\":true,\\"id\\":\\"" & itemId & "\\",\\"name\\":\\"" & itemName & "\\"}"
51
+ return "{\\"success\\":true,\\"id\\":\\"" & itemId & "\\",\\"name\\":\\"" & my jsonEscape(itemName) & "\\"}"
52
52
  else
53
53
  return "{\\"success\\":false,\\"error\\":\\"Item not found\\"}"
54
54
  end if
@@ -27,9 +27,11 @@ module OmnifocusMcp
27
27
 
28
28
  def location_for(args, placement)
29
29
  case placement
30
- when "parent" then "under the parent task"
31
- when "project" then args[:projectName] ? %(in project "#{args[:projectName]}") : "in a project"
32
- else "in your inbox"
30
+ when "parent"
31
+ "under the parent task"
32
+ when "project"
33
+ args[:projectName] ? %(in project "#{args[:projectName]}") : "in a project"
34
+ else "in your inbox"
33
35
  end
34
36
  end
35
37
 
@@ -3,7 +3,7 @@
3
3
  require_relative "../../infrastructure/script_runner"
4
4
  require_relative "../../parsers/apple_script_envelope"
5
5
  require_relative "../../result"
6
- require_relative "../generators/add_omnifocus_task"
6
+ require_relative "../generators/add_omni_focus_task"
7
7
  require_relative "../params"
8
8
 
9
9
  module OmnifocusMcp
@@ -37,7 +37,7 @@ module OmnifocusMcp
37
37
 
38
38
  def call(params)
39
39
  params = Params::McpBoundary.coerce(Params::AddTaskParams, params)
40
- generator.generate_apple_script(params).then { |script| run_script(script) }
40
+ generator.generate_apple_script(params).then { run_script(it) }
41
41
  rescue StandardError => e
42
42
  OmnifocusMcp.logger.warn("[add_omnifocus_task] Error: #{e}")
43
43
  OmnifocusMcp::Result.error(e.message || "Unknown error in add_omnifocus_task")
@@ -50,7 +50,9 @@ module OmnifocusMcp
50
50
  def run_script(script)
51
51
  stdout, stderr, status = script_runner.execute_applescript(script)
52
52
 
53
- OmnifocusMcp.logger.warn("[add_omnifocus_task] AppleScript stderr: #{stderr}") if stderr && !stderr.empty?
53
+ if Utils::Blank.present?(stderr)
54
+ OmnifocusMcp.logger.warn("[add_omnifocus_task] AppleScript stderr: #{stderr}")
55
+ end
54
56
  return OmnifocusMcp::Result.error(applescript_run_failure(stderr:, status:)) unless status.success?
55
57
 
56
58
  parse_result(stdout)
@@ -65,7 +67,7 @@ module OmnifocusMcp
65
67
  def applescript_run_failure(stderr:, status:)
66
68
  exit_code = status.respond_to?(:exitstatus) ? status.exitstatus : status
67
69
  message = "osascript failed (exit #{exit_code})"
68
- message += ": #{stderr.strip}" unless stderr.nil? || stderr.empty?
70
+ message += ": #{stderr.strip}" unless Utils::Blank.blank?(stderr)
69
71
  message
70
72
  end
71
73
  end
@@ -38,7 +38,7 @@ module OmnifocusMcp
38
38
 
39
39
  def call(params)
40
40
  params = Params::McpBoundary.coerce(Params::AddProjectParams, params)
41
- generator.generate_apple_script(params).then { |script| run_script(script) }
41
+ generator.generate_apple_script(params).then { run_script(it) }
42
42
  rescue StandardError => e
43
43
  OmnifocusMcp.logger.warn("[add_project] Error: #{e}")
44
44
  OmnifocusMcp::Result.error(e.message || "Unknown error in add_project")
@@ -51,7 +51,7 @@ module OmnifocusMcp
51
51
  def run_script(script)
52
52
  stdout, stderr, status = script_runner.execute_applescript(script)
53
53
 
54
- OmnifocusMcp.logger.warn("[add_project] AppleScript stderr: #{stderr}") if stderr && !stderr.empty?
54
+ OmnifocusMcp.logger.warn("[add_project] AppleScript stderr: #{stderr}") if Utils::Blank.present?(stderr)
55
55
  return OmnifocusMcp::Result.error(applescript_run_failure(stderr:, status:)) unless status.success?
56
56
 
57
57
  parse_result(stdout)
@@ -66,7 +66,7 @@ module OmnifocusMcp
66
66
  def applescript_run_failure(stderr:, status:)
67
67
  exit_code = status.respond_to?(:exitstatus) ? status.exitstatus : status
68
68
  message = "osascript failed (exit #{exit_code})"
69
- message += ": #{stderr.strip}" unless stderr.nil? || stderr.empty?
69
+ message += ": #{stderr.strip}" unless Utils::Blank.blank?(stderr)
70
70
  message
71
71
  end
72
72
  end
@@ -4,7 +4,7 @@ require_relative "../../../parsers/apple_script_envelope"
4
4
  require_relative "../../../infrastructure/script_runner"
5
5
  require_relative "../../../utils/blank"
6
6
  require_relative "../../../result"
7
- require_relative "../../generators/add_omnifocus_task"
7
+ require_relative "../../generators/add_omni_focus_task"
8
8
  require_relative "param_builder"
9
9
 
10
10
  module OmnifocusMcp
@@ -57,7 +57,7 @@ module OmnifocusMcp
57
57
  private
58
58
 
59
59
  def log_stderr(stderr)
60
- return if stderr.nil? || stderr.empty?
60
+ return if Utils::Blank.blank?(stderr)
61
61
 
62
62
  OmnifocusMcp.logger.warn("[batch_add_items] AppleScript stderr: #{stderr}")
63
63
  end
@@ -20,6 +20,7 @@ module OmnifocusMcp
20
20
  def prepare!
21
21
  mark_cycle_failures(cycle_messages: cycle_detector.detect)
22
22
  mark_unknown_parent_temp_id
23
+ self
23
24
  end
24
25
 
25
26
  # Stable order: by hierarchy_level (nil -> 0), then original index.
@@ -3,7 +3,7 @@
3
3
  require_relative "../../infrastructure/script_runner"
4
4
  require_relative "../../result"
5
5
  require_relative "../params"
6
- require_relative "add_omnifocus_task"
6
+ require_relative "add_omni_focus_task"
7
7
  require_relative "add_project"
8
8
  require_relative "batch_add_items/planner"
9
9
  require_relative "batch_add_items/batch_item"
@@ -33,10 +33,10 @@ module OmnifocusMcp
33
33
  def call(items)
34
34
  batch_items = Array(items).map { |item| coerce_item(item) }
35
35
  .then { |coerced| build_batch_items(coerced) }
36
- planner = Planner.new(batch_items).tap(&:prepare!)
37
36
 
38
37
  return OmnifocusMcp::Result.ok(batch_items.map(&:result)) if try_bulk_add!(batch_items:)
39
38
 
39
+ planner = Planner.new(batch_items).prepare!
40
40
  process_items(ordered: planner.processing_order, planner:)
41
41
  planner.finalize_unresolved!
42
42
 
@@ -74,8 +74,10 @@ module OmnifocusMcp
74
74
 
75
75
  def coerce_item(item)
76
76
  case item
77
- when Params::BatchAddItemParams then item
78
- when Hash then Params::BatchAddItemParams.from_hash(item)
77
+ when Params::BatchAddItemParams
78
+ item
79
+ when Hash
80
+ Params::BatchAddItemParams.from_hash(item)
79
81
  else raise ArgumentError, "expected BatchAddItemParams or Hash, got #{item.class}"
80
82
  end
81
83
  end
@@ -32,8 +32,10 @@ module OmnifocusMcp
32
32
 
33
33
  def coerce_item(item)
34
34
  case item
35
- when Params::BatchRemoveItemParams then item
36
- when Hash then Params::BatchRemoveItemParams.from_hash(item)
35
+ when Params::BatchRemoveItemParams
36
+ item
37
+ when Hash
38
+ Params::BatchRemoveItemParams.from_hash(item)
37
39
  else raise ArgumentError, "expected BatchRemoveItemParams or Hash, got #{item.class}"
38
40
  end
39
41
  end
@@ -9,8 +9,8 @@ module OmnifocusMcp
9
9
  module Operations
10
10
  class DatabaseStats
11
11
  class << self
12
- def get_database_stats(script_runner: Infrastructure::ScriptRunner)
13
- new(script_runner:).get_database_stats
12
+ def database_stats(script_runner: Infrastructure::ScriptRunner)
13
+ new(script_runner:).database_stats
14
14
  end
15
15
 
16
16
  def get_changes_since(since, script_runner: Infrastructure::ScriptRunner)
@@ -23,7 +23,7 @@ module OmnifocusMcp
23
23
  @generator = generator
24
24
  end
25
25
 
26
- def get_database_stats
26
+ def database_stats
27
27
  script_payload_result(script_runner.execute_omnifocus_source(generator.stats_script))
28
28
  end
29
29
 
@@ -36,7 +36,7 @@ module OmnifocusMcp
36
36
 
37
37
  def call(params)
38
38
  params = Params::McpBoundary.coerce(Params::EditItemParams, params)
39
- generator.generate_apple_script(params).then { |script| run_script(script) }
39
+ generator.generate_apple_script(params).then { run_script(it) }
40
40
  rescue StandardError => e
41
41
  OmnifocusMcp.logger.warn("[edit_item] Error: #{e}")
42
42
  OmnifocusMcp::Result.error(e.message || "Unknown error in edit_item")
@@ -49,7 +49,7 @@ module OmnifocusMcp
49
49
  def run_script(script)
50
50
  stdout, stderr, status = script_runner.execute_applescript(script)
51
51
 
52
- OmnifocusMcp.logger.warn("[edit_item] AppleScript stderr: #{stderr}") if stderr && !stderr.empty?
52
+ OmnifocusMcp.logger.warn("[edit_item] AppleScript stderr: #{stderr}") if Utils::Blank.present?(stderr)
53
53
  return OmnifocusMcp::Result.error(applescript_run_failure(stderr:, status:)) unless status.success?
54
54
 
55
55
  parse_result(stdout)
@@ -70,7 +70,7 @@ module OmnifocusMcp
70
70
  def applescript_run_failure(stderr:, status:)
71
71
  exit_code = status.respond_to?(:exitstatus) ? status.exitstatus : status
72
72
  message = "osascript failed (exit #{exit_code})"
73
- message += ": #{stderr.strip}" unless stderr.nil? || stderr.empty?
73
+ message += ": #{stderr.strip}" unless Utils::Blank.blank?(stderr)
74
74
  message
75
75
  end
76
76
  end