apple-notes-mcp 2.9.5 → 2.9.7
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 +38 -2
- package/build/index.js +709 -67
- package/native/public-helper/apple-notes-public-helper.swift +257 -0
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -2991,7 +2991,7 @@ var require_compile = __commonJS({
|
|
|
2991
2991
|
const schOrFunc = root.refs[ref];
|
|
2992
2992
|
if (schOrFunc)
|
|
2993
2993
|
return schOrFunc;
|
|
2994
|
-
let _sch =
|
|
2994
|
+
let _sch = resolve7.call(this, root, ref);
|
|
2995
2995
|
if (_sch === void 0) {
|
|
2996
2996
|
const schema = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref];
|
|
2997
2997
|
const { schemaId } = this.opts;
|
|
@@ -3018,7 +3018,7 @@ var require_compile = __commonJS({
|
|
|
3018
3018
|
function sameSchemaEnv(s1, s2) {
|
|
3019
3019
|
return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
|
|
3020
3020
|
}
|
|
3021
|
-
function
|
|
3021
|
+
function resolve7(root, ref) {
|
|
3022
3022
|
let sch;
|
|
3023
3023
|
while (typeof (sch = this.refs[ref]) == "string")
|
|
3024
3024
|
ref = sch;
|
|
@@ -3843,7 +3843,7 @@ var require_fast_uri = __commonJS({
|
|
|
3843
3843
|
}
|
|
3844
3844
|
return uri;
|
|
3845
3845
|
}
|
|
3846
|
-
function
|
|
3846
|
+
function resolve7(baseURI, relativeURI, options) {
|
|
3847
3847
|
const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
|
|
3848
3848
|
const {
|
|
3849
3849
|
parsed: baseParsed,
|
|
@@ -4205,7 +4205,7 @@ var require_fast_uri = __commonJS({
|
|
|
4205
4205
|
var fastUri = {
|
|
4206
4206
|
SCHEMES,
|
|
4207
4207
|
normalize,
|
|
4208
|
-
resolve:
|
|
4208
|
+
resolve: resolve7,
|
|
4209
4209
|
resolveComponent,
|
|
4210
4210
|
equal,
|
|
4211
4211
|
serialize,
|
|
@@ -24465,14 +24465,14 @@ var require_turndown_cjs = __commonJS({
|
|
|
24465
24465
|
} else if (node.nodeType === 1) {
|
|
24466
24466
|
replacement = replacementForNode.call(self, node);
|
|
24467
24467
|
}
|
|
24468
|
-
return
|
|
24468
|
+
return join27(output, replacement);
|
|
24469
24469
|
}, "");
|
|
24470
24470
|
}
|
|
24471
24471
|
function postProcess(output) {
|
|
24472
24472
|
var self = this;
|
|
24473
24473
|
this.rules.forEach(function(rule) {
|
|
24474
24474
|
if (typeof rule.append === "function") {
|
|
24475
|
-
output =
|
|
24475
|
+
output = join27(output, rule.append(self.options));
|
|
24476
24476
|
}
|
|
24477
24477
|
});
|
|
24478
24478
|
return output.replace(/^[\t\r\n]+/, "").replace(/[\t\r\n\s]+$/, "");
|
|
@@ -24484,7 +24484,7 @@ var require_turndown_cjs = __commonJS({
|
|
|
24484
24484
|
if (whitespace.leading || whitespace.trailing) content = content.trim();
|
|
24485
24485
|
return whitespace.leading + rule.replacement(content, node, this.options) + whitespace.trailing;
|
|
24486
24486
|
}
|
|
24487
|
-
function
|
|
24487
|
+
function join27(output, replacement) {
|
|
24488
24488
|
var s1 = trimTrailingNewlines(output);
|
|
24489
24489
|
var s2 = trimLeadingNewlines(replacement);
|
|
24490
24490
|
var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
|
|
@@ -36608,7 +36608,7 @@ var Protocol = class {
|
|
|
36608
36608
|
return;
|
|
36609
36609
|
}
|
|
36610
36610
|
const pollInterval = task2.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1e3;
|
|
36611
|
-
await new Promise((
|
|
36611
|
+
await new Promise((resolve7) => setTimeout(resolve7, pollInterval));
|
|
36612
36612
|
options?.signal?.throwIfAborted();
|
|
36613
36613
|
}
|
|
36614
36614
|
} catch (error2) {
|
|
@@ -36625,7 +36625,7 @@ var Protocol = class {
|
|
|
36625
36625
|
*/
|
|
36626
36626
|
request(request, resultSchema, options) {
|
|
36627
36627
|
const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
|
|
36628
|
-
return new Promise((
|
|
36628
|
+
return new Promise((resolve7, reject) => {
|
|
36629
36629
|
const earlyReject = (error2) => {
|
|
36630
36630
|
reject(error2);
|
|
36631
36631
|
};
|
|
@@ -36703,7 +36703,7 @@ var Protocol = class {
|
|
|
36703
36703
|
if (!parseResult.success) {
|
|
36704
36704
|
reject(parseResult.error);
|
|
36705
36705
|
} else {
|
|
36706
|
-
|
|
36706
|
+
resolve7(parseResult.data);
|
|
36707
36707
|
}
|
|
36708
36708
|
} catch (error2) {
|
|
36709
36709
|
reject(error2);
|
|
@@ -36964,12 +36964,12 @@ var Protocol = class {
|
|
|
36964
36964
|
}
|
|
36965
36965
|
} catch {
|
|
36966
36966
|
}
|
|
36967
|
-
return new Promise((
|
|
36967
|
+
return new Promise((resolve7, reject) => {
|
|
36968
36968
|
if (signal.aborted) {
|
|
36969
36969
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
36970
36970
|
return;
|
|
36971
36971
|
}
|
|
36972
|
-
const timeoutId = setTimeout(
|
|
36972
|
+
const timeoutId = setTimeout(resolve7, interval);
|
|
36973
36973
|
signal.addEventListener("abort", () => {
|
|
36974
36974
|
clearTimeout(timeoutId);
|
|
36975
36975
|
reject(new McpError(ErrorCode.InvalidRequest, "Request cancelled"));
|
|
@@ -38282,7 +38282,7 @@ var McpServer = class {
|
|
|
38282
38282
|
let task = createTaskResult.task;
|
|
38283
38283
|
const pollInterval = task.pollInterval ?? 5e3;
|
|
38284
38284
|
while (task.status !== "completed" && task.status !== "failed" && task.status !== "cancelled") {
|
|
38285
|
-
await new Promise((
|
|
38285
|
+
await new Promise((resolve7) => setTimeout(resolve7, pollInterval));
|
|
38286
38286
|
const updatedTask = await extra.taskStore.getTask(taskId);
|
|
38287
38287
|
if (!updatedTask) {
|
|
38288
38288
|
throw new McpError(ErrorCode.InternalError, `Task ${taskId} not found during polling`);
|
|
@@ -38970,12 +38970,12 @@ var StdioServerTransport = class {
|
|
|
38970
38970
|
this.onclose?.();
|
|
38971
38971
|
}
|
|
38972
38972
|
send(message) {
|
|
38973
|
-
return new Promise((
|
|
38973
|
+
return new Promise((resolve7) => {
|
|
38974
38974
|
const json2 = serializeMessage(message);
|
|
38975
38975
|
if (this._stdout.write(json2)) {
|
|
38976
|
-
|
|
38976
|
+
resolve7();
|
|
38977
38977
|
} else {
|
|
38978
|
-
this._stdout.once("drain",
|
|
38978
|
+
this._stdout.once("drain", resolve7);
|
|
38979
38979
|
}
|
|
38980
38980
|
});
|
|
38981
38981
|
}
|
|
@@ -47328,13 +47328,13 @@ var escapeSegment = escapeFolderName;
|
|
|
47328
47328
|
function resolveFolders(rows) {
|
|
47329
47329
|
const byPk = new Map(rows.map((row) => [row.pk, row]));
|
|
47330
47330
|
const resolved = /* @__PURE__ */ new Map();
|
|
47331
|
-
const
|
|
47331
|
+
const resolve7 = (pk, seen) => {
|
|
47332
47332
|
const cached2 = resolved.get(pk);
|
|
47333
47333
|
if (cached2) return cached2;
|
|
47334
47334
|
const row = byPk.get(pk);
|
|
47335
47335
|
if (!row || seen.has(pk)) return void 0;
|
|
47336
47336
|
seen.add(pk);
|
|
47337
|
-
const parent = row.parent !== null ?
|
|
47337
|
+
const parent = row.parent !== null ? resolve7(row.parent, seen) : void 0;
|
|
47338
47338
|
const name = row.name ?? "";
|
|
47339
47339
|
const path10 = parent ? `${parent.path}/${escapeSegment(name)}` : escapeSegment(name);
|
|
47340
47340
|
const plainPath = parent ? `${parent.plainPath}/${name}` : name;
|
|
@@ -47348,7 +47348,7 @@ function resolveFolders(rows) {
|
|
|
47348
47348
|
resolved.set(pk, info);
|
|
47349
47349
|
return info;
|
|
47350
47350
|
};
|
|
47351
|
-
for (const row of rows)
|
|
47351
|
+
for (const row of rows) resolve7(row.pk, /* @__PURE__ */ new Set());
|
|
47352
47352
|
return resolved;
|
|
47353
47353
|
}
|
|
47354
47354
|
var coreDataMs = (seconds) => seconds === null || !Number.isFinite(seconds) ? void 0 : CORE_DATA_EPOCH_MS2 + seconds * 1e3;
|
|
@@ -50782,11 +50782,13 @@ function escapeMarkdown(text2) {
|
|
|
50782
50782
|
return text2.replace(/[\\`*_[\]<>~|]/g, (char) => `\\${char}`).replace(/&(?=#?[A-Za-z0-9]+;)/g, "&").replace(/==/g, "\\=\\=");
|
|
50783
50783
|
}
|
|
50784
50784
|
function escapeLineStart(line) {
|
|
50785
|
+
if (/^\s*(?:-[ \t]*){3,}$/.test(line)) return line.replace("-", "\\-");
|
|
50785
50786
|
return line.replace(
|
|
50786
|
-
/^(\s*)([
|
|
50787
|
+
/^(\s*)(#{1,6}|[>+-]|\d{1,9}[.)])(?=\s|$)/,
|
|
50787
50788
|
(_, space, marker) => /^\d/.test(marker) ? `${space}${marker.slice(0, -1)}\\${marker.slice(-1)}` : `${space}\\${marker}`
|
|
50788
50789
|
);
|
|
50789
50790
|
}
|
|
50791
|
+
var BLOCK_START_WORD = /^(?:#{1,6}|[-+*]|-+|=+|\d{1,9}[.)])$/;
|
|
50790
50792
|
function linkDestination(url) {
|
|
50791
50793
|
return url.replace(
|
|
50792
50794
|
/[\s()<>]/g,
|
|
@@ -50958,7 +50960,7 @@ function renderLine(block, body, first2, isTitle, counters) {
|
|
|
50958
50960
|
counters[level] = 0;
|
|
50959
50961
|
if (block.style === "checklist") marker = block.checklist?.done ? "- [x]" : "- [ ]";
|
|
50960
50962
|
}
|
|
50961
|
-
return { text: `${indent}${marker} ${body}`, group: "list", quote };
|
|
50963
|
+
return { text: `${indent}${marker} ${escapeLineStart(body)}`, group: "list", quote };
|
|
50962
50964
|
}
|
|
50963
50965
|
function joinLines(lines) {
|
|
50964
50966
|
let out = "";
|
|
@@ -50991,7 +50993,7 @@ function wrapMarkdown(markdown, width) {
|
|
|
50991
50993
|
let current = prefix;
|
|
50992
50994
|
let empty = true;
|
|
50993
50995
|
for (const word of words) {
|
|
50994
|
-
if (!empty && current.length + 1 + word.length > width) {
|
|
50996
|
+
if (!empty && current.length + 1 + word.length > width && !BLOCK_START_WORD.test(word)) {
|
|
50995
50997
|
out.push(current);
|
|
50996
50998
|
current = hang + word;
|
|
50997
50999
|
} else current += (empty ? "" : " ") + word;
|
|
@@ -52495,27 +52497,627 @@ function formatShortcutSetup(report) {
|
|
|
52495
52497
|
return lines.join("\n");
|
|
52496
52498
|
}
|
|
52497
52499
|
|
|
52498
|
-
// src/services/
|
|
52499
|
-
import { spawnSync as
|
|
52500
|
+
// src/services/publicHelper.ts
|
|
52501
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
52502
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
52500
52503
|
import {
|
|
52501
52504
|
chmodSync,
|
|
52502
|
-
existsSync as
|
|
52505
|
+
existsSync as existsSync14,
|
|
52503
52506
|
mkdirSync as mkdirSync6,
|
|
52504
52507
|
mkdtempSync as mkdtempSync5,
|
|
52508
|
+
readFileSync as readFileSync4,
|
|
52505
52509
|
renameSync,
|
|
52506
52510
|
rmSync as rmSync5,
|
|
52507
52511
|
writeFileSync as writeFileSync4
|
|
52508
52512
|
} from "node:fs";
|
|
52509
|
-
import { release as release3 } from "node:os";
|
|
52510
|
-
import { join as join25 } from "node:path";
|
|
52511
|
-
|
|
52512
|
-
// src/services/privateHelper.ts
|
|
52513
|
-
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
52514
|
-
import { createHash as createHash4 } from "node:crypto";
|
|
52515
|
-
import { existsSync as existsSync14, readFileSync as readFileSync4 } from "node:fs";
|
|
52516
|
-
import { homedir as homedir19 } from "node:os";
|
|
52513
|
+
import { homedir as homedir19, release as release3 } from "node:os";
|
|
52517
52514
|
import { dirname as dirname8, join as join24, resolve as resolve5 } from "node:path";
|
|
52518
52515
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
52516
|
+
var PUBLIC_HELPER_PROTOCOL = 1;
|
|
52517
|
+
var PUBLIC_HELPER_DIR_ENV = "APPLE_NOTES_MCP_PUBLIC_HELPER_DIR";
|
|
52518
|
+
var PUBLIC_HELPER_TIMEOUT_ENV = "APPLE_NOTES_MCP_PUBLIC_HELPER_TIMEOUT_MS";
|
|
52519
|
+
var PUBLIC_HELPER_BINARY = "apple-notes-public-helper";
|
|
52520
|
+
var PUBLIC_HELPER_SOURCE = "native/public-helper/apple-notes-public-helper.swift";
|
|
52521
|
+
var PUBLIC_HELPER_MANIFEST = "manifest.json";
|
|
52522
|
+
var PUBLIC_HELPER_SETUP_COMMAND = "apple-notes-mcp setup --public-helper";
|
|
52523
|
+
var PUBLIC_HELPER_ACTIONS = /* @__PURE__ */ new Set(["hello", "decode_drawing"]);
|
|
52524
|
+
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
52525
|
+
var MAX_OUTPUT_BYTES = 256 * 1024 * 1024;
|
|
52526
|
+
var publicManifestSchema = external_exports.object({
|
|
52527
|
+
schemaVersion: external_exports.literal(1),
|
|
52528
|
+
protocolVersion: external_exports.number().int(),
|
|
52529
|
+
sourceSha256: external_exports.string().regex(/^[a-f0-9]{64}$/),
|
|
52530
|
+
binarySha256: external_exports.string().regex(/^[a-f0-9]{64}$/),
|
|
52531
|
+
builtAt: external_exports.string(),
|
|
52532
|
+
osVersion: external_exports.string(),
|
|
52533
|
+
compiler: external_exports.string()
|
|
52534
|
+
});
|
|
52535
|
+
function packageRoot(fromDir = dirname8(fileURLToPath2(import.meta.url))) {
|
|
52536
|
+
let dir = fromDir;
|
|
52537
|
+
for (; ; ) {
|
|
52538
|
+
const candidate = join24(dir, "package.json");
|
|
52539
|
+
if (existsSync14(candidate)) {
|
|
52540
|
+
try {
|
|
52541
|
+
if (JSON.parse(readFileSync4(candidate, "utf8")).name === "apple-notes-mcp")
|
|
52542
|
+
return dir;
|
|
52543
|
+
} catch {
|
|
52544
|
+
}
|
|
52545
|
+
}
|
|
52546
|
+
const parent = dirname8(dir);
|
|
52547
|
+
if (parent === dir) return resolve5(fromDir, "..");
|
|
52548
|
+
dir = parent;
|
|
52549
|
+
}
|
|
52550
|
+
}
|
|
52551
|
+
function defaultPublicHelperDeps(overrides = {}) {
|
|
52552
|
+
return {
|
|
52553
|
+
env: process.env,
|
|
52554
|
+
platform: process.platform,
|
|
52555
|
+
sourcePath: join24(packageRoot(), PUBLIC_HELPER_SOURCE),
|
|
52556
|
+
exists: existsSync14,
|
|
52557
|
+
readFile: (path10) => readFileSync4(path10),
|
|
52558
|
+
spawn: spawnSync3,
|
|
52559
|
+
...overrides
|
|
52560
|
+
};
|
|
52561
|
+
}
|
|
52562
|
+
function publicHelperInstallDir(env = process.env) {
|
|
52563
|
+
const override = env[PUBLIC_HELPER_DIR_ENV]?.trim();
|
|
52564
|
+
if (override) return override;
|
|
52565
|
+
return join24(homedir19(), "Library", "Application Support", "apple-notes-mcp", "public-helper");
|
|
52566
|
+
}
|
|
52567
|
+
function sha256Hex(data) {
|
|
52568
|
+
return createHash4("sha256").update(data).digest("hex");
|
|
52569
|
+
}
|
|
52570
|
+
function inspectPublicHelper(deps = defaultPublicHelperDeps()) {
|
|
52571
|
+
const installDir = publicHelperInstallDir(deps.env);
|
|
52572
|
+
const binaryPath = join24(installDir, PUBLIC_HELPER_BINARY);
|
|
52573
|
+
const base = { installDir, binaryPath, sourcePath: deps.sourcePath, manifest: null };
|
|
52574
|
+
const fail = (reason, detail) => ({
|
|
52575
|
+
...base,
|
|
52576
|
+
ready: false,
|
|
52577
|
+
reason,
|
|
52578
|
+
detail
|
|
52579
|
+
});
|
|
52580
|
+
if (deps.platform !== "darwin") return fail("unsupported_platform", "macOS only");
|
|
52581
|
+
if (!deps.exists(deps.sourcePath))
|
|
52582
|
+
return fail("helper_not_installed", `Packaged helper source is missing: ${deps.sourcePath}`);
|
|
52583
|
+
const manifestPath = join24(installDir, PUBLIC_HELPER_MANIFEST);
|
|
52584
|
+
if (!deps.exists(binaryPath) || !deps.exists(manifestPath))
|
|
52585
|
+
return fail(
|
|
52586
|
+
"helper_not_installed",
|
|
52587
|
+
`The public native helper is not built. Run \`${PUBLIC_HELPER_SETUP_COMMAND}\`.`
|
|
52588
|
+
);
|
|
52589
|
+
let manifest;
|
|
52590
|
+
try {
|
|
52591
|
+
manifest = publicManifestSchema.parse(JSON.parse(deps.readFile(manifestPath).toString("utf8")));
|
|
52592
|
+
} catch {
|
|
52593
|
+
return fail(
|
|
52594
|
+
"helper_manifest_invalid",
|
|
52595
|
+
`The helper manifest is unreadable. Run \`${PUBLIC_HELPER_SETUP_COMMAND}\`.`
|
|
52596
|
+
);
|
|
52597
|
+
}
|
|
52598
|
+
if (manifest.sourceSha256 !== sha256Hex(deps.readFile(deps.sourcePath)) || manifest.protocolVersion !== PUBLIC_HELPER_PROTOCOL)
|
|
52599
|
+
return {
|
|
52600
|
+
...fail(
|
|
52601
|
+
"helper_stale",
|
|
52602
|
+
`The installed helper was built from a different source than this apple-notes-mcp version ships. Run \`${PUBLIC_HELPER_SETUP_COMMAND}\` again.`
|
|
52603
|
+
),
|
|
52604
|
+
manifest
|
|
52605
|
+
};
|
|
52606
|
+
if (sha256Hex(deps.readFile(binaryPath)) !== manifest.binarySha256)
|
|
52607
|
+
return {
|
|
52608
|
+
...fail(
|
|
52609
|
+
"helper_modified",
|
|
52610
|
+
`The helper binary no longer matches the checksum recorded when it was built. Run \`${PUBLIC_HELPER_SETUP_COMMAND}\` to rebuild it.`
|
|
52611
|
+
),
|
|
52612
|
+
manifest
|
|
52613
|
+
};
|
|
52614
|
+
return { ...base, manifest, ready: true, reason: null, detail: null };
|
|
52615
|
+
}
|
|
52616
|
+
var UNAVAILABLE_CODES = /* @__PURE__ */ new Set([
|
|
52617
|
+
"unsupported_platform",
|
|
52618
|
+
"helper_not_installed",
|
|
52619
|
+
"helper_stale",
|
|
52620
|
+
"helper_modified",
|
|
52621
|
+
"helper_manifest_invalid"
|
|
52622
|
+
]);
|
|
52623
|
+
var PublicHelperError = class extends CodedError {
|
|
52624
|
+
constructor(code, message) {
|
|
52625
|
+
super(message, {
|
|
52626
|
+
code: UNAVAILABLE_CODES.has(code) ? "unsupported" : "operation_failed",
|
|
52627
|
+
helperCode: code
|
|
52628
|
+
});
|
|
52629
|
+
this.code = code;
|
|
52630
|
+
this.name = "PublicHelperError";
|
|
52631
|
+
}
|
|
52632
|
+
code;
|
|
52633
|
+
};
|
|
52634
|
+
var errorSchema = external_exports.object({ status: external_exports.literal("error"), code: external_exports.string(), message: external_exports.string() });
|
|
52635
|
+
var publicHelloSchema = external_exports.object({
|
|
52636
|
+
status: external_exports.literal("ok"),
|
|
52637
|
+
protocolVersion: external_exports.number().int(),
|
|
52638
|
+
sourceSha256: external_exports.string(),
|
|
52639
|
+
actions: external_exports.array(external_exports.string())
|
|
52640
|
+
}).passthrough();
|
|
52641
|
+
function callPublicHelper(action, fields = {}, deps = defaultPublicHelperDeps(), options = {}) {
|
|
52642
|
+
if (!PUBLIC_HELPER_ACTIONS.has(action))
|
|
52643
|
+
throw new PublicHelperError(
|
|
52644
|
+
"unknown_action",
|
|
52645
|
+
`"${action}" is not an action the server sends to the public helper.`
|
|
52646
|
+
);
|
|
52647
|
+
let binaryPath = options.binaryPath;
|
|
52648
|
+
if (!binaryPath) {
|
|
52649
|
+
const install = inspectPublicHelper(deps);
|
|
52650
|
+
if (!install.ready)
|
|
52651
|
+
throw new PublicHelperError(install.reason ?? "helper_not_installed", install.detail ?? "");
|
|
52652
|
+
binaryPath = install.binaryPath;
|
|
52653
|
+
}
|
|
52654
|
+
const timeout = Number.parseInt(deps.env[PUBLIC_HELPER_TIMEOUT_ENV] || "", 10) || options.timeoutMs || DEFAULT_TIMEOUT_MS2;
|
|
52655
|
+
const result = deps.spawn(binaryPath, [], {
|
|
52656
|
+
input: JSON.stringify({ protocol: PUBLIC_HELPER_PROTOCOL, action, ...fields }),
|
|
52657
|
+
encoding: "utf8",
|
|
52658
|
+
timeout,
|
|
52659
|
+
killSignal: "SIGKILL",
|
|
52660
|
+
maxBuffer: MAX_OUTPUT_BYTES
|
|
52661
|
+
});
|
|
52662
|
+
const errno = result.error?.code;
|
|
52663
|
+
if (errno === "ETIMEDOUT" || result.signal && result.status === null)
|
|
52664
|
+
throw new PublicHelperError("timeout", `The helper did not answer within ${timeout} ms.`);
|
|
52665
|
+
if (result.error)
|
|
52666
|
+
throw new PublicHelperError(
|
|
52667
|
+
"helper_unreachable",
|
|
52668
|
+
`Could not run the helper: ${result.error.message}`
|
|
52669
|
+
);
|
|
52670
|
+
let parsed;
|
|
52671
|
+
try {
|
|
52672
|
+
parsed = JSON.parse(String(result.stdout ?? "").trim());
|
|
52673
|
+
} catch {
|
|
52674
|
+
throw new PublicHelperError(
|
|
52675
|
+
"invalid_response",
|
|
52676
|
+
`The helper exited with status ${result.status} and no JSON response.`
|
|
52677
|
+
);
|
|
52678
|
+
}
|
|
52679
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
52680
|
+
throw new PublicHelperError("invalid_response", "The helper response is not a JSON object.");
|
|
52681
|
+
const object3 = parsed;
|
|
52682
|
+
if (result.status !== 0 || object3.status !== "ok") {
|
|
52683
|
+
const error2 = errorSchema.safeParse(object3);
|
|
52684
|
+
if (!error2.success)
|
|
52685
|
+
throw new PublicHelperError(
|
|
52686
|
+
"invalid_response",
|
|
52687
|
+
`The helper failed with an unrecognized response (exit ${result.status}).`
|
|
52688
|
+
);
|
|
52689
|
+
throw new PublicHelperError(error2.data.code, error2.data.message);
|
|
52690
|
+
}
|
|
52691
|
+
return object3;
|
|
52692
|
+
}
|
|
52693
|
+
function defaultPublicHelperBuildDeps() {
|
|
52694
|
+
return {
|
|
52695
|
+
...defaultPublicHelperDeps(),
|
|
52696
|
+
osVersion: () => {
|
|
52697
|
+
const r = spawnSync3("/usr/bin/sw_vers", ["-productVersion"], { encoding: "utf8" });
|
|
52698
|
+
return r.status === 0 ? r.stdout.trim() : `Darwin ${release3()}`;
|
|
52699
|
+
},
|
|
52700
|
+
now: () => /* @__PURE__ */ new Date()
|
|
52701
|
+
};
|
|
52702
|
+
}
|
|
52703
|
+
function sourceDigestSwift(sourceSha) {
|
|
52704
|
+
return `let helperSourceSHA256 = "${sourceSha}"
|
|
52705
|
+
`;
|
|
52706
|
+
}
|
|
52707
|
+
var PUBLIC_HELPER_BUNDLE_ID = "apple-notes-mcp.public-helper";
|
|
52708
|
+
function publicHelperInfoPlist() {
|
|
52709
|
+
return [
|
|
52710
|
+
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
52711
|
+
'<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">',
|
|
52712
|
+
'<plist version="1.0">',
|
|
52713
|
+
"<dict>",
|
|
52714
|
+
" <key>CFBundleIdentifier</key>",
|
|
52715
|
+
` <string>${PUBLIC_HELPER_BUNDLE_ID}</string>`,
|
|
52716
|
+
" <key>CFBundleName</key>",
|
|
52717
|
+
" <string>apple-notes-mcp public helper</string>",
|
|
52718
|
+
" <key>CFBundleInfoDictionaryVersion</key>",
|
|
52719
|
+
" <string>6.0</string>",
|
|
52720
|
+
"</dict>",
|
|
52721
|
+
"</plist>",
|
|
52722
|
+
""
|
|
52723
|
+
].join("\n");
|
|
52724
|
+
}
|
|
52725
|
+
function publicHelperCompileArguments(sourcePath, digestPath, plistPath, outputPath) {
|
|
52726
|
+
return [
|
|
52727
|
+
"swiftc",
|
|
52728
|
+
"-O",
|
|
52729
|
+
"-parse-as-library",
|
|
52730
|
+
"-framework",
|
|
52731
|
+
"AppKit",
|
|
52732
|
+
"-framework",
|
|
52733
|
+
"PencilKit",
|
|
52734
|
+
"-Xlinker",
|
|
52735
|
+
"-sectcreate",
|
|
52736
|
+
"-Xlinker",
|
|
52737
|
+
"__TEXT",
|
|
52738
|
+
"-Xlinker",
|
|
52739
|
+
"__info_plist",
|
|
52740
|
+
"-Xlinker",
|
|
52741
|
+
plistPath,
|
|
52742
|
+
sourcePath,
|
|
52743
|
+
digestPath,
|
|
52744
|
+
"-o",
|
|
52745
|
+
outputPath
|
|
52746
|
+
];
|
|
52747
|
+
}
|
|
52748
|
+
function buildPublicHelper(checkOnly, deps = defaultPublicHelperBuildDeps()) {
|
|
52749
|
+
const steps = [];
|
|
52750
|
+
const done = (ok) => ({
|
|
52751
|
+
ok,
|
|
52752
|
+
checkOnly,
|
|
52753
|
+
steps,
|
|
52754
|
+
installation: inspectPublicHelper(deps)
|
|
52755
|
+
});
|
|
52756
|
+
if (checkOnly) {
|
|
52757
|
+
const installation2 = inspectPublicHelper(deps);
|
|
52758
|
+
steps.push({
|
|
52759
|
+
step: "inspect installed helper",
|
|
52760
|
+
ok: installation2.ready,
|
|
52761
|
+
detail: installation2.ready ? installation2.binaryPath : installation2.detail ?? void 0
|
|
52762
|
+
});
|
|
52763
|
+
return { ok: installation2.ready, checkOnly, steps, installation: installation2 };
|
|
52764
|
+
}
|
|
52765
|
+
if (deps.platform !== "darwin") {
|
|
52766
|
+
steps.push({ step: "platform", ok: false, detail: "macOS only" });
|
|
52767
|
+
return done(false);
|
|
52768
|
+
}
|
|
52769
|
+
if (!deps.exists(deps.sourcePath)) {
|
|
52770
|
+
steps.push({ step: "locate source", ok: false, detail: deps.sourcePath });
|
|
52771
|
+
return done(false);
|
|
52772
|
+
}
|
|
52773
|
+
const sourceSha = sha256Hex(deps.readFile(deps.sourcePath));
|
|
52774
|
+
steps.push({ step: "locate source", ok: true, detail: `sha256 ${sourceSha}` });
|
|
52775
|
+
const version3 = deps.spawn("/usr/bin/xcrun", ["swiftc", "--version"], { encoding: "utf8" });
|
|
52776
|
+
if (version3.status !== 0) {
|
|
52777
|
+
steps.push({
|
|
52778
|
+
step: "find compiler",
|
|
52779
|
+
ok: false,
|
|
52780
|
+
detail: "No Swift compiler found. Install the Command Line Tools with `xcode-select --install`."
|
|
52781
|
+
});
|
|
52782
|
+
return done(false);
|
|
52783
|
+
}
|
|
52784
|
+
const compiler = String(version3.stdout || version3.stderr || "").split("\n").find((line) => line.includes("Swift version"))?.trim() || "swiftc";
|
|
52785
|
+
steps.push({ step: "find compiler", ok: true, detail: compiler });
|
|
52786
|
+
const installDir = publicHelperInstallDir(deps.env);
|
|
52787
|
+
mkdirSync6(installDir, { recursive: true, mode: 448 });
|
|
52788
|
+
const staging = mkdtempSync5(join24(installDir, ".staging-"));
|
|
52789
|
+
try {
|
|
52790
|
+
const stagedBinary = join24(staging, PUBLIC_HELPER_BINARY);
|
|
52791
|
+
const digestPath = join24(staging, "source-digest.swift");
|
|
52792
|
+
const plistPath = join24(staging, "Info.plist");
|
|
52793
|
+
writeFileSync4(digestPath, sourceDigestSwift(sourceSha), { mode: 384 });
|
|
52794
|
+
writeFileSync4(plistPath, publicHelperInfoPlist(), { mode: 384 });
|
|
52795
|
+
const compile = deps.spawn(
|
|
52796
|
+
"/usr/bin/xcrun",
|
|
52797
|
+
publicHelperCompileArguments(deps.sourcePath, digestPath, plistPath, stagedBinary),
|
|
52798
|
+
{ encoding: "utf8", timeout: 3e5 }
|
|
52799
|
+
);
|
|
52800
|
+
if (compile.status !== 0) {
|
|
52801
|
+
steps.push({
|
|
52802
|
+
step: "compile",
|
|
52803
|
+
ok: false,
|
|
52804
|
+
detail: String(compile.stderr || compile.error?.message || "swiftc failed").slice(0, 4e3)
|
|
52805
|
+
});
|
|
52806
|
+
return done(false);
|
|
52807
|
+
}
|
|
52808
|
+
steps.push({ step: "compile", ok: true });
|
|
52809
|
+
const sign = deps.spawn(
|
|
52810
|
+
"/usr/bin/codesign",
|
|
52811
|
+
["--force", "--sign", "-", "--identifier", PUBLIC_HELPER_BUNDLE_ID, stagedBinary],
|
|
52812
|
+
{ encoding: "utf8" }
|
|
52813
|
+
);
|
|
52814
|
+
if (sign.status !== 0) {
|
|
52815
|
+
steps.push({
|
|
52816
|
+
step: "ad-hoc sign",
|
|
52817
|
+
ok: false,
|
|
52818
|
+
detail: String(sign.stderr || "codesign failed")
|
|
52819
|
+
});
|
|
52820
|
+
return done(false);
|
|
52821
|
+
}
|
|
52822
|
+
steps.push({ step: "ad-hoc sign", ok: true });
|
|
52823
|
+
let hello;
|
|
52824
|
+
try {
|
|
52825
|
+
hello = publicHelloSchema.parse(
|
|
52826
|
+
callPublicHelper("hello", {}, deps, { binaryPath: stagedBinary })
|
|
52827
|
+
);
|
|
52828
|
+
} catch (error2) {
|
|
52829
|
+
steps.push({
|
|
52830
|
+
step: "handshake",
|
|
52831
|
+
ok: false,
|
|
52832
|
+
detail: error2 instanceof Error ? error2.message : String(error2)
|
|
52833
|
+
});
|
|
52834
|
+
return done(false);
|
|
52835
|
+
}
|
|
52836
|
+
if (hello.protocolVersion !== PUBLIC_HELPER_PROTOCOL || hello.sourceSha256 !== sourceSha) {
|
|
52837
|
+
steps.push({
|
|
52838
|
+
step: "handshake",
|
|
52839
|
+
ok: false,
|
|
52840
|
+
detail: `helper reported protocol ${hello.protocolVersion}, source ${hello.sourceSha256}`
|
|
52841
|
+
});
|
|
52842
|
+
return done(false);
|
|
52843
|
+
}
|
|
52844
|
+
steps.push({ step: "handshake", ok: true, detail: `actions: ${hello.actions.join(", ")}` });
|
|
52845
|
+
const manifest = {
|
|
52846
|
+
schemaVersion: 1,
|
|
52847
|
+
protocolVersion: hello.protocolVersion,
|
|
52848
|
+
sourceSha256: sourceSha,
|
|
52849
|
+
binarySha256: sha256Hex(deps.readFile(stagedBinary)),
|
|
52850
|
+
builtAt: deps.now().toISOString(),
|
|
52851
|
+
osVersion: deps.osVersion(),
|
|
52852
|
+
compiler
|
|
52853
|
+
};
|
|
52854
|
+
chmodSync(stagedBinary, 448);
|
|
52855
|
+
renameSync(stagedBinary, join24(installDir, PUBLIC_HELPER_BINARY));
|
|
52856
|
+
writeFileSync4(
|
|
52857
|
+
join24(installDir, PUBLIC_HELPER_MANIFEST),
|
|
52858
|
+
JSON.stringify(manifest, null, 2) + "\n",
|
|
52859
|
+
{ mode: 384 }
|
|
52860
|
+
);
|
|
52861
|
+
steps.push({ step: "install", ok: true, detail: installDir });
|
|
52862
|
+
} finally {
|
|
52863
|
+
rmSync5(staging, { recursive: true, force: true });
|
|
52864
|
+
}
|
|
52865
|
+
const installation = inspectPublicHelper(deps);
|
|
52866
|
+
steps.push({
|
|
52867
|
+
step: "verify installation",
|
|
52868
|
+
ok: installation.ready,
|
|
52869
|
+
detail: installation.ready ? void 0 : installation.detail ?? void 0
|
|
52870
|
+
});
|
|
52871
|
+
return { ok: installation.ready, checkOnly, steps, installation };
|
|
52872
|
+
}
|
|
52873
|
+
function formatPublicHelperBuild(report) {
|
|
52874
|
+
const lines = ["Apple Notes MCP public native helper", ""];
|
|
52875
|
+
for (const step of report.steps)
|
|
52876
|
+
lines.push(`${step.ok ? "\u2713" : "\u2717"} ${step.step}${step.detail ? `: ${step.detail}` : ""}`);
|
|
52877
|
+
lines.push("");
|
|
52878
|
+
if (report.ok) lines.push(`Installed at ${report.installation.binaryPath}.`);
|
|
52879
|
+
else if (report.checkOnly) lines.push(`Run \`${PUBLIC_HELPER_SETUP_COMMAND}\` to build it.`);
|
|
52880
|
+
else lines.push("The helper was not installed. Fix the failed step above and run setup again.");
|
|
52881
|
+
return lines.join("\n");
|
|
52882
|
+
}
|
|
52883
|
+
|
|
52884
|
+
// src/utils/noteStoreQuery.ts
|
|
52885
|
+
function parseNoteObjectId(noteId3) {
|
|
52886
|
+
const match = /^x-coredata:\/\/([0-9A-Fa-f-]+)\/ICNote\/p(\d{1,15})$/.exec(noteId3);
|
|
52887
|
+
if (!match)
|
|
52888
|
+
throw new NoteStoreError(
|
|
52889
|
+
`Invalid note ID format: "${noteId3}". Expected format: x-coredata://UUID/ICNote/pNNN`,
|
|
52890
|
+
"invalid_input"
|
|
52891
|
+
);
|
|
52892
|
+
return { store: match[1], pk: Number(match[2]) };
|
|
52893
|
+
}
|
|
52894
|
+
function queryNoteScoped(sql, pk, dbPath2 = NOTES_DB_PATH7) {
|
|
52895
|
+
return runReadOnlySql(dbPath2, sql, { pk: { int: pk } }).split("\n");
|
|
52896
|
+
}
|
|
52897
|
+
var NOTE_STATE_SQL = `SELECT json_object('found', (SELECT count(*) FROM ZICCLOUDSYNCINGOBJECT n WHERE n.Z_PK = @pk AND n.Z_ENT = ${entity("ICNote")}), 'locked', (SELECT COALESCE(n.ZISPASSWORDPROTECTED, 0) FROM ZICCLOUDSYNCINGOBJECT n WHERE n.Z_PK = @pk));`;
|
|
52898
|
+
function assertNoteReadable(stateLine, noteId3) {
|
|
52899
|
+
let state;
|
|
52900
|
+
try {
|
|
52901
|
+
state = JSON.parse(stateLine || "{}");
|
|
52902
|
+
} catch {
|
|
52903
|
+
throw new NoteStoreError("Unexpected response from the Notes database.", "query_error");
|
|
52904
|
+
}
|
|
52905
|
+
if (!state.found)
|
|
52906
|
+
throw new CodedError(`No note found in the database for ID "${noteId3}".`, {
|
|
52907
|
+
code: "not_found"
|
|
52908
|
+
});
|
|
52909
|
+
if (state.locked)
|
|
52910
|
+
throw new CodedError(
|
|
52911
|
+
"This note is password-protected; its attachments are encrypted and cannot be read.",
|
|
52912
|
+
{ code: "unsupported" }
|
|
52913
|
+
);
|
|
52914
|
+
}
|
|
52915
|
+
|
|
52916
|
+
// src/utils/noteDrawings.ts
|
|
52917
|
+
function drawingRowsSql(columns, dataColumn) {
|
|
52918
|
+
return [
|
|
52919
|
+
NOTE_STATE_SQL,
|
|
52920
|
+
`SELECT json_group_array(json_object('pk', a.Z_PK, 'identifier', a.ZIDENTIFIER, 'uti', a.ZTYPEUTI, 'data', hex(a.${dataColumn}))) FROM (SELECT * FROM ZICCLOUDSYNCINGOBJECT a WHERE a.ZNOTE = @pk AND a.ZTYPEUTI IN ('com.apple.drawing.2', 'com.apple.drawing') AND ${notTombstonedSql(columns, "a")} ORDER BY a.Z_PK) a;`
|
|
52921
|
+
].join("\n");
|
|
52922
|
+
}
|
|
52923
|
+
function readDrawingRows2(noteId3, dbPath2 = NOTES_DB_PATH7) {
|
|
52924
|
+
const { store, pk } = parseNoteObjectId(noteId3);
|
|
52925
|
+
const columns = readColumns(dbPath2);
|
|
52926
|
+
const dataColumn = columns.has("ZMERGEABLEDATA1") ? "ZMERGEABLEDATA1" : columns.has("ZMERGEABLEDATA") ? "ZMERGEABLEDATA" : null;
|
|
52927
|
+
if (!dataColumn)
|
|
52928
|
+
throw new NoteStoreError(
|
|
52929
|
+
"This macOS version's Notes database has no drawing data column.",
|
|
52930
|
+
"schema"
|
|
52931
|
+
);
|
|
52932
|
+
const [stateLine, rowsLine] = queryNoteScoped(drawingRowsSql(columns, dataColumn), pk, dbPath2);
|
|
52933
|
+
assertNoteReadable(stateLine, noteId3);
|
|
52934
|
+
const rows = JSON.parse(rowsLine || "[]");
|
|
52935
|
+
return rows.map((row) => ({
|
|
52936
|
+
pk: row.pk,
|
|
52937
|
+
attachmentId: `x-coredata://${store}/ICAttachment/p${row.pk}`,
|
|
52938
|
+
identifier: row.identifier ?? "",
|
|
52939
|
+
typeUti: row.uti,
|
|
52940
|
+
data: row.data ? Buffer.from(row.data, "hex") : null
|
|
52941
|
+
}));
|
|
52942
|
+
}
|
|
52943
|
+
function svgNumber(value) {
|
|
52944
|
+
if (!Number.isFinite(value)) return "0";
|
|
52945
|
+
const rounded = Math.round(value * 100) / 100;
|
|
52946
|
+
return Object.is(rounded, -0) ? "0" : String(rounded);
|
|
52947
|
+
}
|
|
52948
|
+
function escapeAttribute2(value) {
|
|
52949
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
52950
|
+
}
|
|
52951
|
+
var clampChannel = (value) => Math.min(255, Math.max(0, Math.round(value || 0)));
|
|
52952
|
+
var clampUnit = (value) => Math.min(1, Math.max(0, Number.isFinite(value) ? value : 1));
|
|
52953
|
+
function drawingViewBox(strokes, fallback) {
|
|
52954
|
+
let minX = Infinity;
|
|
52955
|
+
let minY = Infinity;
|
|
52956
|
+
let maxX = -Infinity;
|
|
52957
|
+
let maxY = -Infinity;
|
|
52958
|
+
for (const stroke of strokes) {
|
|
52959
|
+
const pad = stroke.width / 2;
|
|
52960
|
+
const extend2 = (x, y, r) => {
|
|
52961
|
+
minX = Math.min(minX, x - r);
|
|
52962
|
+
minY = Math.min(minY, y - r);
|
|
52963
|
+
maxX = Math.max(maxX, x + r);
|
|
52964
|
+
maxY = Math.max(maxY, y + r);
|
|
52965
|
+
};
|
|
52966
|
+
if (stroke.points?.length) for (const p of stroke.points) extend2(p.x, p.y, pad);
|
|
52967
|
+
else {
|
|
52968
|
+
extend2(stroke.bounds.x, stroke.bounds.y, 0);
|
|
52969
|
+
extend2(stroke.bounds.x + stroke.bounds.width, stroke.bounds.y + stroke.bounds.height, 0);
|
|
52970
|
+
}
|
|
52971
|
+
}
|
|
52972
|
+
if (minX === Infinity) return fallback ?? { x: 0, y: 0, width: 1, height: 1 };
|
|
52973
|
+
return { x: minX, y: minY, width: Math.max(1, maxX - minX), height: Math.max(1, maxY - minY) };
|
|
52974
|
+
}
|
|
52975
|
+
function drawingToSvg(strokes, fallback) {
|
|
52976
|
+
const box = drawingViewBox(strokes, fallback);
|
|
52977
|
+
const parts = [
|
|
52978
|
+
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="${svgNumber(box.x)} ${svgNumber(box.y)} ${svgNumber(box.width)} ${svgNumber(box.height)}" width="${svgNumber(box.width)}" height="${svgNumber(box.height)}">`
|
|
52979
|
+
];
|
|
52980
|
+
for (const stroke of strokes) {
|
|
52981
|
+
const points = stroke.points ?? [];
|
|
52982
|
+
if (points.length === 0) continue;
|
|
52983
|
+
const c = stroke.color;
|
|
52984
|
+
const color = `rgb(${clampChannel(c.red)},${clampChannel(c.green)},${clampChannel(c.blue)})`;
|
|
52985
|
+
const shared = `stroke="${color}" stroke-opacity="${svgNumber(clampUnit(c.alpha))}" data-ink="${escapeAttribute2(stroke.inkType)}"`;
|
|
52986
|
+
if (points.length === 1) {
|
|
52987
|
+
parts.push(
|
|
52988
|
+
`<circle cx="${svgNumber(points[0].x)}" cy="${svgNumber(points[0].y)}" r="${svgNumber(stroke.width / 2)}" fill="${color}" fill-opacity="${svgNumber(clampUnit(c.alpha))}" data-ink="${escapeAttribute2(stroke.inkType)}"/>`
|
|
52989
|
+
);
|
|
52990
|
+
continue;
|
|
52991
|
+
}
|
|
52992
|
+
const d = points.map((p, i) => `${i === 0 ? "M" : "L"}${svgNumber(p.x)} ${svgNumber(p.y)}`).join(" ");
|
|
52993
|
+
parts.push(
|
|
52994
|
+
`<path d="${d}" fill="none" ${shared} stroke-width="${svgNumber(stroke.width)}" stroke-linecap="round" stroke-linejoin="round"/>`
|
|
52995
|
+
);
|
|
52996
|
+
}
|
|
52997
|
+
parts.push("</svg>");
|
|
52998
|
+
return parts.join("\n");
|
|
52999
|
+
}
|
|
53000
|
+
|
|
53001
|
+
// src/services/noteDrawings.ts
|
|
53002
|
+
var bounds = external_exports.object({ x: external_exports.number(), y: external_exports.number(), width: external_exports.number(), height: external_exports.number() });
|
|
53003
|
+
var strokeSchema = external_exports.object({
|
|
53004
|
+
inkType: external_exports.string(),
|
|
53005
|
+
color: external_exports.object({
|
|
53006
|
+
red: external_exports.number(),
|
|
53007
|
+
green: external_exports.number(),
|
|
53008
|
+
blue: external_exports.number(),
|
|
53009
|
+
alpha: external_exports.number()
|
|
53010
|
+
}),
|
|
53011
|
+
width: external_exports.number(),
|
|
53012
|
+
pointCount: external_exports.number().int(),
|
|
53013
|
+
bounds,
|
|
53014
|
+
points: external_exports.array(
|
|
53015
|
+
external_exports.object({
|
|
53016
|
+
x: external_exports.number(),
|
|
53017
|
+
y: external_exports.number(),
|
|
53018
|
+
width: external_exports.number(),
|
|
53019
|
+
opacity: external_exports.number(),
|
|
53020
|
+
force: external_exports.number()
|
|
53021
|
+
})
|
|
53022
|
+
).optional(),
|
|
53023
|
+
transformApplied: external_exports.boolean().optional()
|
|
53024
|
+
}).strip();
|
|
53025
|
+
var decodedDrawingSchema = external_exports.object({
|
|
53026
|
+
status: external_exports.literal("ok"),
|
|
53027
|
+
strokeCount: external_exports.number().int(),
|
|
53028
|
+
strokes: external_exports.array(strokeSchema),
|
|
53029
|
+
truncated: external_exports.boolean(),
|
|
53030
|
+
bounds
|
|
53031
|
+
});
|
|
53032
|
+
function decodeRow(row, format, includePoints, deps) {
|
|
53033
|
+
const base = {
|
|
53034
|
+
attachmentId: row.attachmentId,
|
|
53035
|
+
identifier: row.identifier,
|
|
53036
|
+
typeUti: row.typeUti,
|
|
53037
|
+
status: "error"
|
|
53038
|
+
};
|
|
53039
|
+
if (!row.data || row.data.length === 0)
|
|
53040
|
+
return { ...base, code: "no_data", message: "This drawing has no stored PencilKit data." };
|
|
53041
|
+
let decoded;
|
|
53042
|
+
try {
|
|
53043
|
+
const needPoints = includePoints || format !== "json";
|
|
53044
|
+
const raw = callPublicHelper(
|
|
53045
|
+
"decode_drawing",
|
|
53046
|
+
{ dataBase64: row.data.toString("base64"), includePoints: needPoints },
|
|
53047
|
+
deps
|
|
53048
|
+
);
|
|
53049
|
+
const parsed = decodedDrawingSchema.safeParse(raw);
|
|
53050
|
+
if (!parsed.success)
|
|
53051
|
+
return { ...base, code: "invalid_response", message: "Unexpected helper response." };
|
|
53052
|
+
decoded = parsed.data;
|
|
53053
|
+
} catch (error2) {
|
|
53054
|
+
const code = error2 instanceof PublicHelperError ? error2.code : "internal_error";
|
|
53055
|
+
return { ...base, code, message: error2 instanceof Error ? error2.message : String(error2) };
|
|
53056
|
+
}
|
|
53057
|
+
const strokes = decoded.strokes;
|
|
53058
|
+
const result = {
|
|
53059
|
+
...base,
|
|
53060
|
+
status: "ok",
|
|
53061
|
+
strokeCount: decoded.strokeCount,
|
|
53062
|
+
bounds: decoded.bounds,
|
|
53063
|
+
truncated: decoded.truncated
|
|
53064
|
+
};
|
|
53065
|
+
if (format !== "json") result.svg = drawingToSvg(strokes, decoded.bounds);
|
|
53066
|
+
if (format !== "svg")
|
|
53067
|
+
result.strokes = includePoints ? strokes : strokes.map(({ points: _points, ...rest }) => rest);
|
|
53068
|
+
return result;
|
|
53069
|
+
}
|
|
53070
|
+
function getNoteDrawings(noteId3, options = {}) {
|
|
53071
|
+
const format = options.format ?? "json";
|
|
53072
|
+
const includePoints = options.includePoints ?? true;
|
|
53073
|
+
const deps = options.deps ?? defaultPublicHelperDeps();
|
|
53074
|
+
const rows = (options.readRows ?? readDrawingRows2)(noteId3, options.dbPath);
|
|
53075
|
+
if (rows.length === 0) return { id: noteId3, drawingCount: 0, status: "none", drawings: [] };
|
|
53076
|
+
const install = inspectPublicHelper(deps);
|
|
53077
|
+
if (!install.ready)
|
|
53078
|
+
throw new PublicHelperError(install.reason ?? "helper_not_installed", install.detail ?? "");
|
|
53079
|
+
const drawings = rows.map((row) => decodeRow(row, format, includePoints, deps));
|
|
53080
|
+
const ok = drawings.filter((d) => d.status === "ok").length;
|
|
53081
|
+
return {
|
|
53082
|
+
id: noteId3,
|
|
53083
|
+
drawingCount: drawings.length,
|
|
53084
|
+
status: ok === drawings.length ? "ok" : ok ? "partial" : "error",
|
|
53085
|
+
drawings
|
|
53086
|
+
};
|
|
53087
|
+
}
|
|
53088
|
+
function formatNoteDrawings(result) {
|
|
53089
|
+
if (result.drawingCount === 0) return `No classic PencilKit drawings in note ${result.id}.`;
|
|
53090
|
+
const lines = [
|
|
53091
|
+
`${result.drawingCount} classic drawing${result.drawingCount === 1 ? "" : "s"} in note ${result.id} (${result.status}):`
|
|
53092
|
+
];
|
|
53093
|
+
for (const d of result.drawings)
|
|
53094
|
+
lines.push(
|
|
53095
|
+
d.status === "ok" ? `- ${d.attachmentId}: ${d.strokeCount} stroke${d.strokeCount === 1 ? "" : "s"}${d.truncated ? " (truncated)" : ""}` : `- ${d.attachmentId}: error ${d.code}: ${d.message}`
|
|
53096
|
+
);
|
|
53097
|
+
return lines.join("\n");
|
|
53098
|
+
}
|
|
53099
|
+
|
|
53100
|
+
// src/services/privateHelperBuild.ts
|
|
53101
|
+
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
53102
|
+
import {
|
|
53103
|
+
chmodSync as chmodSync2,
|
|
53104
|
+
existsSync as existsSync16,
|
|
53105
|
+
mkdirSync as mkdirSync7,
|
|
53106
|
+
mkdtempSync as mkdtempSync6,
|
|
53107
|
+
renameSync as renameSync2,
|
|
53108
|
+
rmSync as rmSync6,
|
|
53109
|
+
writeFileSync as writeFileSync5
|
|
53110
|
+
} from "node:fs";
|
|
53111
|
+
import { release as release4 } from "node:os";
|
|
53112
|
+
import { join as join26 } from "node:path";
|
|
53113
|
+
|
|
53114
|
+
// src/services/privateHelper.ts
|
|
53115
|
+
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
53116
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
53117
|
+
import { existsSync as existsSync15, readFileSync as readFileSync5 } from "node:fs";
|
|
53118
|
+
import { homedir as homedir20 } from "node:os";
|
|
53119
|
+
import { dirname as dirname9, join as join25, resolve as resolve6 } from "node:path";
|
|
53120
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
52519
53121
|
var PRIVATE_HELPER_PROTOCOL = 1;
|
|
52520
53122
|
var ENABLE_ENV = "APPLE_NOTES_MCP_ENABLE_PRIVATE";
|
|
52521
53123
|
var HELPER_DIR_ENV = "APPLE_NOTES_MCP_PRIVATE_HELPER_DIR";
|
|
@@ -52528,8 +53130,8 @@ var READ_ONLY_ACTIONS = /* @__PURE__ */ new Set([
|
|
|
52528
53130
|
var HELPER_BINARY_NAME = "apple-notes-private-helper";
|
|
52529
53131
|
var HELPER_SOURCE_RELATIVE = "native/private-helper/apple-notes-private-helper.m";
|
|
52530
53132
|
var MANIFEST_NAME = "manifest.json";
|
|
52531
|
-
var
|
|
52532
|
-
var
|
|
53133
|
+
var DEFAULT_TIMEOUT_MS3 = 2e4;
|
|
53134
|
+
var MAX_OUTPUT_BYTES2 = 4 * 1024 * 1024;
|
|
52533
53135
|
var manifestSchema = external_exports.object({
|
|
52534
53136
|
schemaVersion: external_exports.literal(1),
|
|
52535
53137
|
protocolVersion: external_exports.number().int(),
|
|
@@ -52539,19 +53141,19 @@ var manifestSchema = external_exports.object({
|
|
|
52539
53141
|
osVersion: external_exports.string(),
|
|
52540
53142
|
compiler: external_exports.string()
|
|
52541
53143
|
});
|
|
52542
|
-
function
|
|
53144
|
+
function packageRoot2(fromDir = dirname9(fileURLToPath3(import.meta.url))) {
|
|
52543
53145
|
let dir = fromDir;
|
|
52544
53146
|
for (; ; ) {
|
|
52545
|
-
const candidate =
|
|
52546
|
-
if (
|
|
53147
|
+
const candidate = join25(dir, "package.json");
|
|
53148
|
+
if (existsSync15(candidate)) {
|
|
52547
53149
|
try {
|
|
52548
|
-
const pkg = JSON.parse(
|
|
53150
|
+
const pkg = JSON.parse(readFileSync5(candidate, "utf8"));
|
|
52549
53151
|
if (pkg.name === "apple-notes-mcp") return dir;
|
|
52550
53152
|
} catch {
|
|
52551
53153
|
}
|
|
52552
53154
|
}
|
|
52553
|
-
const parent =
|
|
52554
|
-
if (parent === dir) return
|
|
53155
|
+
const parent = dirname9(dir);
|
|
53156
|
+
if (parent === dir) return resolve6(fromDir, "..");
|
|
52555
53157
|
dir = parent;
|
|
52556
53158
|
}
|
|
52557
53159
|
}
|
|
@@ -52559,10 +53161,10 @@ function defaultDeps2(overrides = {}) {
|
|
|
52559
53161
|
return {
|
|
52560
53162
|
env: process.env,
|
|
52561
53163
|
platform: process.platform,
|
|
52562
|
-
sourcePath:
|
|
52563
|
-
exists:
|
|
52564
|
-
readFile: (path10) =>
|
|
52565
|
-
spawn:
|
|
53164
|
+
sourcePath: join25(packageRoot2(), HELPER_SOURCE_RELATIVE),
|
|
53165
|
+
exists: existsSync15,
|
|
53166
|
+
readFile: (path10) => readFileSync5(path10),
|
|
53167
|
+
spawn: spawnSync4,
|
|
52566
53168
|
...overrides
|
|
52567
53169
|
};
|
|
52568
53170
|
}
|
|
@@ -52572,14 +53174,14 @@ function privateHelperEnabled(env = process.env) {
|
|
|
52572
53174
|
function helperInstallDir(env = process.env) {
|
|
52573
53175
|
const override = env[HELPER_DIR_ENV]?.trim();
|
|
52574
53176
|
if (override) return override;
|
|
52575
|
-
return
|
|
53177
|
+
return join25(homedir20(), "Library", "Application Support", "apple-notes-mcp", "private-helper");
|
|
52576
53178
|
}
|
|
52577
|
-
function
|
|
52578
|
-
return
|
|
53179
|
+
function sha256Hex2(data) {
|
|
53180
|
+
return createHash5("sha256").update(data).digest("hex");
|
|
52579
53181
|
}
|
|
52580
53182
|
function inspectInstallation(deps = defaultDeps2()) {
|
|
52581
53183
|
const installDir = helperInstallDir(deps.env);
|
|
52582
|
-
const binaryPath =
|
|
53184
|
+
const binaryPath = join25(installDir, HELPER_BINARY_NAME);
|
|
52583
53185
|
const base = {
|
|
52584
53186
|
installDir,
|
|
52585
53187
|
binaryPath,
|
|
@@ -52596,8 +53198,8 @@ function inspectInstallation(deps = defaultDeps2()) {
|
|
|
52596
53198
|
if (deps.platform !== "darwin") return fail("unsupported_platform", "macOS only");
|
|
52597
53199
|
if (!deps.exists(deps.sourcePath))
|
|
52598
53200
|
return fail("helper_not_installed", `Packaged helper source is missing: ${deps.sourcePath}`);
|
|
52599
|
-
base.expectedSourceSha256 =
|
|
52600
|
-
const manifestPath =
|
|
53201
|
+
base.expectedSourceSha256 = sha256Hex2(deps.readFile(deps.sourcePath));
|
|
53202
|
+
const manifestPath = join25(installDir, MANIFEST_NAME);
|
|
52601
53203
|
if (!deps.exists(binaryPath) || !deps.exists(manifestPath))
|
|
52602
53204
|
return fail(
|
|
52603
53205
|
"helper_not_installed",
|
|
@@ -52618,7 +53220,7 @@ function inspectInstallation(deps = defaultDeps2()) {
|
|
|
52618
53220
|
"helper_stale",
|
|
52619
53221
|
"The installed helper was built from a different helper source or protocol than this apple-notes-mcp version ships. Run `apple-notes-mcp setup --native-helper` again."
|
|
52620
53222
|
);
|
|
52621
|
-
if (
|
|
53223
|
+
if (sha256Hex2(deps.readFile(binaryPath)) !== manifest.binarySha256)
|
|
52622
53224
|
return fail(
|
|
52623
53225
|
"helper_modified",
|
|
52624
53226
|
"The helper binary does not match the checksum recorded when it was built. Run `apple-notes-mcp setup --native-helper` to rebuild it."
|
|
@@ -52635,7 +53237,7 @@ var PrivateHelperError = class extends Error {
|
|
|
52635
53237
|
code;
|
|
52636
53238
|
details;
|
|
52637
53239
|
};
|
|
52638
|
-
var
|
|
53240
|
+
var errorSchema2 = external_exports.object({
|
|
52639
53241
|
status: external_exports.literal("error"),
|
|
52640
53242
|
code: external_exports.string(),
|
|
52641
53243
|
message: external_exports.string()
|
|
@@ -52707,13 +53309,13 @@ function callPrivateHelper(action, fields = {}, deps = defaultDeps2(), options =
|
|
|
52707
53309
|
throw new PrivateHelperError(install.reason || "helper_not_installed", install.detail || "");
|
|
52708
53310
|
binaryPath = install.binaryPath;
|
|
52709
53311
|
}
|
|
52710
|
-
const timeout = Number.parseInt(deps.env[TIMEOUT_ENV] || "", 10) ||
|
|
53312
|
+
const timeout = Number.parseInt(deps.env[TIMEOUT_ENV] || "", 10) || DEFAULT_TIMEOUT_MS3;
|
|
52711
53313
|
const result = deps.spawn(binaryPath, [], {
|
|
52712
53314
|
input: JSON.stringify({ protocol: PRIVATE_HELPER_PROTOCOL, action, ...fields }),
|
|
52713
53315
|
encoding: "utf8",
|
|
52714
53316
|
timeout,
|
|
52715
53317
|
killSignal: "SIGKILL",
|
|
52716
|
-
maxBuffer:
|
|
53318
|
+
maxBuffer: MAX_OUTPUT_BYTES2,
|
|
52717
53319
|
env: deps.env
|
|
52718
53320
|
});
|
|
52719
53321
|
const errno = result.error?.code;
|
|
@@ -52738,7 +53340,7 @@ function callPrivateHelper(action, fields = {}, deps = defaultDeps2(), options =
|
|
|
52738
53340
|
throw new PrivateHelperError("invalid_response", "The helper response is not a JSON object");
|
|
52739
53341
|
const object3 = parsed;
|
|
52740
53342
|
if (result.status !== 0 || object3.status === "error") {
|
|
52741
|
-
const error2 =
|
|
53343
|
+
const error2 = errorSchema2.safeParse(object3);
|
|
52742
53344
|
if (!error2.success)
|
|
52743
53345
|
throw new PrivateHelperError(
|
|
52744
53346
|
"invalid_response",
|
|
@@ -52841,8 +53443,8 @@ function defaultBuildDeps() {
|
|
|
52841
53443
|
return {
|
|
52842
53444
|
...defaultDeps2(),
|
|
52843
53445
|
osVersion: () => {
|
|
52844
|
-
const r =
|
|
52845
|
-
return r.status === 0 ? r.stdout.trim() : `Darwin ${
|
|
53446
|
+
const r = spawnSync5("/usr/bin/sw_vers", ["-productVersion"], { encoding: "utf8" });
|
|
53447
|
+
return r.status === 0 ? r.stdout.trim() : `Darwin ${release4()}`;
|
|
52846
53448
|
},
|
|
52847
53449
|
now: () => /* @__PURE__ */ new Date()
|
|
52848
53450
|
};
|
|
@@ -52892,7 +53494,7 @@ function buildPrivateHelper(checkOnly, deps = defaultBuildDeps()) {
|
|
|
52892
53494
|
return done(false);
|
|
52893
53495
|
}
|
|
52894
53496
|
const source = deps.readFile(deps.sourcePath);
|
|
52895
|
-
const sourceSha =
|
|
53497
|
+
const sourceSha = sha256Hex2(source);
|
|
52896
53498
|
steps.push({
|
|
52897
53499
|
step: "locate source",
|
|
52898
53500
|
ok: true,
|
|
@@ -52911,10 +53513,10 @@ function buildPrivateHelper(checkOnly, deps = defaultBuildDeps()) {
|
|
|
52911
53513
|
const compiler = String(clangVersion.stdout || "").split("\n")[0] || "clang";
|
|
52912
53514
|
steps.push({ step: "find compiler", ok: true, detail: compiler });
|
|
52913
53515
|
const installDir = helperInstallDir(deps.env);
|
|
52914
|
-
|
|
52915
|
-
const staging =
|
|
53516
|
+
mkdirSync7(installDir, { recursive: true, mode: 448 });
|
|
53517
|
+
const staging = mkdtempSync6(join26(installDir, ".staging-"));
|
|
52916
53518
|
try {
|
|
52917
|
-
const stagedBinary =
|
|
53519
|
+
const stagedBinary = join26(staging, HELPER_BINARY_NAME);
|
|
52918
53520
|
const compile = deps.spawn(
|
|
52919
53521
|
"/usr/bin/xcrun",
|
|
52920
53522
|
compileArguments(deps.sourcePath, stagedBinary, sourceSha),
|
|
@@ -52985,19 +53587,19 @@ function buildPrivateHelper(checkOnly, deps = defaultBuildDeps()) {
|
|
|
52985
53587
|
schemaVersion: 1,
|
|
52986
53588
|
protocolVersion: hello.protocolVersion,
|
|
52987
53589
|
sourceSha256: sourceSha,
|
|
52988
|
-
binarySha256:
|
|
53590
|
+
binarySha256: sha256Hex2(deps.readFile(stagedBinary)),
|
|
52989
53591
|
builtAt: deps.now().toISOString(),
|
|
52990
53592
|
osVersion: deps.osVersion(),
|
|
52991
53593
|
compiler
|
|
52992
53594
|
};
|
|
52993
|
-
|
|
52994
|
-
|
|
52995
|
-
|
|
53595
|
+
chmodSync2(stagedBinary, 448);
|
|
53596
|
+
renameSync2(stagedBinary, join26(installDir, HELPER_BINARY_NAME));
|
|
53597
|
+
writeFileSync5(join26(installDir, MANIFEST_NAME), JSON.stringify(manifest, null, 2) + "\n", {
|
|
52996
53598
|
mode: 384
|
|
52997
53599
|
});
|
|
52998
53600
|
steps.push({ step: "install", ok: true, detail: installDir });
|
|
52999
53601
|
} finally {
|
|
53000
|
-
if (
|
|
53602
|
+
if (existsSync16(staging)) rmSync6(staging, { recursive: true, force: true });
|
|
53001
53603
|
}
|
|
53002
53604
|
const installation = inspectInstallation(deps);
|
|
53003
53605
|
steps.push({
|
|
@@ -53137,6 +53739,11 @@ function registerPrivateHelperTools(server2, manager, depsFactory = () => defaul
|
|
|
53137
53739
|
loadFileConfig();
|
|
53138
53740
|
var require2 = createRequire(import.meta.url);
|
|
53139
53741
|
var { version: version2 } = require2("../package.json");
|
|
53742
|
+
if (process.argv[2] === "setup" && process.argv.slice(3).includes("--public-helper")) {
|
|
53743
|
+
const report = buildPublicHelper(process.argv.slice(3).includes("--check"));
|
|
53744
|
+
process.stdout.write(formatPublicHelperBuild(report) + "\n");
|
|
53745
|
+
process.exit(report.ok ? 0 : 1);
|
|
53746
|
+
}
|
|
53140
53747
|
if (process.argv[2] === "setup" && process.argv.slice(3).includes("--native-helper")) {
|
|
53141
53748
|
const report = buildPrivateHelper(process.argv.slice(3).includes("--check"));
|
|
53142
53749
|
process.stdout.write(formatHelperBuild(report) + "\n");
|
|
@@ -56166,6 +56773,41 @@ ${lines.join("\n")}${more}`,
|
|
|
56166
56773
|
);
|
|
56167
56774
|
}, "Error listing notes")
|
|
56168
56775
|
);
|
|
56776
|
+
registerTool(
|
|
56777
|
+
"get-note-drawings",
|
|
56778
|
+
{
|
|
56779
|
+
description: "Use when: reading the strokes of a note's classic PencilKit drawings (com.apple.drawing / com.apple.drawing.2 attachments), by note id, as JSON or SVG.\nReturns: per drawing its attachment id, status (ok/error with a code), stroke count, bounds, and strokes (ink type, sRGB color, width, points) and/or a standalone SVG document; overall status ok/partial/error/none.\nDo not use when: the drawing is a modern Paper sketch (com.apple.paper is not decoded here) or you want the attachment file itself (save-attachment).\nNote: read-only. Needs Full Disk Access and the public native helper built once with `apple-notes-mcp setup --public-helper` (compiled locally with PencilKit; no Notes writes).",
|
|
56780
|
+
inputSchema: {
|
|
56781
|
+
id: noteIdInput,
|
|
56782
|
+
format: external_exports.enum(["json", "svg", "both"]).optional().describe(
|
|
56783
|
+
'"json" (default) returns strokes, "svg" returns SVG documents, "both" returns both'
|
|
56784
|
+
),
|
|
56785
|
+
includePoints: external_exports.boolean().optional().describe(
|
|
56786
|
+
"Include per-point x/y/width/opacity/force in JSON strokes (default true). SVG output always uses the points."
|
|
56787
|
+
)
|
|
56788
|
+
},
|
|
56789
|
+
outputSchema: {
|
|
56790
|
+
id: external_exports.string().optional(),
|
|
56791
|
+
drawingCount: external_exports.number().optional(),
|
|
56792
|
+
status: external_exports.string().optional(),
|
|
56793
|
+
drawings: external_exports.array(external_exports.object({}).passthrough()).optional(),
|
|
56794
|
+
pointsOmitted: external_exports.boolean().optional()
|
|
56795
|
+
}
|
|
56796
|
+
},
|
|
56797
|
+
withErrorHandling(({ id: id2, format, includePoints }) => {
|
|
56798
|
+
let result = getNoteDrawings(id2, { format, includePoints });
|
|
56799
|
+
let pointsOmitted = false;
|
|
56800
|
+
if (Buffer.byteLength(JSON.stringify(result)) > exportMaxResponseBytes() && includePoints !== false && format !== "svg") {
|
|
56801
|
+
result = getNoteDrawings(id2, { format, includePoints: false });
|
|
56802
|
+
pointsOmitted = true;
|
|
56803
|
+
}
|
|
56804
|
+
const text2 = formatNoteDrawings(result) + (pointsOmitted ? "\nStroke points were omitted to stay under the response size limit (APPLE_NOTES_MCP_EXPORT_MAX_BYTES)." : "");
|
|
56805
|
+
return successResponse(text2, {
|
|
56806
|
+
...result,
|
|
56807
|
+
...pointsOmitted ? { pointsOmitted } : {}
|
|
56808
|
+
});
|
|
56809
|
+
}, "Error reading drawings")
|
|
56810
|
+
);
|
|
56169
56811
|
registerTool(
|
|
56170
56812
|
"list-recent-notes",
|
|
56171
56813
|
{
|