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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -1
- data/README.md +17 -13
- data/bin/omnifocus-mcp +0 -1
- data/docs/superpowers/plans/2026-11-17-server-gap-fixes.md +192 -0
- data/lib/omnifocus_mcp/infrastructure/apple_script.rb +83 -19
- data/lib/omnifocus_mcp/infrastructure/script_runner.rb +6 -8
- data/lib/omnifocus_mcp/json_rpc_compat.rb +1 -2
- data/lib/omnifocus_mcp/logger.rb +1 -0
- data/lib/omnifocus_mcp/resources/base.rb +2 -37
- data/lib/omnifocus_mcp/resources/stats_resource.rb +1 -1
- data/lib/omnifocus_mcp/tools/database_stats.rb +3 -157
- data/lib/omnifocus_mcp/tools/definitions/{add_omnifocus_task_tool.rb → add_omni_focus_task_tool.rb} +8 -4
- data/lib/omnifocus_mcp/tools/definitions/add_project_tool.rb +4 -1
- data/lib/omnifocus_mcp/tools/definitions/batch_add_items_tool.rb +5 -3
- data/lib/omnifocus_mcp/tools/definitions/date_formatter.rb +8 -7
- data/lib/omnifocus_mcp/tools/definitions/edit_item_tool.rb +25 -6
- data/lib/omnifocus_mcp/tools/definitions/key_normalizer.rb +21 -1
- data/lib/omnifocus_mcp/tools/definitions/query_omnifocus_tool.rb +1 -2
- data/lib/omnifocus_mcp/tools/generators/{add_omnifocus_task.rb → add_omni_focus_task.rb} +8 -13
- data/lib/omnifocus_mcp/tools/generators/add_project.rb +4 -6
- data/lib/omnifocus_mcp/tools/generators/database_stats.rb +133 -3
- data/lib/omnifocus_mcp/tools/generators/edit_item.rb +39 -56
- data/lib/omnifocus_mcp/tools/generators/note_edit.rb +108 -0
- data/lib/omnifocus_mcp/tools/generators/query_omnifocus.rb +32 -26
- data/lib/omnifocus_mcp/tools/generators/remove_item.rb +1 -1
- data/lib/omnifocus_mcp/tools/messages/{add_omnifocus_task.rb → add_omni_focus_task.rb} +5 -3
- data/lib/omnifocus_mcp/tools/operations/{add_omnifocus_task.rb → add_omni_focus_task.rb} +6 -4
- data/lib/omnifocus_mcp/tools/operations/add_project.rb +3 -3
- data/lib/omnifocus_mcp/tools/operations/batch_add_items/bulk_executor.rb +2 -2
- data/lib/omnifocus_mcp/tools/operations/batch_add_items/planner.rb +1 -0
- data/lib/omnifocus_mcp/tools/operations/batch_add_items.rb +6 -4
- data/lib/omnifocus_mcp/tools/operations/batch_remove_items.rb +4 -2
- data/lib/omnifocus_mcp/tools/operations/database_stats.rb +3 -3
- data/lib/omnifocus_mcp/tools/operations/edit_item.rb +3 -3
- data/lib/omnifocus_mcp/tools/operations/list_perspectives.rb +1 -1
- data/lib/omnifocus_mcp/tools/operations/remove_item.rb +3 -3
- data/lib/omnifocus_mcp/tools/params/mcp_boundary.rb +4 -2
- data/lib/omnifocus_mcp/tools/params.rb +2 -2
- data/lib/omnifocus_mcp/tools/presenters/query_results.rb +12 -6
- data/lib/omnifocus_mcp/utils/blank.rb +4 -0
- data/lib/omnifocus_mcp/utils/date_filter.rb +1 -2
- data/lib/omnifocus_mcp/version.rb +1 -1
- data/lib/omnifocus_mcp.rb +6 -7
- metadata +8 -10
- data/lib/omnifocus_mcp/tools/batch_report.rb +0 -9
- data/lib/omnifocus_mcp/tools/generators/.keep +0 -1
- data/lib/omnifocus_mcp/tools/query_omnifocus_formatter.rb +0 -9
- data/lib/omnifocus_mcp/utils/date_formatting.rb +0 -9
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "../result"
|
|
4
|
-
require_relative "../infrastructure/js_embed"
|
|
5
|
-
require_relative "../infrastructure/script_runner"
|
|
6
|
-
|
|
7
3
|
module OmnifocusMcp
|
|
8
4
|
module Tools
|
|
9
5
|
# Lightweight database overview helpers that don't require pulling the
|
|
10
6
|
# full OmniFocus dataset.
|
|
11
7
|
#
|
|
12
8
|
# Provides:
|
|
13
|
-
# * {.
|
|
9
|
+
# * {.database_stats} — counts + last-modified timestamp
|
|
14
10
|
# * {.get_changes_since} — incremental change feed since a timestamp
|
|
15
|
-
# rubocop:disable Metrics/ModuleLength
|
|
16
11
|
module DatabaseStats
|
|
17
|
-
# Lightweight database statistics: counts + last-modified timestamp.
|
|
18
|
-
#
|
|
19
|
-
# @return [OmnifocusMcp::Result] +ok+ carries the stats Hash; +error+ carries a user-facing message.
|
|
20
12
|
class << self
|
|
21
|
-
def
|
|
13
|
+
def database_stats
|
|
22
14
|
require_relative "operations/database_stats"
|
|
23
15
|
|
|
24
|
-
Operations::DatabaseStats.
|
|
16
|
+
Operations::DatabaseStats.database_stats
|
|
25
17
|
end
|
|
26
18
|
|
|
27
19
|
# Incremental change feed since `since` (a Time, DateTime, or ISO string).
|
|
@@ -32,153 +24,7 @@ module OmnifocusMcp
|
|
|
32
24
|
|
|
33
25
|
Operations::DatabaseStats.get_changes_since(since)
|
|
34
26
|
end
|
|
35
|
-
|
|
36
|
-
STATS_SCRIPT = <<~JS
|
|
37
|
-
(() => {
|
|
38
|
-
try {
|
|
39
|
-
const allTasks = flattenedTasks;
|
|
40
|
-
const activeTasks = allTasks.filter(task =>
|
|
41
|
-
task.taskStatus !== Task.Status.Completed &&
|
|
42
|
-
task.taskStatus !== Task.Status.Dropped
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const allProjects = flattenedProjects;
|
|
46
|
-
const activeProjects = allProjects.filter(project =>
|
|
47
|
-
project.status === Project.Status.Active
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const overdueCount = activeTasks.filter(task =>
|
|
51
|
-
task.taskStatus === Task.Status.Overdue
|
|
52
|
-
).length;
|
|
53
|
-
|
|
54
|
-
const nextActionCount = activeTasks.filter(task =>
|
|
55
|
-
task.taskStatus === Task.Status.Next
|
|
56
|
-
).length;
|
|
57
|
-
|
|
58
|
-
const flaggedCount = activeTasks.filter(task => task.flagged).length;
|
|
59
|
-
const inboxCount = activeTasks.filter(task => task.inInbox).length;
|
|
60
|
-
|
|
61
|
-
let lastModified = new Date(0);
|
|
62
|
-
allTasks.forEach(task => {
|
|
63
|
-
if (task.modificationDate && task.modificationDate > lastModified) {
|
|
64
|
-
lastModified = task.modificationDate;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
return JSON.stringify({
|
|
69
|
-
taskCount: allTasks.length,
|
|
70
|
-
activeTaskCount: activeTasks.length,
|
|
71
|
-
projectCount: allProjects.length,
|
|
72
|
-
activeProjectCount: activeProjects.length,
|
|
73
|
-
folderCount: flattenedFolders.length,
|
|
74
|
-
tagCount: flattenedTags.filter(tag => tag.active).length,
|
|
75
|
-
overdueCount: overdueCount,
|
|
76
|
-
nextActionCount: nextActionCount,
|
|
77
|
-
flaggedCount: flaggedCount,
|
|
78
|
-
inboxCount: inboxCount,
|
|
79
|
-
lastModified: lastModified.toISOString()
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
} catch (error) {
|
|
83
|
-
return JSON.stringify({
|
|
84
|
-
error: "Failed to get database stats: " + error.toString()
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
})();
|
|
88
|
-
JS
|
|
89
|
-
|
|
90
|
-
# rubocop:disable Metrics/MethodLength
|
|
91
|
-
def changes_script(since_iso)
|
|
92
|
-
escaped_since = Infrastructure::JsEmbed.double_quoted_string(since_iso)
|
|
93
|
-
|
|
94
|
-
<<~JS
|
|
95
|
-
(() => {
|
|
96
|
-
try {
|
|
97
|
-
const sinceDate = new Date("#{escaped_since}");
|
|
98
|
-
|
|
99
|
-
const allTasks = flattenedTasks;
|
|
100
|
-
|
|
101
|
-
const newTasks = allTasks.filter(task =>
|
|
102
|
-
task.creationDate && task.creationDate > sinceDate
|
|
103
|
-
).map(task => ({
|
|
104
|
-
id: task.id.primaryKey,
|
|
105
|
-
name: task.name,
|
|
106
|
-
creationDate: task.creationDate.toISOString()
|
|
107
|
-
}));
|
|
108
|
-
|
|
109
|
-
const updatedTasks = allTasks.filter(task =>
|
|
110
|
-
task.modificationDate &&
|
|
111
|
-
task.modificationDate > sinceDate &&
|
|
112
|
-
task.creationDate &&
|
|
113
|
-
task.creationDate <= sinceDate
|
|
114
|
-
).map(task => ({
|
|
115
|
-
id: task.id.primaryKey,
|
|
116
|
-
name: task.name,
|
|
117
|
-
modificationDate: task.modificationDate.toISOString()
|
|
118
|
-
}));
|
|
119
|
-
|
|
120
|
-
const completedTasks = allTasks.filter(task =>
|
|
121
|
-
task.completionDate &&
|
|
122
|
-
task.completionDate > sinceDate
|
|
123
|
-
).map(task => ({
|
|
124
|
-
id: task.id.primaryKey,
|
|
125
|
-
name: task.name,
|
|
126
|
-
completionDate: task.completionDate.toISOString()
|
|
127
|
-
}));
|
|
128
|
-
|
|
129
|
-
const allProjects = flattenedProjects;
|
|
130
|
-
|
|
131
|
-
const newProjects = allProjects.filter(project =>
|
|
132
|
-
project.creationDate && project.creationDate > sinceDate
|
|
133
|
-
).map(project => ({
|
|
134
|
-
id: project.id.primaryKey,
|
|
135
|
-
name: project.name,
|
|
136
|
-
creationDate: project.creationDate.toISOString()
|
|
137
|
-
}));
|
|
138
|
-
|
|
139
|
-
const updatedProjects = allProjects.filter(project =>
|
|
140
|
-
project.modificationDate &&
|
|
141
|
-
project.modificationDate > sinceDate &&
|
|
142
|
-
project.creationDate &&
|
|
143
|
-
project.creationDate <= sinceDate
|
|
144
|
-
).map(project => ({
|
|
145
|
-
id: project.id.primaryKey,
|
|
146
|
-
name: project.name,
|
|
147
|
-
modificationDate: project.modificationDate.toISOString()
|
|
148
|
-
}));
|
|
149
|
-
|
|
150
|
-
return JSON.stringify({
|
|
151
|
-
newTasks: newTasks,
|
|
152
|
-
updatedTasks: updatedTasks,
|
|
153
|
-
completedTasks: completedTasks,
|
|
154
|
-
newProjects: newProjects,
|
|
155
|
-
updatedProjects: updatedProjects
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
} catch (error) {
|
|
159
|
-
return JSON.stringify({
|
|
160
|
-
error: "Failed to get changes: " + error.toString()
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
})();
|
|
164
|
-
JS
|
|
165
|
-
end
|
|
166
|
-
# rubocop:enable Metrics/MethodLength
|
|
167
|
-
|
|
168
|
-
private
|
|
169
|
-
|
|
170
|
-
# Collapse a {Infrastructure::ScriptRunner} {Result} into a {Result} over the parsed Hash payload.
|
|
171
|
-
def script_payload_result(execution)
|
|
172
|
-
execution.and_then do |payload|
|
|
173
|
-
if payload.is_a?(Hash) && payload["error"]
|
|
174
|
-
Result.error(payload["error"])
|
|
175
|
-
else
|
|
176
|
-
Result.ok(payload)
|
|
177
|
-
end
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
27
|
end
|
|
181
28
|
end
|
|
182
|
-
# rubocop:enable Metrics/ModuleLength
|
|
183
29
|
end
|
|
184
30
|
end
|
data/lib/omnifocus_mcp/tools/definitions/{add_omnifocus_task_tool.rb → add_omni_focus_task_tool.rb}
RENAMED
|
@@ -4,18 +4,19 @@ require "fast_mcp"
|
|
|
4
4
|
|
|
5
5
|
require_relative "mcp_envelope"
|
|
6
6
|
require_relative "operation_factory"
|
|
7
|
-
require_relative "../messages/
|
|
8
|
-
require_relative "../operations/
|
|
7
|
+
require_relative "../messages/add_omni_focus_task"
|
|
8
|
+
require_relative "../operations/add_omni_focus_task"
|
|
9
9
|
require_relative "../params"
|
|
10
10
|
|
|
11
11
|
module OmnifocusMcp
|
|
12
12
|
module Tools
|
|
13
13
|
module Definitions
|
|
14
|
-
# `FastMcp::Tool` for `
|
|
14
|
+
# `FastMcp::Tool` for `add_omni_focus_task`.
|
|
15
15
|
class AddOmniFocusTaskTool < FastMcp::Tool
|
|
16
16
|
tool_name "add_omnifocus_task"
|
|
17
17
|
description "Add a new task to OmniFocus"
|
|
18
18
|
|
|
19
|
+
# rubocop:disable-next Metrics/BlockLength
|
|
19
20
|
arguments do
|
|
20
21
|
required(:name).filled(:string).description("The name of the task")
|
|
21
22
|
optional(:note).filled(:string).description("Additional notes for the task")
|
|
@@ -30,7 +31,10 @@ module OmnifocusMcp
|
|
|
30
31
|
optional(:flagged).filled(:bool).description("Whether the task is flagged or not")
|
|
31
32
|
optional(:estimatedMinutes).filled(:integer)
|
|
32
33
|
.description("Estimated time to complete the task, in minutes")
|
|
33
|
-
optional(:tags).array(:string).description(
|
|
34
|
+
optional(:tags).array(:string).description(
|
|
35
|
+
"Tags to assign to the task. " \
|
|
36
|
+
"Use 'Parent/Child' for a nested tag, e.g. 'Work/Mac'; missing tags are created at that path"
|
|
37
|
+
)
|
|
34
38
|
optional(:projectName).filled(:string).description(
|
|
35
39
|
"The name of the project to add the task to (will add to inbox if not specified)"
|
|
36
40
|
)
|
|
@@ -28,7 +28,10 @@ module OmnifocusMcp
|
|
|
28
28
|
optional(:flagged).filled(:bool).description("Whether the project is flagged or not")
|
|
29
29
|
optional(:estimatedMinutes).filled(:integer)
|
|
30
30
|
.description("Estimated time to complete the project, in minutes")
|
|
31
|
-
optional(:tags).array(:string).description(
|
|
31
|
+
optional(:tags).array(:string).description(
|
|
32
|
+
"Tags to assign to the project. " \
|
|
33
|
+
"Use 'Parent/Child' for a nested tag, e.g. 'Work/Mac'; missing tags are created at that path"
|
|
34
|
+
)
|
|
32
35
|
optional(:folderName).filled(:string).description(
|
|
33
36
|
"The name of the folder to add the project to (will add to root if not specified)"
|
|
34
37
|
)
|
|
@@ -16,7 +16,7 @@ module OmnifocusMcp
|
|
|
16
16
|
tool_name "batch_add_items"
|
|
17
17
|
description "Add multiple tasks or projects to OmniFocus in a single operation"
|
|
18
18
|
|
|
19
|
-
# rubocop:disable Metrics/BlockLength
|
|
19
|
+
# rubocop:disable-next Metrics/BlockLength
|
|
20
20
|
arguments do
|
|
21
21
|
required(:items).array(:hash) do
|
|
22
22
|
required(:type).filled(included_in?: %w[task project])
|
|
@@ -33,7 +33,10 @@ module OmnifocusMcp
|
|
|
33
33
|
optional(:flagged).filled(:bool).description("Whether the item is flagged or not")
|
|
34
34
|
optional(:estimatedMinutes).filled(:integer)
|
|
35
35
|
.description("Estimated time to complete the item, in minutes")
|
|
36
|
-
optional(:tags).array(:string).description(
|
|
36
|
+
optional(:tags).array(:string).description(
|
|
37
|
+
"Tags to assign to the item. " \
|
|
38
|
+
"Use 'Parent/Child' for a nested tag, e.g. 'Work/Mac'; missing tags are created at that path"
|
|
39
|
+
)
|
|
37
40
|
|
|
38
41
|
optional(:projectName).filled(:string)
|
|
39
42
|
.description("For tasks: The name of the project to add the task to")
|
|
@@ -56,7 +59,6 @@ module OmnifocusMcp
|
|
|
56
59
|
"Process parents before children; when false, best-effort order will still try to resolve parents first"
|
|
57
60
|
)
|
|
58
61
|
end
|
|
59
|
-
# rubocop:enable Metrics/BlockLength
|
|
60
62
|
|
|
61
63
|
extend OperationFactory
|
|
62
64
|
|
|
@@ -14,9 +14,12 @@ module OmnifocusMcp
|
|
|
14
14
|
return "" if Utils::Blank.blank?(iso)
|
|
15
15
|
|
|
16
16
|
case style
|
|
17
|
-
when :locale
|
|
18
|
-
|
|
19
|
-
when :
|
|
17
|
+
when :locale
|
|
18
|
+
format_parsed(iso) { |d| us_short_date(d) }
|
|
19
|
+
when :compact
|
|
20
|
+
format_parsed(iso) { |d| us_compact_date(d) }
|
|
21
|
+
when :iso
|
|
22
|
+
Utils::IsoDate.to_date_only(iso)
|
|
20
23
|
else raise ArgumentError, "Unknown date style: #{style.inspect}"
|
|
21
24
|
end
|
|
22
25
|
end
|
|
@@ -24,13 +27,11 @@ module OmnifocusMcp
|
|
|
24
27
|
private
|
|
25
28
|
|
|
26
29
|
def us_short_date(date)
|
|
27
|
-
|
|
28
|
-
format("%d/%d/%d", date.month, date.day, date.year)
|
|
30
|
+
format("%<month>d/%<day>d/%<year>d", month: date.month, day: date.day, year: date.year)
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
def us_compact_date(date)
|
|
32
|
-
|
|
33
|
-
format("%d/%d", date.month, date.day)
|
|
34
|
+
format("%<month>d/%<day>d", month: date.month, day: date.day)
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
def format_parsed(iso)
|
|
@@ -17,7 +17,7 @@ module OmnifocusMcp
|
|
|
17
17
|
tool_name "edit_item"
|
|
18
18
|
description "Edit a task or project in OmniFocus"
|
|
19
19
|
|
|
20
|
-
# rubocop:disable Metrics/BlockLength
|
|
20
|
+
# rubocop:disable-next Metrics/BlockLength
|
|
21
21
|
arguments do
|
|
22
22
|
optional(:id).filled(:string).description("The ID of the task or project to edit")
|
|
23
23
|
optional(:name).filled(:string)
|
|
@@ -26,7 +26,18 @@ module OmnifocusMcp
|
|
|
26
26
|
.description("Type of item to edit ('task' or 'project')")
|
|
27
27
|
|
|
28
28
|
optional(:newName).filled(:string).description("New name for the item")
|
|
29
|
-
optional(:newNote).filled(:string).description("New note for the item")
|
|
29
|
+
optional(:newNote).filled(:string).description("New note for the item (replaces the whole note)")
|
|
30
|
+
optional(:noteReplacements).array(:hash) do
|
|
31
|
+
required(:find).filled(:string)
|
|
32
|
+
required(:replace).value(:string)
|
|
33
|
+
end.description(
|
|
34
|
+
"Replace text inside the note: every occurrence of each 'find' becomes its 'replace' (case-sensitive). " \
|
|
35
|
+
"If any 'find' is not in the note, nothing on the item is changed. Applied after newNote. " \
|
|
36
|
+
"Links, attachments and styles elsewhere in the note are kept."
|
|
37
|
+
)
|
|
38
|
+
optional(:appendNote).filled(:string).description(
|
|
39
|
+
"Text to add to the end of the note, on a new line. Applied after noteReplacements."
|
|
40
|
+
)
|
|
30
41
|
optional(:newDueDate).maybe(:string).description(
|
|
31
42
|
"New due date in ISO format (YYYY-MM-DD or full ISO date); set to empty string to clear"
|
|
32
43
|
)
|
|
@@ -45,9 +56,18 @@ module OmnifocusMcp
|
|
|
45
56
|
"repeating tasks \u2014 it completes the current occurrence to trigger the next repeat, then " \
|
|
46
57
|
"drops the completed instance."
|
|
47
58
|
)
|
|
48
|
-
optional(:addTags).array(:string).description(
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
optional(:addTags).array(:string).description(
|
|
60
|
+
"Tags to add to the task. " \
|
|
61
|
+
"Use 'Parent/Child' for a nested tag, e.g. 'Work/Mac'; missing tags are created at that path"
|
|
62
|
+
)
|
|
63
|
+
optional(:removeTags).array(:string).description(
|
|
64
|
+
"Tags to remove from the task. " \
|
|
65
|
+
"Use 'Parent/Child' for a nested tag, e.g. 'Work/Mac'; missing tags are ignored"
|
|
66
|
+
)
|
|
67
|
+
optional(:replaceTags).array(:string).description(
|
|
68
|
+
"Tags to replace all existing tags with. " \
|
|
69
|
+
"Use 'Parent/Child' for a nested tag, e.g. 'Work/Mac'; missing tags are created at that path"
|
|
70
|
+
)
|
|
51
71
|
optional(:newProjectName).maybe(:string).description(
|
|
52
72
|
"Move this task to a different project by name or folder path (e.g. 'My Project' or " \
|
|
53
73
|
"'Work/My Project' to disambiguate). Pass an empty string or 'inbox' to move the task to " \
|
|
@@ -59,7 +79,6 @@ module OmnifocusMcp
|
|
|
59
79
|
optional(:newProjectStatus).filled(included_in?: %w[active completed dropped onHold])
|
|
60
80
|
.description("New status for projects")
|
|
61
81
|
end
|
|
62
|
-
# rubocop:enable Metrics/BlockLength
|
|
63
82
|
|
|
64
83
|
extend OperationFactory
|
|
65
84
|
|
|
@@ -18,11 +18,31 @@ module OmnifocusMcp
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
def camel_keys(obj)
|
|
22
|
+
case obj
|
|
23
|
+
when Hash
|
|
24
|
+
obj.each_with_object({}) do |(k, v), out|
|
|
25
|
+
out[camel_case_key(k)] = camel_keys(v)
|
|
26
|
+
end
|
|
27
|
+
when Array
|
|
28
|
+
obj.map { |item| camel_keys(item) }
|
|
29
|
+
else
|
|
30
|
+
obj
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
21
34
|
def snake_case_key(key)
|
|
22
|
-
return key unless key
|
|
35
|
+
return key unless key in Symbol | String
|
|
23
36
|
|
|
24
37
|
key.to_s.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase.to_sym
|
|
25
38
|
end
|
|
39
|
+
|
|
40
|
+
def camel_case_key(key)
|
|
41
|
+
return key unless key in Symbol | String
|
|
42
|
+
|
|
43
|
+
parts = key.to_s.split("_")
|
|
44
|
+
([parts.first] + parts.drop(1).map(&:capitalize)).join
|
|
45
|
+
end
|
|
26
46
|
end
|
|
27
47
|
end
|
|
28
48
|
end
|
|
@@ -22,7 +22,7 @@ module OmnifocusMcp
|
|
|
22
22
|
|
|
23
23
|
DATE_FILTER_FIELDS = %i[due_within deferred_until planned_within due_on defer_on planned_on].freeze
|
|
24
24
|
|
|
25
|
-
# rubocop:disable Metrics/BlockLength
|
|
25
|
+
# rubocop:disable-next Metrics/BlockLength
|
|
26
26
|
arguments do
|
|
27
27
|
required(:entity).filled(included_in?: %w[tasks projects folders]).description(
|
|
28
28
|
"Type of entity to query. Choose 'tasks' for individual tasks, 'projects' for projects, " \
|
|
@@ -146,7 +146,6 @@ module OmnifocusMcp
|
|
|
146
146
|
.filled(:bool)
|
|
147
147
|
.description("Return only count of matches, not full details. Efficient for statistics. Default: false")
|
|
148
148
|
end
|
|
149
|
-
# rubocop:enable Metrics/BlockLength
|
|
150
149
|
|
|
151
150
|
extend OperationFactory
|
|
152
151
|
|
|
@@ -69,7 +69,7 @@ module OmnifocusMcp
|
|
|
69
69
|
def applescript_run_failure(stderr:, status:)
|
|
70
70
|
exit_code = status.respond_to?(:exitstatus) ? status.exitstatus : status
|
|
71
71
|
message = "osascript failed (exit #{exit_code})"
|
|
72
|
-
message += ": #{stderr.strip}" unless
|
|
72
|
+
message += ": #{stderr.strip}" unless Utils::Blank.blank?(stderr)
|
|
73
73
|
message
|
|
74
74
|
end
|
|
75
75
|
|
|
@@ -78,7 +78,7 @@ module OmnifocusMcp
|
|
|
78
78
|
def extract_fields(params)
|
|
79
79
|
{
|
|
80
80
|
name: Infrastructure::AppleScript.escape(params.name.to_s),
|
|
81
|
-
note: Infrastructure::AppleScript.
|
|
81
|
+
note: Infrastructure::AppleScript.multiline_string(params.note.to_s),
|
|
82
82
|
project_name: Infrastructure::AppleScript.escape(params.project_name.to_s),
|
|
83
83
|
parent_task_id: Infrastructure::AppleScript.escape(params.parent_task_id.to_s),
|
|
84
84
|
parent_task_name: Infrastructure::AppleScript.escape(params.parent_task_name.to_s),
|
|
@@ -132,7 +132,7 @@ module OmnifocusMcp
|
|
|
132
132
|
"-- Get the task ID",
|
|
133
133
|
"set taskId to id of newTask as string",
|
|
134
134
|
tag_assignments_block(fields[:tags]),
|
|
135
|
-
finalize == :bulk ? bulk_record_result : success_return
|
|
135
|
+
finalize == :bulk ? bulk_record_result : success_return
|
|
136
136
|
].compact.join("\n")
|
|
137
137
|
end
|
|
138
138
|
|
|
@@ -173,10 +173,10 @@ module OmnifocusMcp
|
|
|
173
173
|
APPLESCRIPT
|
|
174
174
|
end
|
|
175
175
|
|
|
176
|
-
def success_return
|
|
176
|
+
def success_return
|
|
177
177
|
payload = [
|
|
178
178
|
%(\\"taskId\\":\\"" & taskId & "\\"),
|
|
179
|
-
%(\\"name\\":\\"
|
|
179
|
+
%(\\"name\\":\\"" & my jsonEscape(name of newTask) & "\\"),
|
|
180
180
|
%(\\"placement\\":\\"" & placement & "\\")
|
|
181
181
|
].join(",")
|
|
182
182
|
%(return "{\\"success\\":true,#{payload}}")
|
|
@@ -215,7 +215,7 @@ module OmnifocusMcp
|
|
|
215
215
|
APPLESCRIPT
|
|
216
216
|
end
|
|
217
217
|
|
|
218
|
-
# rubocop:disable Metrics/MethodLength
|
|
218
|
+
# rubocop:disable-next Metrics/MethodLength
|
|
219
219
|
def parent_lookup_by_name(fields)
|
|
220
220
|
<<~APPLESCRIPT.chomp
|
|
221
221
|
if parentTask is missing value and "#{fields[:parent_task_name]}" is not "" then
|
|
@@ -244,7 +244,6 @@ module OmnifocusMcp
|
|
|
244
244
|
end if
|
|
245
245
|
APPLESCRIPT
|
|
246
246
|
end
|
|
247
|
-
# rubocop:enable Metrics/MethodLength
|
|
248
247
|
|
|
249
248
|
# Pick the container: explicit parent, project root, or inbox.
|
|
250
249
|
def task_creation(fields)
|
|
@@ -286,7 +285,7 @@ module OmnifocusMcp
|
|
|
286
285
|
["-- Set #{label} date", "set #{label} date of newTask to #{value}"]
|
|
287
286
|
end
|
|
288
287
|
|
|
289
|
-
# rubocop:disable Metrics/MethodLength
|
|
288
|
+
# rubocop:disable-next Metrics/MethodLength
|
|
290
289
|
def placement_derivation(project_name)
|
|
291
290
|
<<~APPLESCRIPT.chomp
|
|
292
291
|
-- Derive placement from container; distinguish real parent vs project root task
|
|
@@ -323,16 +322,12 @@ module OmnifocusMcp
|
|
|
323
322
|
end try
|
|
324
323
|
APPLESCRIPT
|
|
325
324
|
end
|
|
326
|
-
# rubocop:enable Metrics/MethodLength
|
|
327
325
|
|
|
328
326
|
def tag_assignments_block(tags)
|
|
329
327
|
return nil if tags.empty?
|
|
330
328
|
|
|
331
329
|
blocks = tags.map do |tag|
|
|
332
|
-
Infrastructure::AppleScript.tag_assignment(
|
|
333
|
-
item_var: "newTask",
|
|
334
|
-
tag_name: Infrastructure::AppleScript.escape(tag.to_s)
|
|
335
|
-
)
|
|
330
|
+
Infrastructure::AppleScript.tag_assignment(item_var: "newTask", tag_path: tag.to_s)
|
|
336
331
|
end
|
|
337
332
|
|
|
338
333
|
"\n-- Add tags if provided\n#{blocks.join("\n")}"
|
|
@@ -36,7 +36,7 @@ module OmnifocusMcp
|
|
|
36
36
|
def extract_fields(params)
|
|
37
37
|
{
|
|
38
38
|
name: Infrastructure::AppleScript.escape(params.name.to_s),
|
|
39
|
-
note: Infrastructure::AppleScript.
|
|
39
|
+
note: Infrastructure::AppleScript.multiline_string(params.note.to_s),
|
|
40
40
|
folder_name: params.folder_name.to_s,
|
|
41
41
|
flagged: params.flagged == true,
|
|
42
42
|
sequential: params.sequential == true,
|
|
@@ -76,7 +76,8 @@ module OmnifocusMcp
|
|
|
76
76
|
"-- Get the project ID",
|
|
77
77
|
"set projectId to id of newProject as string",
|
|
78
78
|
tag_assignments_block(fields[:tags]),
|
|
79
|
-
%(return "{\\"success\\":true,\\"projectId\\":\\"" & projectId &
|
|
79
|
+
%(return "{\\"success\\":true,\\"projectId\\":\\"" & projectId & ) +
|
|
80
|
+
%("\\",\\"name\\":\\"" & my jsonEscape(name of newProject) & "\\"}")
|
|
80
81
|
].compact.join("\n")
|
|
81
82
|
end
|
|
82
83
|
|
|
@@ -125,10 +126,7 @@ module OmnifocusMcp
|
|
|
125
126
|
return nil if tags.empty?
|
|
126
127
|
|
|
127
128
|
blocks = tags.map do |tag|
|
|
128
|
-
Infrastructure::AppleScript.tag_assignment(
|
|
129
|
-
item_var: "newProject",
|
|
130
|
-
tag_name: Infrastructure::AppleScript.escape(tag.to_s)
|
|
131
|
-
)
|
|
129
|
+
Infrastructure::AppleScript.tag_assignment(item_var: "newProject", tag_path: tag.to_s)
|
|
132
130
|
end
|
|
133
131
|
|
|
134
132
|
"\n-- Add tags if provided\n#{blocks.join("\n")}"
|
|
@@ -1,14 +1,144 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "
|
|
3
|
+
require_relative "../../infrastructure/js_embed"
|
|
4
4
|
|
|
5
5
|
module OmnifocusMcp
|
|
6
6
|
module Tools
|
|
7
7
|
module Generators
|
|
8
8
|
class DatabaseStats
|
|
9
9
|
class << self
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
STATS_SCRIPT = <<~JS
|
|
11
|
+
(() => {
|
|
12
|
+
try {
|
|
13
|
+
const allTasks = flattenedTasks;
|
|
14
|
+
const activeTasks = allTasks.filter(task =>
|
|
15
|
+
task.taskStatus !== Task.Status.Completed &&
|
|
16
|
+
task.taskStatus !== Task.Status.Dropped
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const allProjects = flattenedProjects;
|
|
20
|
+
const activeProjects = allProjects.filter(project =>
|
|
21
|
+
project.status === Project.Status.Active
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const overdueCount = activeTasks.filter(task =>
|
|
25
|
+
task.taskStatus === Task.Status.Overdue
|
|
26
|
+
).length;
|
|
27
|
+
|
|
28
|
+
const nextActionCount = activeTasks.filter(task =>
|
|
29
|
+
task.taskStatus === Task.Status.Next
|
|
30
|
+
).length;
|
|
31
|
+
|
|
32
|
+
const flaggedCount = activeTasks.filter(task => task.flagged).length;
|
|
33
|
+
const inboxCount = activeTasks.filter(task => task.inInbox).length;
|
|
34
|
+
|
|
35
|
+
let lastModified = new Date(0);
|
|
36
|
+
allTasks.forEach(task => {
|
|
37
|
+
if (task.modificationDate && task.modificationDate > lastModified) {
|
|
38
|
+
lastModified = task.modificationDate;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return JSON.stringify({
|
|
43
|
+
taskCount: allTasks.length,
|
|
44
|
+
activeTaskCount: activeTasks.length,
|
|
45
|
+
projectCount: allProjects.length,
|
|
46
|
+
activeProjectCount: activeProjects.length,
|
|
47
|
+
folderCount: flattenedFolders.length,
|
|
48
|
+
tagCount: flattenedTags.filter(tag => tag.active).length,
|
|
49
|
+
overdueCount: overdueCount,
|
|
50
|
+
nextActionCount: nextActionCount,
|
|
51
|
+
flaggedCount: flaggedCount,
|
|
52
|
+
inboxCount: inboxCount,
|
|
53
|
+
lastModified: lastModified.toISOString()
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
} catch (error) {
|
|
57
|
+
return JSON.stringify({
|
|
58
|
+
error: "Failed to get database stats: " + error.toString()
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
})();
|
|
62
|
+
JS
|
|
63
|
+
|
|
64
|
+
def stats_script = STATS_SCRIPT
|
|
65
|
+
|
|
66
|
+
# rubocop:disable-next Metrics/MethodLength
|
|
67
|
+
def changes_script(since_iso)
|
|
68
|
+
escaped_since = Infrastructure::JsEmbed.double_quoted_string(since_iso)
|
|
69
|
+
|
|
70
|
+
<<~JS
|
|
71
|
+
(() => {
|
|
72
|
+
try {
|
|
73
|
+
const sinceDate = new Date("#{escaped_since}");
|
|
74
|
+
|
|
75
|
+
const allTasks = flattenedTasks;
|
|
76
|
+
|
|
77
|
+
const newTasks = allTasks.filter(task =>
|
|
78
|
+
task.creationDate && task.creationDate > sinceDate
|
|
79
|
+
).map(task => ({
|
|
80
|
+
id: task.id.primaryKey,
|
|
81
|
+
name: task.name,
|
|
82
|
+
creationDate: task.creationDate.toISOString()
|
|
83
|
+
}));
|
|
84
|
+
|
|
85
|
+
const updatedTasks = allTasks.filter(task =>
|
|
86
|
+
task.modificationDate &&
|
|
87
|
+
task.modificationDate > sinceDate &&
|
|
88
|
+
task.creationDate &&
|
|
89
|
+
task.creationDate <= sinceDate
|
|
90
|
+
).map(task => ({
|
|
91
|
+
id: task.id.primaryKey,
|
|
92
|
+
name: task.name,
|
|
93
|
+
modificationDate: task.modificationDate.toISOString()
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
const completedTasks = allTasks.filter(task =>
|
|
97
|
+
task.completionDate &&
|
|
98
|
+
task.completionDate > sinceDate
|
|
99
|
+
).map(task => ({
|
|
100
|
+
id: task.id.primaryKey,
|
|
101
|
+
name: task.name,
|
|
102
|
+
completionDate: task.completionDate.toISOString()
|
|
103
|
+
}));
|
|
104
|
+
|
|
105
|
+
const allProjects = flattenedProjects;
|
|
106
|
+
|
|
107
|
+
const newProjects = allProjects.filter(project =>
|
|
108
|
+
project.creationDate && project.creationDate > sinceDate
|
|
109
|
+
).map(project => ({
|
|
110
|
+
id: project.id.primaryKey,
|
|
111
|
+
name: project.name,
|
|
112
|
+
creationDate: project.creationDate.toISOString()
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
const updatedProjects = allProjects.filter(project =>
|
|
116
|
+
project.modificationDate &&
|
|
117
|
+
project.modificationDate > sinceDate &&
|
|
118
|
+
project.creationDate &&
|
|
119
|
+
project.creationDate <= sinceDate
|
|
120
|
+
).map(project => ({
|
|
121
|
+
id: project.id.primaryKey,
|
|
122
|
+
name: project.name,
|
|
123
|
+
modificationDate: project.modificationDate.toISOString()
|
|
124
|
+
}));
|
|
125
|
+
|
|
126
|
+
return JSON.stringify({
|
|
127
|
+
newTasks: newTasks,
|
|
128
|
+
updatedTasks: updatedTasks,
|
|
129
|
+
completedTasks: completedTasks,
|
|
130
|
+
newProjects: newProjects,
|
|
131
|
+
updatedProjects: updatedProjects
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
} catch (error) {
|
|
135
|
+
return JSON.stringify({
|
|
136
|
+
error: "Failed to get changes: " + error.toString()
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
JS
|
|
141
|
+
end
|
|
12
142
|
end
|
|
13
143
|
end
|
|
14
144
|
end
|