omnifocus-mcp-enhanced 1.6.11 → 1.7.0

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 (42) hide show
  1. package/README.md +3 -0
  2. package/README.zh.md +3 -0
  3. package/dist/omnifocustypes.js +11 -0
  4. package/dist/server.js +2 -0
  5. package/dist/tools/definitions/addOmniFocusTask.js +5 -1
  6. package/dist/tools/definitions/addProject.js +5 -1
  7. package/dist/tools/definitions/editItem.js +5 -1
  8. package/dist/tools/definitions/plannedDateSchemas.test.js +25 -0
  9. package/dist/tools/definitions/setRepetitionRule.js +88 -0
  10. package/dist/tools/definitions/setRepetitionRule.test.js +42 -0
  11. package/dist/tools/primitives/addOmniFocusTask.js +22 -4
  12. package/dist/tools/primitives/addProject.js +22 -4
  13. package/dist/tools/primitives/applyTagsExclusive.js +37 -0
  14. package/dist/tools/primitives/applyTagsExclusive.test.js +19 -0
  15. package/dist/tools/primitives/editItem.js +35 -3
  16. package/dist/tools/primitives/editItem.test.js +22 -0
  17. package/dist/tools/primitives/setRepetitionRule.js +85 -0
  18. package/dist/tools/primitives/setRepetitionRule.test.js +65 -0
  19. package/dist/utils/omnifocusScripts/applyTagsExclusive.js +106 -0
  20. package/dist/utils/omnifocusScripts/setRepetitionRule.js +117 -0
  21. package/dist/utils/scriptExecution.js +7 -3
  22. package/package.json +1 -1
  23. package/src/omnifocustypes.ts +12 -0
  24. package/src/server.ts +8 -0
  25. package/src/tools/definitions/addOmniFocusTask.ts +6 -1
  26. package/src/tools/definitions/addProject.ts +6 -1
  27. package/src/tools/definitions/editItem.ts +6 -1
  28. package/src/tools/definitions/plannedDateSchemas.test.ts +31 -0
  29. package/src/tools/definitions/setRepetitionRule.test.ts +53 -0
  30. package/src/tools/definitions/setRepetitionRule.ts +93 -0
  31. package/src/tools/primitives/addOmniFocusTask.ts +28 -6
  32. package/src/tools/primitives/addProject.ts +28 -6
  33. package/src/tools/primitives/applyTagsExclusive.test.ts +23 -0
  34. package/src/tools/primitives/applyTagsExclusive.ts +56 -0
  35. package/src/tools/primitives/editItem.test.ts +26 -0
  36. package/src/tools/primitives/editItem.ts +42 -3
  37. package/src/tools/primitives/setRepetitionRule.test.ts +76 -0
  38. package/src/tools/primitives/setRepetitionRule.ts +132 -0
  39. package/src/types.ts +11 -0
  40. package/src/utils/omnifocusScripts/applyTagsExclusive.js +106 -0
  41. package/src/utils/omnifocusScripts/setRepetitionRule.js +117 -0
  42. package/src/utils/scriptExecution.ts +9 -8
package/README.md CHANGED
@@ -44,6 +44,7 @@ Want to see where the project is heading next? See the [roadmap](docs/roadmap/20
44
44
 
45
45
  ## 🆕 Latest Release
46
46
 
47
+ - **v1.7.0** - Added OmniFocus 4.7+ repeat rule support via `set_repetition_rule` (ICS rule strings, schedule type, anchor date, catch-up, end date, repetition count), mutually exclusive tag support via `exclusiveTags` on add/edit tools, and improved planned-date editing tests.
47
48
  - **v1.6.10** - Fixed Inbox task completion via `edit_item`, fixed AppleScript special-character handling for apostrophes/backslashes, fixed JSON result escaping for special characters, and clarified `batch_add_items` / `mcporter` usage with working examples.
48
49
  - **v1.6.9** - Added task attachment support: `get_task_by_id` now lists attachment metadata, `dump_database` exports attachment/link metadata, and new `read_task_attachment` returns image attachments as MCP image content when possible.
49
50
  - **v1.6.8** - Added stable task move support via `move_task` and `edit_item` (`newProjectId/newProjectName/newParentTaskId/newParentTaskName/moveToInbox`) with duplicate-name protection and cycle-prevention checks.
@@ -66,6 +67,8 @@ Want to see where the project is heading next? See the [roadmap](docs/roadmap/20
66
67
  - **🔄 Full CRUD Operations** - Create, read, update, delete tasks and projects
67
68
  - **📅 Time Management** - Due, defer, planned dates, estimates, and scheduling
68
69
  - **🏷️ Advanced Tagging** - Tag-based filtering with exact/partial matching
70
+ - **🚫 Mutually Exclusive Tags** - Automatically respects exclusive tag groups when applying tags
71
+ - **🔁 Repeat Rules** - Full OmniFocus 4.7+ repetition support (ICS rules, schedule type, anchor date, catch-up, end date, count)
69
72
  - **🤖 AI Integration** - Seamless Claude AI integration for intelligent workflows
70
73
  - **🖼️ Attachment-Aware Reads** - Surface note attachments and linked files before deciding whether AI should inspect them
71
74
 
package/README.zh.md CHANGED
@@ -40,6 +40,7 @@ OmniFocus 本身已经很强了,但它大多数时候仍然是一个需要你
40
40
 
41
41
  ## 🆕 最新版本
42
42
 
43
+ - **v1.7.0** - 新增 OmniFocus 4.7+ 重复规则支持(`set_repetition_rule`:ICS 规则、重复方式、锚定日期、自动追平、结束日期、重复次数),新增互斥标签支持(`exclusiveTags`),并补全计划日期编辑测试。
43
44
  - **v1.6.10** - 修复 `edit_item` 无法完成 Inbox 任务的问题,修复 AppleScript 对单引号/反斜杠等特殊字符的处理,修复特殊字符导致的 JSON 返回解析失败,并补充 `batch_add_items` / `mcporter` 的可直接运行示例与说明。
44
45
  - **v1.6.9** - 新增任务附件支持:`get_task_by_id` 会返回附件元信息,`dump_database` 导出附件/链接元信息,并新增 `read_task_attachment`,可在支持时直接把图片附件作为 MCP 图片内容返回。
45
46
  - **v1.6.6** - 新增 Planned Date(计划日期)全链路支持:创建/编辑/读取/过滤/排序/导出,包含 `plannedDate` / `newPlannedDate`。
@@ -61,6 +62,8 @@ OmniFocus 本身已经很强了,但它大多数时候仍然是一个需要你
61
62
  - **🔄 完整 CRUD 操作** - 创建、读取、更新、删除任务和项目
62
63
  - **📅 时间管理** - 截止日期、推迟日期、计划日期、估时和计划
63
64
  - **🏷️ 高级标签** - 基于标签的精确/模糊匹配过滤
65
+ - **🚫 互斥标签** - 应用标签时自动遵守互斥标签组规则
66
+ - **🔁 重复规则** - 完整支持 OmniFocus 4.7+ 重复任务(ICS 规则、重复方式、锚定日期、自动追平、结束日期、重复次数)
64
67
  - **🤖 AI 集成** - 与 Claude AI 无缝集成,实现智能工作流
65
68
  - **🖼️ 附件感知读取** - 先暴露备注附件和链接文件的元信息,再决定是否让 AI 继续查看附件内容
66
69
 
@@ -18,6 +18,17 @@ export var Task;
18
18
  RepetitionMethod[RepetitionMethod["Fixed"] = 2] = "Fixed";
19
19
  RepetitionMethod[RepetitionMethod["None"] = 3] = "None";
20
20
  })(RepetitionMethod = Task.RepetitionMethod || (Task.RepetitionMethod = {}));
21
+ let RepetitionScheduleType;
22
+ (function (RepetitionScheduleType) {
23
+ RepetitionScheduleType[RepetitionScheduleType["Regularly"] = 0] = "Regularly";
24
+ RepetitionScheduleType[RepetitionScheduleType["FromCompletion"] = 1] = "FromCompletion";
25
+ })(RepetitionScheduleType = Task.RepetitionScheduleType || (Task.RepetitionScheduleType = {}));
26
+ let AnchorDateKey;
27
+ (function (AnchorDateKey) {
28
+ AnchorDateKey[AnchorDateKey["DeferDate"] = 0] = "DeferDate";
29
+ AnchorDateKey[AnchorDateKey["DueDate"] = 1] = "DueDate";
30
+ AnchorDateKey[AnchorDateKey["PlannedDate"] = 2] = "PlannedDate";
31
+ })(AnchorDateKey = Task.AnchorDateKey || (Task.AnchorDateKey = {}));
21
32
  })(Task || (Task = {}));
22
33
  export var Project;
23
34
  (function (Project) {
package/dist/server.js CHANGED
@@ -13,6 +13,7 @@ import * as batchRemoveItemsTool from './tools/definitions/batchRemoveItems.js';
13
13
  import * as getTaskByIdTool from './tools/definitions/getTaskById.js';
14
14
  import * as readTaskAttachmentTool from './tools/definitions/readTaskAttachment.js';
15
15
  import * as getTodayCompletedTasksTool from './tools/definitions/getTodayCompletedTasks.js';
16
+ import * as setRepetitionRuleTool from './tools/definitions/setRepetitionRule.js';
16
17
  // Import perspective tools
17
18
  import * as getInboxTasksTool from './tools/definitions/getInboxTasks.js';
18
19
  import * as getFlaggedTasksTool from './tools/definitions/getFlaggedTasks.js';
@@ -41,6 +42,7 @@ server.tool("batch_remove_items", "Remove multiple tasks or projects from OmniFo
41
42
  server.tool("get_task_by_id", "Get information about a specific task by ID or name", getTaskByIdTool.schema.shape, getTaskByIdTool.handler);
42
43
  server.tool("read_task_attachment", "Read a task attachment reported by get_task_by_id. Images are returned as MCP image content when possible.", readTaskAttachmentTool.schema.shape, readTaskAttachmentTool.handler);
43
44
  server.tool("get_today_completed_tasks", "Get tasks completed today - view today's accomplishments", getTodayCompletedTasksTool.schema.shape, getTodayCompletedTasksTool.handler);
45
+ server.tool("set_repetition_rule", "Set, update, or clear the repeat rule on a task. Supports ICS rule strings, schedule type, anchor date, catch-up, end date, and repetition count.", setRepetitionRuleTool.schema.shape, setRepetitionRuleTool.handler);
44
46
  // Register perspective tools
45
47
  server.tool("get_inbox_tasks", "Get tasks from OmniFocus inbox perspective", getInboxTasksTool.schema.shape, getInboxTasksTool.handler);
46
48
  server.tool("get_flagged_tasks", "Get flagged tasks from OmniFocus with optional project filtering", getFlaggedTasksTool.schema.shape, getFlaggedTasksTool.handler);
@@ -9,6 +9,7 @@ export const schema = z.object({
9
9
  flagged: z.boolean().optional().describe("Whether the task is flagged or not"),
10
10
  estimatedMinutes: z.number().optional().describe("Estimated time to complete the task, in minutes"),
11
11
  tags: z.array(z.string()).optional().describe("Tags to assign to the task"),
12
+ exclusiveTags: z.boolean().optional().describe("Respect mutually exclusive tag groups when applying tags (default: true). When a tag belongs to an exclusive group, sibling tags from that group are removed."),
12
13
  projectName: z.string().optional().describe("The name of the project to add the task to (will add to inbox if not specified)"),
13
14
  parentTaskId: z.string().optional().describe("The ID of the parent task to create this task as a subtask"),
14
15
  parentTaskName: z.string().optional().describe("The name of the parent task to create this task as a subtask (alternative to parentTaskId)")
@@ -39,10 +40,13 @@ export async function handler(args, extra) {
39
40
  let plannedDateText = args.plannedDate
40
41
  ? ` planned for ${new Date(args.plannedDate).toLocaleDateString()}`
41
42
  : "";
43
+ let exclusivityText = result.removedSiblings && result.removedSiblings.length > 0
44
+ ? `\nRemoved mutually exclusive tags: ${result.removedSiblings.join(', ')}`
45
+ : "";
42
46
  return {
43
47
  content: [{
44
48
  type: "text",
45
- text: `✅ Task "${args.name}" created successfully ${locationText}${dueDateText}${plannedDateText}${tagText}.\n\nid: ${result.taskId}`
49
+ text: `✅ Task "${args.name}" created successfully ${locationText}${dueDateText}${plannedDateText}${tagText}.\n\nid: ${result.taskId}${exclusivityText}`
46
50
  }]
47
51
  };
48
52
  }
@@ -9,6 +9,7 @@ export const schema = z.object({
9
9
  flagged: z.boolean().optional().describe("Whether the project is flagged or not"),
10
10
  estimatedMinutes: z.number().optional().describe("Estimated time to complete the project, in minutes"),
11
11
  tags: z.array(z.string()).optional().describe("Tags to assign to the project"),
12
+ exclusiveTags: z.boolean().optional().describe("Respect mutually exclusive tag groups when applying tags (default: true). When a tag belongs to an exclusive group, sibling tags from that group are removed."),
12
13
  folderName: z.string().optional().describe("The name of the folder to add the project to (will add to root if not specified)"),
13
14
  sequential: z.boolean().optional().describe("Whether tasks in the project should be sequential (default: false)")
14
15
  });
@@ -33,10 +34,13 @@ export async function handler(args, extra) {
33
34
  let sequentialText = args.sequential
34
35
  ? " (sequential)"
35
36
  : " (parallel)";
37
+ let exclusivityText = result.removedSiblings && result.removedSiblings.length > 0
38
+ ? `\nRemoved mutually exclusive tags: ${result.removedSiblings.join(', ')}`
39
+ : "";
36
40
  return {
37
41
  content: [{
38
42
  type: "text",
39
- text: `✅ Project "${args.name}" created successfully ${locationText}${dueDateText}${plannedDateText}${tagText}${sequentialText}.\n\nid: ${result.projectId}`
43
+ text: `✅ Project "${args.name}" created successfully ${locationText}${dueDateText}${plannedDateText}${tagText}${sequentialText}.\n\nid: ${result.projectId}${exclusivityText}`
40
44
  }]
41
45
  };
42
46
  }
@@ -17,6 +17,7 @@ export const schema = z.object({
17
17
  addTags: z.array(z.string()).optional().describe("Tags to add to the task"),
18
18
  removeTags: z.array(z.string()).optional().describe("Tags to remove from the task"),
19
19
  replaceTags: z.array(z.string()).optional().describe("Tags to replace all existing tags with"),
20
+ exclusiveTags: z.boolean().optional().describe("Respect mutually exclusive tag groups when adding/replacing tags (default: true). When a tag belongs to an exclusive group, sibling tags from that group are removed."),
20
21
  newProjectId: z.string().optional().describe("For tasks: move task to this project ID"),
21
22
  newProjectName: z.string().optional().describe("For tasks: move task to this project name (errors on duplicate names)"),
22
23
  newParentTaskId: z.string().optional().describe("For tasks: move task under this parent task ID"),
@@ -48,10 +49,13 @@ export async function handler(args, extra) {
48
49
  if (result.changedProperties) {
49
50
  changedText = ` (${result.changedProperties})`;
50
51
  }
52
+ let exclusivityText = result.removedSiblings && result.removedSiblings.length > 0
53
+ ? `\nRemoved mutually exclusive tags: ${result.removedSiblings.join(', ')}`
54
+ : "";
51
55
  return {
52
56
  content: [{
53
57
  type: "text",
54
- text: `✅ ${itemTypeLabel} "${result.name}" updated successfully${changedText}.`
58
+ text: `✅ ${itemTypeLabel} "${result.name}" updated successfully${changedText}.${exclusivityText}`
55
59
  }]
56
60
  };
57
61
  }
@@ -74,3 +74,28 @@ test('filter_tasks schema supports planned date filters and sorting', () => {
74
74
  assert.equal(parsed.plannedBefore, '2026-02-20');
75
75
  assert.equal(parsed.sortBy, 'plannedDate');
76
76
  });
77
+ test('add_omnifocus_task schema preserves exclusiveTags', () => {
78
+ const parsed = addTaskSchema.parse({
79
+ name: 'Task with exclusive tags',
80
+ tags: ['High', 'Work'],
81
+ exclusiveTags: false
82
+ });
83
+ assert.equal(parsed.exclusiveTags, false);
84
+ });
85
+ test('add_project schema preserves exclusiveTags', () => {
86
+ const parsed = addProjectSchema.parse({
87
+ name: 'Project with exclusive tags',
88
+ tags: ['High'],
89
+ exclusiveTags: true
90
+ });
91
+ assert.equal(parsed.exclusiveTags, true);
92
+ });
93
+ test('edit_item schema preserves exclusiveTags', () => {
94
+ const parsed = editItemSchema.parse({
95
+ itemType: 'task',
96
+ id: 'abc',
97
+ addTags: ['High'],
98
+ exclusiveTags: true
99
+ });
100
+ assert.equal(parsed.exclusiveTags, true);
101
+ });
@@ -0,0 +1,88 @@
1
+ import { z } from 'zod';
2
+ import { setRepetitionRule } from '../primitives/setRepetitionRule.js';
3
+ export const schema = z.object({
4
+ taskId: z.string().describe('The ID of the task to modify'),
5
+ ruleString: z
6
+ .string()
7
+ .optional()
8
+ .describe('ICS recurrence rule string, e.g. FREQ=WEEKLY;INTERVAL=2. Defaults to FREQ=WEEKLY.'),
9
+ scheduleType: z
10
+ .enum(['Regularly', 'FromCompletion'])
11
+ .optional()
12
+ .describe('How the next occurrence is scheduled. Regularly repeats from assigned dates; FromCompletion repeats after completion.'),
13
+ anchorDateKey: z
14
+ .enum(['DueDate', 'DeferDate', 'PlannedDate'])
15
+ .optional()
16
+ .describe('Which date property is advanced when the task repeats.'),
17
+ catchUpAutomatically: z
18
+ .boolean()
19
+ .optional()
20
+ .describe('When true, missed occurrences are skipped and the next future occurrence is created.'),
21
+ endDate: z
22
+ .string()
23
+ .optional()
24
+ .describe('ISO date string for when the repetition ends. Encoded into the rule as UNTIL=.'),
25
+ count: z
26
+ .number()
27
+ .optional()
28
+ .describe('Number of repetitions after which the rule ends. Encoded into the rule as COUNT=.'),
29
+ clear: z
30
+ .boolean()
31
+ .optional()
32
+ .describe('Set to true to remove the repetition rule from the task.'),
33
+ });
34
+ export async function handler(args, extra) {
35
+ try {
36
+ const result = await setRepetitionRule({
37
+ taskId: args.taskId,
38
+ ruleString: args.ruleString,
39
+ scheduleType: args.scheduleType,
40
+ anchorDateKey: args.anchorDateKey,
41
+ catchUpAutomatically: args.catchUpAutomatically,
42
+ endDate: args.endDate,
43
+ count: args.count,
44
+ clear: args.clear,
45
+ });
46
+ if (!result.success) {
47
+ return {
48
+ content: [
49
+ {
50
+ type: 'text',
51
+ text: `Failed to set repetition rule: ${result.error || 'Unknown error'}`,
52
+ },
53
+ ],
54
+ isError: true,
55
+ };
56
+ }
57
+ if (result.cleared) {
58
+ return {
59
+ content: [
60
+ {
61
+ type: 'text',
62
+ text: 'Repetition rule cleared successfully.',
63
+ },
64
+ ],
65
+ };
66
+ }
67
+ return {
68
+ content: [
69
+ {
70
+ type: 'text',
71
+ text: `Repetition rule set successfully.\nRule: ${result.ruleString}\nSchedule: ${result.scheduleType}\nAnchor: ${result.anchorDateKey}\nCatch up automatically: ${result.catchUpAutomatically}`,
72
+ },
73
+ ],
74
+ };
75
+ }
76
+ catch (err) {
77
+ const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
78
+ return {
79
+ content: [
80
+ {
81
+ type: 'text',
82
+ text: `Error setting repetition rule: ${errorMessage}`,
83
+ },
84
+ ],
85
+ isError: true,
86
+ };
87
+ }
88
+ }
@@ -0,0 +1,42 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+ import { schema } from './setRepetitionRule.js';
4
+ test('set_repetition_rule schema requires taskId', () => {
5
+ assert.throws(() => schema.parse({}));
6
+ });
7
+ test('set_repetition_rule schema accepts minimal valid input', () => {
8
+ const parsed = schema.parse({ taskId: 'abc123' });
9
+ assert.equal(parsed.taskId, 'abc123');
10
+ });
11
+ test('set_repetition_rule schema accepts full repetition config', () => {
12
+ const parsed = schema.parse({
13
+ taskId: 'abc123',
14
+ ruleString: 'FREQ=WEEKLY;INTERVAL=2',
15
+ scheduleType: 'FromCompletion',
16
+ anchorDateKey: 'PlannedDate',
17
+ catchUpAutomatically: true,
18
+ endDate: '2026-12-31T23:59:59.000Z',
19
+ count: 10,
20
+ });
21
+ assert.equal(parsed.ruleString, 'FREQ=WEEKLY;INTERVAL=2');
22
+ assert.equal(parsed.scheduleType, 'FromCompletion');
23
+ assert.equal(parsed.anchorDateKey, 'PlannedDate');
24
+ assert.equal(parsed.catchUpAutomatically, true);
25
+ assert.equal(parsed.count, 10);
26
+ });
27
+ test('set_repetition_rule schema rejects invalid scheduleType', () => {
28
+ assert.throws(() => schema.parse({
29
+ taskId: 'abc123',
30
+ scheduleType: 'Sometimes',
31
+ }));
32
+ });
33
+ test('set_repetition_rule schema rejects invalid anchorDateKey', () => {
34
+ assert.throws(() => schema.parse({
35
+ taskId: 'abc123',
36
+ anchorDateKey: 'StartDate',
37
+ }));
38
+ });
39
+ test('set_repetition_rule schema accepts clear flag', () => {
40
+ const parsed = schema.parse({ taskId: 'abc123', clear: true });
41
+ assert.equal(parsed.clear, true);
42
+ });
@@ -2,6 +2,7 @@ import { executeAppleScript } from '../../utils/scriptExecution.js';
2
2
  import { appleScriptDateCode } from '../../utils/dateFormatter.js';
3
3
  import { buildAppleScriptJsonHelpers } from '../../utils/appleScriptJson.js';
4
4
  import { escapeAppleScriptString } from '../../utils/appleScriptString.js';
5
+ import { applyTagsExclusive } from './applyTagsExclusive.js';
5
6
  export function buildTagAssignmentScript(tags, targetVar) {
6
7
  if (!tags || tags.length === 0) {
7
8
  return '';
@@ -149,11 +150,28 @@ export async function addOmniFocusTask(params) {
149
150
  // Parse the result
150
151
  try {
151
152
  const result = JSON.parse(stdout);
152
- // Return the result
153
+ if (!result.success) {
154
+ return {
155
+ success: false,
156
+ error: result.error
157
+ };
158
+ }
159
+ const taskId = result.taskId;
160
+ const tags = params.tags || [];
161
+ const exclusiveTags = params.exclusiveTags !== false;
162
+ // If tags were applied and exclusivity is enabled, enforce mutually exclusive groups.
163
+ if (taskId && tags.length > 0 && exclusiveTags) {
164
+ const exclusivityResult = await applyTagsExclusive(taskId, tags, 'add');
165
+ return {
166
+ success: true,
167
+ taskId,
168
+ removedSiblings: exclusivityResult.removedSiblings,
169
+ missingTags: exclusivityResult.missing,
170
+ };
171
+ }
153
172
  return {
154
- success: result.success,
155
- taskId: result.taskId,
156
- error: result.error
173
+ success: true,
174
+ taskId,
157
175
  };
158
176
  }
159
177
  catch (parseError) {
@@ -2,6 +2,7 @@ import { executeAppleScript } from '../../utils/scriptExecution.js';
2
2
  import { appleScriptDateCode } from '../../utils/dateFormatter.js';
3
3
  import { buildAppleScriptJsonHelpers } from '../../utils/appleScriptJson.js';
4
4
  import { escapeAppleScriptString } from '../../utils/appleScriptString.js';
5
+ import { applyTagsExclusive } from './applyTagsExclusive.js';
5
6
  /**
6
7
  * Generate pure AppleScript for project creation
7
8
  */
@@ -99,11 +100,28 @@ export async function addProject(params) {
99
100
  // Parse the result
100
101
  try {
101
102
  const result = JSON.parse(stdout);
102
- // Return the result
103
+ if (!result.success) {
104
+ return {
105
+ success: false,
106
+ error: result.error
107
+ };
108
+ }
109
+ const projectId = result.projectId;
110
+ const tags = params.tags || [];
111
+ const exclusiveTags = params.exclusiveTags !== false;
112
+ // If tags were applied and exclusivity is enabled, enforce mutually exclusive groups.
113
+ if (projectId && tags.length > 0 && exclusiveTags) {
114
+ const exclusivityResult = await applyTagsExclusive(projectId, tags, 'add');
115
+ return {
116
+ success: true,
117
+ projectId,
118
+ removedSiblings: exclusivityResult.removedSiblings,
119
+ missingTags: exclusivityResult.missing,
120
+ };
121
+ }
103
122
  return {
104
- success: result.success,
105
- projectId: result.projectId,
106
- error: result.error
123
+ success: true,
124
+ projectId,
107
125
  };
108
126
  }
109
127
  catch (parseError) {
@@ -0,0 +1,37 @@
1
+ import { executeOmniFocusScript } from '../../utils/scriptExecution.js';
2
+ /**
3
+ * Apply tags to a task while respecting mutually exclusive tag groups.
4
+ *
5
+ * When a tag belongs to a mutually exclusive group (its parent tag has
6
+ * childrenAreMutuallyExclusive === true), sibling tags from that group are
7
+ * removed before the new tag is added.
8
+ *
9
+ * @param taskId OmniFocus task primary key
10
+ * @param tagNames Tag names to apply
11
+ * @param mode 'add' preserves existing tags; 'replace' clears existing tags first
12
+ */
13
+ export async function applyTagsExclusive(taskId, tagNames, mode = 'add') {
14
+ const result = await executeOmniFocusScript('@applyTagsExclusive.js', {
15
+ taskId,
16
+ tagNames,
17
+ mode,
18
+ });
19
+ if (typeof result === 'string') {
20
+ try {
21
+ return JSON.parse(result);
22
+ }
23
+ catch {
24
+ return { success: false, error: result };
25
+ }
26
+ }
27
+ return result;
28
+ }
29
+ /**
30
+ * Pure decision helper for tests: determine which sibling tags should be removed
31
+ * when applying a tag from a mutually exclusive group.
32
+ */
33
+ export function siblingsToRemove(parentExclusive, siblingNames, currentTagNames, targetTagName) {
34
+ if (!parentExclusive)
35
+ return [];
36
+ return siblingNames.filter(name => name !== targetTagName && currentTagNames.includes(name));
37
+ }
@@ -0,0 +1,19 @@
1
+ import assert from 'node:assert/strict';
2
+ import test from 'node:test';
3
+ import { siblingsToRemove } from './applyTagsExclusive.js';
4
+ test('siblingsToRemove returns empty when group is not exclusive', () => {
5
+ const result = siblingsToRemove(false, ['High', 'Medium', 'Low'], ['High'], 'Medium');
6
+ assert.deepEqual(result, []);
7
+ });
8
+ test('siblingsToRemove returns empty when tag has no parent group', () => {
9
+ const result = siblingsToRemove(true, [], ['High'], 'Medium');
10
+ assert.deepEqual(result, []);
11
+ });
12
+ test('siblingsToRemove removes current siblings but not target', () => {
13
+ const result = siblingsToRemove(true, ['High', 'Medium', 'Low'], ['High', 'Low'], 'Medium');
14
+ assert.deepEqual(result, ['High', 'Low']);
15
+ });
16
+ test('siblingsToRemove ignores siblings not currently applied', () => {
17
+ const result = siblingsToRemove(true, ['High', 'Medium', 'Low'], ['Low'], 'Medium');
18
+ assert.deepEqual(result, ['Low']);
19
+ });
@@ -2,6 +2,7 @@ import { executeAppleScript } from '../../utils/scriptExecution.js';
2
2
  import { buildAppleScriptJsonHelpers } from '../../utils/appleScriptJson.js';
3
3
  import { appleScriptDateCode } from '../../utils/dateFormatter.js';
4
4
  import { escapeAppleScriptString } from '../../utils/appleScriptString.js';
5
+ import { applyTagsExclusive } from './applyTagsExclusive.js';
5
6
  function hasTaskMoveTarget(params) {
6
7
  return Boolean(params.newProjectId ||
7
8
  params.newProjectName ||
@@ -483,13 +484,44 @@ export async function editItem(params) {
483
484
  // Parse the result
484
485
  try {
485
486
  const result = JSON.parse(stdout);
486
- // Return the result
487
+ if (!result.success) {
488
+ return {
489
+ success: false,
490
+ error: result.error
491
+ };
492
+ }
493
+ const itemId = result.id;
494
+ const exclusiveTags = params.exclusiveTags !== false;
495
+ // Enforce mutually exclusive tag groups when tags were added or replaced.
496
+ if (itemId && exclusiveTags && params.itemType === 'task') {
497
+ if (params.replaceTags && params.replaceTags.length > 0) {
498
+ const exclusivityResult = await applyTagsExclusive(itemId, params.replaceTags, 'replace');
499
+ return {
500
+ success: true,
501
+ id: result.id,
502
+ name: result.name,
503
+ changedProperties: result.changedProperties,
504
+ removedSiblings: exclusivityResult.removedSiblings,
505
+ missingTags: exclusivityResult.missing,
506
+ };
507
+ }
508
+ if (params.addTags && params.addTags.length > 0) {
509
+ const exclusivityResult = await applyTagsExclusive(itemId, params.addTags, 'add');
510
+ return {
511
+ success: true,
512
+ id: result.id,
513
+ name: result.name,
514
+ changedProperties: result.changedProperties,
515
+ removedSiblings: exclusivityResult.removedSiblings,
516
+ missingTags: exclusivityResult.missing,
517
+ };
518
+ }
519
+ }
487
520
  return {
488
- success: result.success,
521
+ success: true,
489
522
  id: result.id,
490
523
  name: result.name,
491
524
  changedProperties: result.changedProperties,
492
- error: result.error
493
525
  };
494
526
  }
495
527
  catch (parseError) {
@@ -112,3 +112,25 @@ test('generateAppleScript escapes edit responses through AppleScript helper', ()
112
112
  assert.match(script, /my jsonEscape\(changedPropsText\)/);
113
113
  assert.match(script, /my jsonEscape\(errorMessage\)/);
114
114
  });
115
+ test('generateAppleScript sets planned date from preamble variable', () => {
116
+ const script = generateAppleScript({
117
+ id: 'task-123',
118
+ itemType: 'task',
119
+ newPlannedDate: '2026-03-15'
120
+ });
121
+ const tellIndex = script.indexOf('tell application "OmniFocus"');
122
+ const preambleIndex = script.indexOf('set newPlannedDateValue to current date');
123
+ assert.ok(preambleIndex > -1 && preambleIndex < tellIndex);
124
+ assert.match(script, /set planned date of foundItem to newPlannedDateValue/);
125
+ assert.match(script, /set end of changedProperties to "planned date"/);
126
+ });
127
+ test('generateAppleScript clears planned date with missing value', () => {
128
+ const script = generateAppleScript({
129
+ id: 'task-123',
130
+ itemType: 'task',
131
+ newPlannedDate: ''
132
+ });
133
+ assert.match(script, /set planned date of foundItem to missing value/);
134
+ assert.match(script, /set end of changedProperties to "planned date"/);
135
+ assert.doesNotMatch(script, /set newPlannedDateValue to current date/);
136
+ });
@@ -0,0 +1,85 @@
1
+ import { executeOmniFocusScript } from '../../utils/scriptExecution.js';
2
+ /**
3
+ * Build the ICS rule string from components. Exposed for testing.
4
+ */
5
+ export function buildRepetitionRuleString(params) {
6
+ let ruleString = params.ruleString || 'FREQ=WEEKLY';
7
+ ruleString = ruleString.trim().replace(/^RRULE:/i, '');
8
+ ruleString = ruleString.replace(/;?(COUNT|UNTIL)=[^;]*/gi, '');
9
+ if (params.count && params.count > 0) {
10
+ ruleString += `;COUNT=${params.count}`;
11
+ }
12
+ if (params.endDate) {
13
+ const until = toICSDateTime(params.endDate);
14
+ if (until) {
15
+ ruleString += `;UNTIL=${until}`;
16
+ }
17
+ }
18
+ return ruleString;
19
+ }
20
+ function toICSDateTime(isoDate) {
21
+ const date = new Date(isoDate);
22
+ if (Number.isNaN(date.getTime()))
23
+ return null;
24
+ const pad = (n) => String(n).padStart(2, '0');
25
+ return (date.getUTCFullYear() +
26
+ pad(date.getUTCMonth() + 1) +
27
+ pad(date.getUTCDate()) +
28
+ 'T' +
29
+ pad(date.getUTCHours()) +
30
+ pad(date.getUTCMinutes()) +
31
+ pad(date.getUTCSeconds()) +
32
+ 'Z');
33
+ }
34
+ export function validateSetRepetitionRuleParams(params) {
35
+ if (!params.taskId) {
36
+ return { valid: false, error: 'taskId is required' };
37
+ }
38
+ if (params.clear === true) {
39
+ return { valid: true };
40
+ }
41
+ if (params.scheduleType && !['Regularly', 'FromCompletion'].includes(params.scheduleType)) {
42
+ return { valid: false, error: 'scheduleType must be Regularly or FromCompletion' };
43
+ }
44
+ if (params.anchorDateKey && !['DueDate', 'DeferDate', 'PlannedDate'].includes(params.anchorDateKey)) {
45
+ return { valid: false, error: 'anchorDateKey must be DueDate, DeferDate, or PlannedDate' };
46
+ }
47
+ if (params.count !== undefined && (typeof params.count !== 'number' || params.count <= 0)) {
48
+ return { valid: false, error: 'count must be a positive number' };
49
+ }
50
+ if (params.endDate) {
51
+ const date = new Date(params.endDate);
52
+ if (Number.isNaN(date.getTime())) {
53
+ return { valid: false, error: 'endDate must be a valid ISO date string' };
54
+ }
55
+ }
56
+ return { valid: true };
57
+ }
58
+ /**
59
+ * Set, update, or clear the repetition rule on an OmniFocus task.
60
+ */
61
+ export async function setRepetitionRule(params) {
62
+ const validation = validateSetRepetitionRuleParams(params);
63
+ if (!validation.valid) {
64
+ return { success: false, error: validation.error };
65
+ }
66
+ const result = await executeOmniFocusScript('@setRepetitionRule.js', {
67
+ taskId: params.taskId,
68
+ ruleString: params.ruleString,
69
+ scheduleType: params.scheduleType,
70
+ anchorDateKey: params.anchorDateKey,
71
+ catchUpAutomatically: params.catchUpAutomatically,
72
+ endDate: params.endDate,
73
+ count: params.count,
74
+ clear: params.clear,
75
+ });
76
+ if (typeof result === 'string') {
77
+ try {
78
+ return JSON.parse(result);
79
+ }
80
+ catch {
81
+ return { success: false, error: result };
82
+ }
83
+ }
84
+ return result;
85
+ }