@1agents/dsh-plugin-todo 0.1.0 → 0.1.2

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.
package/README.md CHANGED
@@ -18,12 +18,21 @@ npm test
18
18
 
19
19
  第一次读取会弹出「提醒事项」和「日历」的权限。如果没弹出,到「系统设置 → 隐私与安全性」里允许 `IosAgenda.app`(`work.1agents.ios-agenda`)。
20
20
 
21
+ ### 为什么必须经过系统启动器
22
+
23
+ macOS 的隐私授权按「责任进程」判定,而不是看实际读数据的是谁。宿主直接 `spawn` 包内的二进制时,责任进程是整个 DSH,日历权限会被静默判成 `notDetermined`:系统既不弹框,也不会读成功。
24
+
25
+ 所以页面和 MCP 都改成先用 `open -W -a IosAgenda.app --args call-file …` 交给 LaunchServices 起一个自己,这个进程才是自己的责任进程,授权和读取都正常。副作用有两条:
26
+
27
+ - 需要图形登录会话,没有 `open` 可用的环境(例如纯 ssh)跑不了。
28
+ - 每次调用要经 LaunchServices 起一个实例。首次约 3 秒,之后约 150 毫秒。
29
+
21
30
  ## 安装
22
31
 
23
32
  前提:Apple 芯片的 macOS、Node.js 20 或以上、已安装的 DeepSeek Harness。提醒事项和日历只在这台 Mac 上读写。当前发布的原生程序是 arm64,Intel Mac 不能安装。
24
33
 
25
34
  ```sh
26
- dsh plugin --profile web add @1agents/dsh-plugin-todo@0.1.0
35
+ dsh plugin --profile web add @1agents/dsh-plugin-todo@0.1.2
27
36
  ```
28
37
 
29
38
  装完后重启 DSH。左侧栏「历史会话」上方出现「日程」。Host 启动时会把 MCP 登记到 `127.0.0.1:36908`。网关没在跑时,页面仍可用,Agent 搜索不到工具。当前这个对话窗口走的是 desktop profile;要在 `dsh web`(默认 `http://127.0.0.1:3080`)里看到,安装目标是 web profile。
@@ -13,9 +13,9 @@
13
13
  <key>CFBundlePackageType</key>
14
14
  <string>APPL</string>
15
15
  <key>CFBundleVersion</key>
16
- <string>0.1.0</string>
16
+ <string>0.1.2</string>
17
17
  <key>CFBundleShortVersionString</key>
18
- <string>0.1.0</string>
18
+ <string>0.1.2</string>
19
19
  <key>LSUIElement</key>
20
20
  <true/>
21
21
  <key>NSCalendarsUsageDescription</key>
package/dist/client.js CHANGED
@@ -30,7 +30,7 @@ var import_react = require("react");
30
30
  var SERVICE = "iosAgenda";
31
31
  var PACKAGE = "@1agents/dsh-plugin-todo";
32
32
  var PANEL_ID = "ios-agenda";
33
- var METHODS = ["snapshot", "createReminder", "completeReminder", "deleteReminder", "createEvent", "deleteEvent"];
33
+ var METHODS = ["authorize", "snapshot", "createReminder", "completeReminder", "deleteReminder", "createEvent", "deleteEvent"];
34
34
  function objectOf(value) {
35
35
  if (!value || typeof value !== "object" || Array.isArray(value)) return {};
36
36
  return value;
@@ -77,6 +77,14 @@ var zh = {
77
77
  complete: "\u5B8C\u6210",
78
78
  remove: "\u5220\u9664",
79
79
  permission: "\u9700\u8981\u5728\u7CFB\u7EDF\u8BBE\u7F6E\u91CC\u5141\u8BB8 IosAgenda.app\uFF08work.1agents.ios-agenda\uFF09\u8BBF\u95EE\u63D0\u9192\u4E8B\u9879\u548C\u65E5\u5386\u3002",
80
+ authorize: "\u6388\u6743",
81
+ openSettings: "\u6253\u5F00\u7CFB\u7EDF\u8BBE\u7F6E",
82
+ authTitle: "\u9700\u8981\u8BBF\u95EE\u63D0\u9192\u4E8B\u9879\u548C\u65E5\u5386",
83
+ authBody: "\u70B9\u6388\u6743\u540E\u4F1A\u5F39\u51FA\u7CFB\u7EDF\u8BF7\u6C42\u3002\u5982\u679C\u4E4B\u524D\u62D2\u7EDD\u8FC7\uFF0C\u4F1A\u6253\u5F00\u7CFB\u7EDF\u8BBE\u7F6E\u91CC\u7684\u5BF9\u5E94\u5F00\u5173\u3002",
84
+ authGranted: "\u5DF2\u5141\u8BB8",
85
+ authNeeded: "\u672A\u5141\u8BB8",
86
+ authSettings: "\u7CFB\u7EDF\u8BBE\u7F6E\u5DF2\u6253\u5F00\u3002\u6253\u5F00\u5F00\u5173\u540E\u70B9\u5237\u65B0\u3002",
87
+ reminders: "\u63D0\u9192\u4E8B\u9879",
80
88
  allDay: "\u5168\u5929",
81
89
  continues: "\u7EED",
82
90
  overdue: "\u903E\u671F",
@@ -104,6 +112,14 @@ var en = {
104
112
  complete: "Complete",
105
113
  remove: "Delete",
106
114
  permission: "Allow IosAgenda.app (work.1agents.ios-agenda) to access Reminders and Calendar in System Settings.",
115
+ authorize: "Allow access",
116
+ openSettings: "Open System Settings",
117
+ authTitle: "Reminders and Calendar access",
118
+ authBody: "Allow access to show the system prompt. If access was denied, this opens the matching switch in System Settings.",
119
+ authGranted: "Allowed",
120
+ authNeeded: "Not allowed",
121
+ authSettings: "System Settings is open. Turn the switch on, then refresh.",
122
+ reminders: "Reminders",
107
123
  allDay: "All day",
108
124
  continues: "Continues",
109
125
  overdue: "Overdue",
@@ -140,6 +156,12 @@ function readViewPreference() {
140
156
  return empty;
141
157
  }
142
158
  }
159
+ function accessGranted(status) {
160
+ return status === "fullAccess" || status === "authorized";
161
+ }
162
+ function accessBlocked(status) {
163
+ return status === "denied" || status === "restricted" || status === "writeOnly";
164
+ }
143
165
  function soleAccent(colors) {
144
166
  const unique = new Set(colors.filter(Boolean));
145
167
  return unique.size === 1 ? [...unique][0] : "";
@@ -482,6 +504,7 @@ function AgendaPage({ t, agenda }) {
482
504
  const [data, setData] = (0, import_react.useState)(null);
483
505
  const [loadedKey, setLoadedKey] = (0, import_react.useState)("");
484
506
  const [error, setError] = (0, import_react.useState)("");
507
+ const [auth, setAuth] = (0, import_react.useState)(null);
485
508
  const [busy, setBusy] = (0, import_react.useState)(false);
486
509
  const [revision, setRevision] = (0, import_react.useState)(0);
487
510
  const [hiddenLists, setHiddenLists] = (0, import_react.useState)(() => new Set(viewPreference.hiddenLists));
@@ -504,9 +527,20 @@ function AgendaPage({ t, agenda }) {
504
527
  if (!active || requestId !== requestRef.current) return;
505
528
  setBusy(false);
506
529
  if (!result.ok) {
507
- setError(result.error?.code === "ACCESS_DENIED" ? t("permission") : result.error?.message || t("unavailable"));
530
+ if (result.error?.code === "ACCESS_DENIED") {
531
+ setAuth({
532
+ reminders: result.error.access?.reminders || "notDetermined",
533
+ events: result.error.access?.events || "notDetermined",
534
+ openedSettings: false
535
+ });
536
+ setError("");
537
+ return;
538
+ }
539
+ setAuth(null);
540
+ setError(result.error?.message || t("unavailable"));
508
541
  return;
509
542
  }
543
+ setAuth(null);
510
544
  setError("");
511
545
  setData(result.data);
512
546
  setLoadedKey(range.key);
@@ -526,6 +560,26 @@ function AgendaPage({ t, agenda }) {
526
560
  } catch {
527
561
  }
528
562
  }, [mode, hiddenLists, hiddenCalendars]);
563
+ async function authorize() {
564
+ setBusy(true);
565
+ const result = await invoke(agenda, "authorize", {});
566
+ setBusy(false);
567
+ if (!result.ok) {
568
+ setError(result.error?.message || t("unavailable"));
569
+ return;
570
+ }
571
+ const report = result.data?.access ?? {};
572
+ if (result.data?.granted) {
573
+ setAuth(null);
574
+ setRevision((value) => value + 1);
575
+ return;
576
+ }
577
+ setAuth({
578
+ reminders: report.reminders || "notDetermined",
579
+ events: report.events || "notDetermined",
580
+ openedSettings: Boolean(result.data?.openedSettings)
581
+ });
582
+ }
529
583
  function selectDay(date) {
530
584
  const day = startOfDay(date);
531
585
  setCursor(day);
@@ -683,12 +737,26 @@ function AgendaPage({ t, agenda }) {
683
737
  ] }),
684
738
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ia-refresh", onClick: () => setRevision((value) => value + 1), disabled: busy, children: t("refresh") })
685
739
  ] }),
740
+ auth && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "ia-auth", children: [
741
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { children: t("authTitle") }),
742
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t("authBody") }),
743
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ia-auth-row", children: [
744
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: t("reminders") }),
745
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: accessGranted(auth.reminders) ? t("authGranted") : t("authNeeded") })
746
+ ] }),
747
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ia-auth-row", children: [
748
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: t("calendars") }),
749
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: accessGranted(auth.events) ? t("authGranted") : t("authNeeded") })
750
+ ] }),
751
+ auth.openedSettings && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "ia-auth-hint", children: t("authSettings") }),
752
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: authorize, disabled: busy, children: accessBlocked(auth.reminders) || accessBlocked(auth.events) ? t("openSettings") : t("authorize") })
753
+ ] }),
686
754
  error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "ios-agenda-error", role: "alert", children: error }),
687
- !ready && !error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "ios-agenda-muted", children: t("loading") }),
688
- ready && mode === "day" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("section", { className: "ia-day-list", children: dayList.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AgendaBlocks, { blocks: dayList, overdueIds, listColors, calendarColors, t, busy, onComplete: (id) => submit("completeReminder", { id, completed: true }, () => {
755
+ !ready && !error && !auth && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "ios-agenda-muted", children: t("loading") }),
756
+ ready && !auth && mode === "day" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("section", { className: "ia-day-list", children: dayList.length ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AgendaBlocks, { blocks: dayList, overdueIds, listColors, calendarColors, t, busy, onComplete: (id) => submit("completeReminder", { id, completed: true }, () => {
689
757
  }), onDelete: (method, id) => submit(method, { id }, () => {
690
758
  }) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "ios-agenda-muted", children: t("emptyDay") }) }),
691
- ready && mode === "week" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "ia-week-scroll", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "ia-week", children: weekDays.map((day) => {
759
+ ready && !auth && mode === "week" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "ia-week-scroll", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "ia-week", children: weekDays.map((day) => {
692
760
  const blocks = dayBlocks(day, events, reminders);
693
761
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: sameDay(day, cursor) ? "ia-week-col is-selected" : "ia-week-col", children: [
694
762
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { type: "button", className: sameDay(day, today) ? "ia-week-head is-today" : "ia-week-head", onClick: () => selectDay(day), children: [
@@ -700,7 +768,7 @@ function AgendaPage({ t, agenda }) {
700
768
  }) })
701
769
  ] }, dayKey(day));
702
770
  }) }) }),
703
- ready && overdueItems.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "ia-group", ref: overdueRef, children: [
771
+ ready && !auth && overdueItems.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "ia-group", ref: overdueRef, children: [
704
772
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { children: t("overdue") }),
705
773
  overdueItems.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
706
774
  AgendaRow,
@@ -721,7 +789,7 @@ function AgendaPage({ t, agenda }) {
721
789
  `overdue:${item.id}`
722
790
  ))
723
791
  ] }),
724
- ready && undatedItems.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "ia-group", ref: undatedRef, children: [
792
+ ready && !auth && undatedItems.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "ia-group", ref: undatedRef, children: [
725
793
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { children: t("undated") }),
726
794
  undatedItems.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
727
795
  AgendaRow,
@@ -742,7 +810,7 @@ function AgendaPage({ t, agenda }) {
742
810
  ))
743
811
  ] })
744
812
  ] }),
745
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { className: "ia-composer", onSubmit: (event) => {
813
+ !auth && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { className: "ia-composer", onSubmit: (event) => {
746
814
  event.preventDefault();
747
815
  if (!reminderTitle.trim()) return;
748
816
  submit("createReminder", { title: reminderTitle.trim() }, () => setReminderTitle(""));
@@ -751,7 +819,7 @@ function AgendaPage({ t, agenda }) {
751
819
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "submit", disabled: busy || !reminderTitle.trim(), children: t("add") }),
752
820
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => eventOpen ? setEventOpen(false) : openEvent(), children: t("newEvent") })
753
821
  ] }),
754
- eventOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { className: "ia-event-form", onSubmit: (event) => {
822
+ !auth && eventOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { className: "ia-event-form", onSubmit: (event) => {
755
823
  event.preventDefault();
756
824
  if (!eventTitle.trim() || !eventStart || !eventEnd) return;
757
825
  submit("createEvent", {
@@ -850,6 +918,11 @@ var css = `
850
918
  .ia-composer { border-top: 1px solid var(--dsw-alias-border-default); }
851
919
  .ia-event-form { padding-top: 0; padding-bottom: 14px; }
852
920
  .ia-composer input, .ia-event-form input { flex: 1; min-width: 0; border: 1px solid var(--dsw-alias-border-default); background: var(--dsw-alias-bg-layer-1); border-radius: 8px; padding: 8px 10px; }
921
+ .ia-auth { max-width: 440px; margin: 12px 0 20px; padding: 16px; border: 1px solid var(--dsw-alias-border-default); border-radius: 12px; background: var(--dsw-alias-bg-layer-1); }
922
+ .ia-auth h2 { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
923
+ .ia-auth p, .ia-auth-hint { margin: 0 0 12px; color: var(--dsw-alias-label-secondary); }
924
+ .ia-auth-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; }
925
+ .ia-auth button { margin-top: 8px; border: none; border-radius: 8px; padding: 8px 14px; cursor: pointer; background: var(--dsw-alias-state-business-primary); color: var(--dsw-alias-bg-base); }
853
926
  .ios-agenda-error { margin: 0 0 12px; padding: 8px 10px; border-radius: 8px; background: var(--dsw-alias-bg-layer-1); }
854
927
  .ios-agenda input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--dsw-alias-state-business-primary); }
855
928
  .ia-filter-row input[type="checkbox"] { flex: none; accent-color: var(--ia-swatch, var(--dsw-alias-state-business-primary)); }
package/dist/host.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/contract.js
2
2
  var SERVICE = "iosAgenda";
3
3
  var PACKAGE = "@1agents/dsh-plugin-todo";
4
- var METHODS = ["snapshot", "createReminder", "completeReminder", "deleteReminder", "createEvent", "deleteEvent"];
4
+ var METHODS = ["authorize", "snapshot", "createReminder", "completeReminder", "deleteReminder", "createEvent", "deleteEvent"];
5
5
  function objectOf(value) {
6
6
  if (!value || typeof value !== "object" || Array.isArray(value)) return {};
7
7
  return value;
@@ -34,60 +34,123 @@ var contribution = {
34
34
  // src/native.js
35
35
  import { spawn } from "node:child_process";
36
36
  import { constants } from "node:fs";
37
- import { access } from "node:fs/promises";
37
+ import { access, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
38
+ import { tmpdir } from "node:os";
39
+ import { join, resolve } from "node:path";
38
40
  import { fileURLToPath } from "node:url";
39
41
  function binaryPath(from = import.meta.url) {
40
42
  return fileURLToPath(new URL("./IosAgenda.app/Contents/MacOS/ios-agenda", from));
41
43
  }
44
+ function appBundle(binary2) {
45
+ return resolve(binary2, "../../..");
46
+ }
47
+ function timeoutFor(method) {
48
+ return method === "authorize" || method === "snapshot" ? 12e4 : 2e4;
49
+ }
50
+ function parseResult(output, stderr) {
51
+ const line = String(output).trim().split("\n").findLast((item) => item.trim());
52
+ if (!line) {
53
+ return { ok: false, error: { code: "BAD_RESPONSE", message: stderr.trim() || "\u539F\u751F\u7A0B\u5E8F\u6CA1\u6709\u8FD4\u56DE JSON" } };
54
+ }
55
+ try {
56
+ return JSON.parse(line);
57
+ } catch {
58
+ return { ok: false, error: { code: "BAD_RESPONSE", message: stderr.trim() || line } };
59
+ }
60
+ }
42
61
  async function callNative(binary2, method, input = {}, signal) {
43
62
  await access(binary2, constants.X_OK).catch(() => {
44
63
  throw Object.assign(new Error("\u8FD8\u6CA1\u6709\u6784\u5EFA IosAgenda.app\u3002\u5148\u8FD0\u884C npm run build\u3002"), { code: "NOT_BUILT" });
45
64
  });
46
- return await new Promise((resolve) => {
47
- const child = spawn(binary2, ["call", method], { stdio: ["pipe", "pipe", "pipe"] });
48
- let stdout = "";
49
- let stderr = "";
50
- let settled = false;
51
- const finish = (result) => {
52
- if (settled) return;
53
- settled = true;
54
- clearTimeout(timer);
55
- resolve(result);
56
- };
57
- const timer = setTimeout(() => {
58
- child.kill("SIGTERM");
59
- finish({ ok: false, error: { code: "TIMEOUT", message: "\u8BFB\u53D6\u65E5\u5386\u6216\u63D0\u9192\u4E8B\u9879\u8D85\u65F6\u3002\u5982\u679C\u7CFB\u7EDF\u6B63\u5728\u8BE2\u95EE\u6743\u9650\uFF0C\u5141\u8BB8\u540E\u518D\u8BD5\u3002" } });
60
- }, 2e4);
61
- child.stdout.setEncoding("utf8");
62
- child.stderr.setEncoding("utf8");
63
- child.stdout.on("data", (chunk) => {
64
- stdout += chunk;
65
- });
66
- child.stderr.on("data", (chunk) => {
67
- stderr += chunk;
65
+ const bundle = appBundle(binary2);
66
+ await access(bundle, constants.F_OK).catch(() => {
67
+ throw Object.assign(new Error("\u627E\u4E0D\u5230 IosAgenda.app \u5305\uFF0C\u65E0\u6CD5\u901A\u8FC7\u7CFB\u7EDF\u542F\u52A8\u5668\u6388\u6743\u3002\u5148\u8FD0\u884C npm run build\u3002"), { code: "NOT_BUILT" });
68
+ });
69
+ const workdir = await mkdtemp(join(tmpdir(), "ios-agenda-"));
70
+ const inputPath = join(workdir, "input.json");
71
+ const outputPath = join(workdir, "output.json");
72
+ const errorPath = join(workdir, "stderr.txt");
73
+ await writeFile(inputPath, JSON.stringify(input ?? {}), "utf8");
74
+ try {
75
+ return await new Promise((resolveResult) => {
76
+ const child = spawn("open", [
77
+ "-W",
78
+ "-n",
79
+ "-a",
80
+ bundle,
81
+ "--stdout",
82
+ outputPath,
83
+ "--stderr",
84
+ errorPath,
85
+ "--args",
86
+ "call-file",
87
+ method,
88
+ inputPath
89
+ ], { stdio: ["ignore", "pipe", "pipe"] });
90
+ let stderr = "";
91
+ let settled = false;
92
+ let timer = null;
93
+ const finish = async (result) => {
94
+ if (settled) return;
95
+ settled = true;
96
+ if (timer) clearTimeout(timer);
97
+ resolveResult(result);
98
+ };
99
+ timer = setTimeout(() => {
100
+ child.kill("SIGTERM");
101
+ const cleanup = spawn("pkill", ["-f", binary2], { stdio: "ignore" });
102
+ cleanup.on("error", () => {
103
+ });
104
+ cleanup.on("close", () => {
105
+ finish({ ok: false, error: { code: "TIMEOUT", message: "\u8C03\u7528\u672C\u673A\u65E5\u5386\u8D85\u65F6\u3002\u5982\u679C\u7CFB\u7EDF\u6B63\u5728\u8BE2\u95EE\u6743\u9650\uFF0C\u5141\u8BB8\u540E\u518D\u8BD5\u3002" } });
106
+ });
107
+ }, timeoutFor(method));
108
+ child.stderr.setEncoding("utf8");
109
+ child.stderr.on("data", (chunk) => {
110
+ stderr += chunk;
111
+ });
112
+ child.on("error", (error) => finish({ ok: false, error: { code: "SPAWN", message: error.message } }));
113
+ child.on("close", async (code) => {
114
+ let output = "";
115
+ try {
116
+ output = await readFile(outputPath, "utf8");
117
+ } catch {
118
+ const openFailed = code !== 0 || stderr.trim();
119
+ return finish({
120
+ ok: false,
121
+ error: {
122
+ code: "SPAWN",
123
+ message: openFailed ? `\u7CFB\u7EDF\u542F\u52A8\u5668\u6CA1\u80FD\u62C9\u8D77 IosAgenda.app\uFF1A${stderr.trim() || `\u9000\u51FA\u7801 ${code}`}` : "\u539F\u751F\u7A0B\u5E8F\u6CA1\u6709\u5199\u51FA\u7ED3\u679C"
124
+ }
125
+ });
126
+ }
127
+ let logged = stderr;
128
+ try {
129
+ logged = await readFile(errorPath, "utf8");
130
+ } catch {
131
+ }
132
+ finish(parseResult(output, logged));
133
+ });
134
+ signal?.addEventListener("abort", () => {
135
+ child.kill("SIGTERM");
136
+ spawn("pkill", ["-f", binary2], { stdio: "ignore" }).on("error", () => {
137
+ });
138
+ }, { once: true });
68
139
  });
69
- child.on("error", (error) => finish({ ok: false, error: { code: "SPAWN", message: error.message } }));
70
- child.on("close", () => {
71
- const line = stdout.trim().split("\n").findLast((item) => item.trim());
72
- try {
73
- finish(line ? JSON.parse(line) : { ok: false, error: { code: "BAD_RESPONSE", message: stderr.trim() || "\u539F\u751F\u7A0B\u5E8F\u6CA1\u6709\u8FD4\u56DE JSON" } });
74
- } catch {
75
- finish({ ok: false, error: { code: "BAD_RESPONSE", message: stderr.trim() || stdout.trim() || "\u539F\u751F\u7A0B\u5E8F\u8FD4\u56DE\u7684\u4E0D\u662F JSON" } });
76
- }
140
+ } finally {
141
+ await rm(workdir, { recursive: true, force: true }).catch(() => {
77
142
  });
78
- signal?.addEventListener("abort", () => child.kill("SIGTERM"), { once: true });
79
- child.stdin.end(JSON.stringify(input ?? {}));
80
- });
143
+ }
81
144
  }
82
145
 
83
146
  // src/register-mcp.js
84
147
  import { spawn as spawn2 } from "node:child_process";
85
- import { readFile } from "node:fs/promises";
148
+ import { readFile as readFile2 } from "node:fs/promises";
86
149
  import { homedir } from "node:os";
87
- import { join } from "node:path";
150
+ import { join as join2 } from "node:path";
88
151
  var SOURCE = "ios-agenda";
89
152
  function run(args, input) {
90
- return new Promise((resolve) => {
153
+ return new Promise((resolve2) => {
91
154
  const child = spawn2("dreammate-node", args, { stdio: ["pipe", "pipe", "pipe"] });
92
155
  let stdout = "";
93
156
  let stderr = "";
@@ -99,15 +162,15 @@ function run(args, input) {
99
162
  child.stderr.on("data", (chunk) => {
100
163
  stderr += chunk;
101
164
  });
102
- child.on("error", (error) => resolve({ code: 127, stdout, stderr: error.message }));
103
- child.on("close", (code) => resolve({ code: code ?? 1, stdout, stderr }));
165
+ child.on("error", (error) => resolve2({ code: 127, stdout, stderr: error.message }));
166
+ child.on("close", (code) => resolve2({ code: code ?? 1, stdout, stderr }));
104
167
  if (input) child.stdin.end(input);
105
168
  else child.stdin.end();
106
169
  });
107
170
  }
108
171
  async function currentCommand() {
109
172
  try {
110
- const raw = await readFile(join(homedir(), ".1agents", "mcp-sources.json"), "utf8");
173
+ const raw = await readFile2(join2(homedir(), ".1agents", "mcp-sources.json"), "utf8");
111
174
  return JSON.parse(raw)?.mcpServers?.[SOURCE]?.command;
112
175
  } catch {
113
176
  return void 0;
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@1agents/dsh-plugin-todo",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "管理本机已同步的系统提醒事项和日历。页面在 DSH,工具在 dreammate-node MCP。",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "os": ["darwin"],
8
- "cpu": ["arm64"],
7
+ "os": [
8
+ "darwin"
9
+ ],
10
+ "cpu": [
11
+ "arm64"
12
+ ],
9
13
  "repository": {
10
14
  "type": "git",
11
15
  "url": "git+https://github.com/scottzx/DSH-Plugin-Todo.git"
@@ -19,7 +23,7 @@
19
23
  "registry": "https://registry.npmjs.org/"
20
24
  },
21
25
  "bin": {
22
- "ios-agenda": "./bin/ios-agenda.mjs"
26
+ "ios-agenda": "bin/ios-agenda.mjs"
23
27
  },
24
28
  "exports": {
25
29
  ".": "./dist/host.js",
@@ -15,6 +15,6 @@ dreammate-node cli inspect --agent http://127.0.0.1:36908 --service mcp-ios-agen
15
15
  dreammate-node cli invoke --agent http://127.0.0.1:36908 --service mcp-ios-agenda --method agenda_snapshot --params '{}'
16
16
  ```
17
17
 
18
- 方法以 inspect 返回的 Schema 为准。常用的是 `agenda_snapshot`、`agenda_create_reminder`、`agenda_complete_reminder`、`agenda_create_event`。写入后不会立刻出现在手机上,要等 iCloud 同步。
18
+ 方法以 inspect 返回的 Schema 为准。常用的是 `agenda_snapshot`、`agenda_create_reminder`、`agenda_complete_reminder`、`agenda_create_event`。没有访问权限时先调用 `agenda_authorize`:还没决定会弹出系统授权框,已经被拒绝会打开系统设置。写入后不会立刻出现在手机上,要等 iCloud 同步。
19
19
 
20
20
  没有来源时,先在插件仓库执行 `npm run build`,再由 DSH 启用插件,或手动 `dreammate-node mcp add`。来源范围是 `local`。