@1agents/dsh-plugin-todo 0.1.1 → 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.1
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.1</string>
16
+ <string>0.1.2</string>
17
17
  <key>CFBundleShortVersionString</key>
18
- <string>0.1.1</string>
18
+ <string>0.1.2</string>
19
19
  <key>LSUIElement</key>
20
20
  <true/>
21
21
  <key>NSCalendarsUsageDescription</key>
package/dist/host.js CHANGED
@@ -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
- }, method === "authorize" || method === "snapshot" ? 12e4 : 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@1agents/dsh-plugin-todo",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "管理本机已同步的系统提醒事项和日历。页面在 DSH,工具在 dreammate-node MCP。",
5
5
  "type": "module",
6
6
  "license": "MIT",