@kingcrab/pi-imessage 0.0.43 → 1.0.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.
- package/README.md +101 -127
- package/dist/agent/behavior.js +79 -0
- package/dist/agent/chats.js +67 -0
- package/dist/agent/commands.js +163 -0
- package/dist/agent/compaction.js +51 -0
- package/dist/agent/deliver.js +139 -0
- package/dist/agent/direct-send.js +68 -0
- package/dist/agent/harness.js +79 -0
- package/dist/agent/health.js +32 -0
- package/dist/agent/models.js +69 -0
- package/dist/agent/progress-format.js +87 -0
- package/dist/agent/progress.js +135 -0
- package/dist/agent/prompt.js +79 -0
- package/dist/agent/replies.js +9 -0
- package/dist/agent/run.js +159 -0
- package/dist/agent/scheduling.js +290 -0
- package/dist/agent/time.js +18 -0
- package/dist/cli.js +88 -191
- package/dist/config/settings.js +60 -0
- package/dist/extensions/browser.js +326 -0
- package/dist/extensions/final-text.js +23 -0
- package/dist/extensions/memory.js +109 -0
- package/dist/extensions/message.js +33 -0
- package/dist/extensions/read-image.js +72 -0
- package/dist/extensions/schedules.js +41 -0
- package/dist/extensions/subagent.js +54 -0
- package/dist/extensions/web.js +99 -0
- package/dist/extensions/workspace.js +98 -0
- package/dist/main.js +568 -88
- package/dist/transport/attachments.js +37 -0
- package/dist/transport/http.js +110 -0
- package/dist/{rich-text.js → transport/rich-text.js} +25 -13
- package/dist/{send.js → transport/send.js} +13 -13
- package/dist/transport/watch.js +124 -0
- package/dist/web/app.js +748 -0
- package/dist/web/history.js +87 -0
- package/dist/web/memory.js +81 -0
- package/dist/web/page.js +28 -0
- package/dist/web/schedules.js +74 -0
- package/dist/web/server.js +348 -0
- package/dist/web/style.css +543 -0
- package/dist/web/tasks.js +63 -0
- package/docs/adr/0001-durable-owns-state.md +11 -0
- package/docs/adr/0002-module-layering.md +11 -0
- package/docs/adr/0003-replies-at-most-once.md +11 -0
- package/docs/adr/0004-native-extensions.md +11 -0
- package/docs/adr/0005-history-migration.md +11 -0
- package/docs/adr/0006-jsonl-storage.md +11 -0
- package/docs/adr/0007-images-by-path.md +11 -0
- package/docs/adr/0008-compaction-and-run.md +11 -0
- package/docs/adr/0009-one-shot-cutover.md +11 -0
- package/docs/adr/0010-test-budget.md +11 -0
- package/docs/adr/0011-reconcile-unsent-answers.md +24 -0
- package/docs/adr/0012-run-in-owned-conversation.md +22 -0
- package/docs/adr/0013-thin-adapters-around-durable.md +18 -0
- package/docs/adr/0014-ephemeral-private-storage.md +13 -0
- package/docs/adr/0015-ordinary-stop-keeps-native-inbox.md +21 -0
- package/docs/adr/0016-process-http-transport.md +21 -0
- package/docs/adr/0017-browser-cli-owned-scope.md +22 -0
- package/docs/adr/0018-tasks-without-prompt-api.md +19 -0
- package/docs/adr/0019-remove-scheduled-services.md +41 -0
- package/docs/adr/0020-chat-task-progress.md +41 -0
- package/docs/adr/0021-readable-progress-without-link-previews.md +33 -0
- package/docs/adr/0022-progress-admission-and-settlement.md +35 -0
- package/docs/adr/0023-retain-progress-type-prefixes.md +18 -0
- package/docs/adr/0024-status-marker-before-type-prefix.md +13 -0
- package/docs/adr/0025-reusable-progress-and-command-preview.md +49 -0
- package/docs/adr/0026-inline-command-only-requests.md +16 -0
- package/docs/adr/0027-command-preview-width.md +10 -0
- package/docs/adr/0028-command-preview-120.md +8 -0
- package/docs/adr/0030-shared-web-read-cache.md +33 -0
- package/docs/adr/0031-quiet-compaction-progress.md +32 -0
- package/docs/adr/0032-native-background-schedules.md +58 -0
- package/docs/adr/0033-operator-scheduled-run.md +23 -0
- package/docs/adr/0034-machine-local-schedule-time.md +36 -0
- package/docs/adr/0035-external-business-task-extensions.md +56 -0
- package/docs/adr/0036-workspace-policy-and-neutral-service-id.md +37 -0
- package/docs/adr/0037-restart-during-in-flight-work.md +30 -0
- package/docs/adr/0038-restart-any-time.md +25 -0
- package/docs/adr/0039-rerun-interrupted-tools.md +24 -0
- package/docs/adr/0040-chat-progress-notices.md +44 -0
- package/docs/adr/0041-restart-and-recovery.md +28 -0
- package/docs/adr/0042-background-schedules-and-workspace-extensions.md +44 -0
- package/docs/adr/0043-remove-legacy-migration.md +23 -0
- package/docs/adr/0044-message-channels.md +32 -0
- package/docs/adr/0045-chat-scheduling-tools.md +51 -0
- package/docs/adr/0046-selective-command-redaction.md +31 -0
- package/docs/adr/0047-one-scheduling-path.md +158 -0
- package/docs/adr/README.md +50 -0
- package/docs/api.md +92 -0
- package/docs/architecture.md +164 -0
- package/docs/browser.md +93 -0
- package/docs/memory.md +27 -0
- package/docs/screenshot.png +0 -0
- package/docs/workspace-extensions.md +133 -0
- package/examples/workspace-extensions/system-context/index.ts +69 -0
- package/examples/workspace-extensions/system-context/package.json +3 -0
- package/ops/README.md +267 -0
- package/ops/preflight.mjs +28 -0
- package/package.json +36 -37
- package/dist/agent.d.ts +0 -84
- package/dist/agent.d.ts.map +0 -1
- package/dist/agent.js +0 -780
- package/dist/agent.js.map +0 -1
- package/dist/cli.d.ts +0 -15
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/imessage.d.ts +0 -33
- package/dist/imessage.d.ts.map +0 -1
- package/dist/imessage.js +0 -76
- package/dist/imessage.js.map +0 -1
- package/dist/logger.d.ts +0 -33
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -104
- package/dist/logger.js.map +0 -1
- package/dist/main.d.ts +0 -5
- package/dist/main.d.ts.map +0 -1
- package/dist/main.js.map +0 -1
- package/dist/memory.d.ts +0 -53
- package/dist/memory.d.ts.map +0 -1
- package/dist/memory.js +0 -196
- package/dist/memory.js.map +0 -1
- package/dist/model-health.d.ts +0 -11
- package/dist/model-health.d.ts.map +0 -1
- package/dist/model-health.js +0 -69
- package/dist/model-health.js.map +0 -1
- package/dist/pipeline.d.ts +0 -27
- package/dist/pipeline.d.ts.map +0 -1
- package/dist/pipeline.js +0 -59
- package/dist/pipeline.js.map +0 -1
- package/dist/queue.d.ts +0 -23
- package/dist/queue.d.ts.map +0 -1
- package/dist/queue.js +0 -89
- package/dist/queue.js.map +0 -1
- package/dist/reminders.d.ts +0 -42
- package/dist/reminders.d.ts.map +0 -1
- package/dist/reminders.js +0 -207
- package/dist/reminders.js.map +0 -1
- package/dist/rich-text.d.ts +0 -26
- package/dist/rich-text.d.ts.map +0 -1
- package/dist/rich-text.js.map +0 -1
- package/dist/self-echo.d.ts +0 -19
- package/dist/self-echo.d.ts.map +0 -1
- package/dist/self-echo.js +0 -54
- package/dist/self-echo.js.map +0 -1
- package/dist/send.d.ts +0 -24
- package/dist/send.d.ts.map +0 -1
- package/dist/send.js.map +0 -1
- package/dist/settings.d.ts +0 -44
- package/dist/settings.d.ts.map +0 -1
- package/dist/settings.js +0 -80
- package/dist/settings.js.map +0 -1
- package/dist/store.d.ts +0 -57
- package/dist/store.d.ts.map +0 -1
- package/dist/store.js +0 -124
- package/dist/store.js.map +0 -1
- package/dist/tasks.d.ts +0 -95
- package/dist/tasks.d.ts.map +0 -1
- package/dist/tasks.js +0 -384
- package/dist/tasks.js.map +0 -1
- package/dist/types.d.ts +0 -93
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -38
- package/dist/types.js.map +0 -1
- package/dist/watch.d.ts +0 -21
- package/dist/watch.d.ts.map +0 -1
- package/dist/watch.js +0 -219
- package/dist/watch.js.map +0 -1
- package/dist/web/data.d.ts +0 -11
- package/dist/web/data.d.ts.map +0 -1
- package/dist/web/data.js +0 -56
- package/dist/web/data.js.map +0 -1
- package/dist/web/html.d.ts +0 -5
- package/dist/web/html.d.ts.map +0 -1
- package/dist/web/html.js +0 -16
- package/dist/web/html.js.map +0 -1
- package/dist/web/index.d.ts +0 -25
- package/dist/web/index.d.ts.map +0 -1
- package/dist/web/index.js +0 -335
- package/dist/web/index.js.map +0 -1
- package/dist/web/render.d.ts +0 -11
- package/dist/web/render.d.ts.map +0 -1
- package/dist/web/render.js +0 -56
- package/dist/web/render.js.map +0 -1
- package/dist/web/templates/logs.eta +0 -75
- package/dist/web/templates/memory.eta +0 -91
- package/dist/web/templates/page.eta +0 -98
package/dist/tasks.js
DELETED
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pipeline task factories — each function creates a task for a specific
|
|
3
|
-
* pipeline phase. Tasks are pure functions with injected dependencies;
|
|
4
|
-
* the bot registers them without containing any business logic itself.
|
|
5
|
-
*
|
|
6
|
-
* before:
|
|
7
|
-
* logIncoming — logs the received message
|
|
8
|
-
* dropSelfEcho — drops messages that are echoes of the bot's own replies
|
|
9
|
-
* archiveImages — copies image attachments into chat/images/YYYY-MM-DD
|
|
10
|
-
* storeIncoming — persists the incoming message to log.jsonl
|
|
11
|
-
* checkReplyEnabled — drops messages when reply is disabled by settings
|
|
12
|
-
* downloadImages — reads image attachments from disk and populates incoming.images
|
|
13
|
-
* resizeImages — normalizes images for model-compatible input via macOS sips
|
|
14
|
-
*
|
|
15
|
-
* start:
|
|
16
|
-
* commandHandler — intercepts slash commands (/help, /new, /status, /reload) before the agent
|
|
17
|
-
* callAgent — sends the message to the agent and yields replies as they arrive
|
|
18
|
-
*
|
|
19
|
-
* end:
|
|
20
|
-
* sendReply — remembers echo, sends reply via Messages.app
|
|
21
|
-
* logOutgoing — logs the outgoing reply
|
|
22
|
-
* storeOutgoing — persists the outgoing reply to log.jsonl
|
|
23
|
-
*/
|
|
24
|
-
import { execFile } from "node:child_process";
|
|
25
|
-
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
26
|
-
import { tmpdir } from "node:os";
|
|
27
|
-
import { join } from "node:path";
|
|
28
|
-
import { promisify } from "node:util";
|
|
29
|
-
import { isReplyEnabled } from "./settings.js";
|
|
30
|
-
import { displayTarget, formatAgentReply } from "./types.js";
|
|
31
|
-
// ── Helpers ───────────────────────────────────────────────────────────────────
|
|
32
|
-
function messageTypeLabel(chat) {
|
|
33
|
-
if (chat.messageType === "group")
|
|
34
|
-
return "GROUP";
|
|
35
|
-
return chat.messageType === "sms" ? "SMS" : "DM";
|
|
36
|
-
}
|
|
37
|
-
function formatIncomingTarget(chat, incoming) {
|
|
38
|
-
return chat.messageType === "group" ? `${chat.groupName}|${incoming.sender}` : incoming.sender;
|
|
39
|
-
}
|
|
40
|
-
const HELP_TEXT = [
|
|
41
|
-
"Commands:",
|
|
42
|
-
"/help — list commands",
|
|
43
|
-
"/new — reset this chat session",
|
|
44
|
-
"/status — show session stats",
|
|
45
|
-
"/compact [instructions] — compress session context",
|
|
46
|
-
"/stop — stop the current agent run",
|
|
47
|
-
"/reload — reload models and clear sessions",
|
|
48
|
-
].join("\n");
|
|
49
|
-
// ── before tasks ──────────────────────────────────────────────────────────────
|
|
50
|
-
/**
|
|
51
|
-
* Log the incoming message to console. Always passes through.
|
|
52
|
-
*
|
|
53
|
-
* Examples:
|
|
54
|
-
* [sid] <- [DM] +16501234567: hey what's up
|
|
55
|
-
* [sid] <- [SMS] +16501234567: can you call me
|
|
56
|
-
* [sid] <- [GROUP] Family|+16501234567: dinner at 6? [2 attachment(s)]
|
|
57
|
-
*/
|
|
58
|
-
export function createLogIncomingTask(digestLogger) {
|
|
59
|
-
return (chat, incoming, outgoing) => {
|
|
60
|
-
const label = messageTypeLabel(chat);
|
|
61
|
-
const target = formatIncomingTarget(chat, incoming);
|
|
62
|
-
const attachmentNote = incoming.attachments.length > 0 ? ` [${incoming.attachments.length} attachment(s)]` : "";
|
|
63
|
-
digestLogger.log(`[sid] <- [${label}] ${target}: ${(incoming.text ?? "(attachment)").substring(0, 80)}${attachmentNote}`);
|
|
64
|
-
return outgoing;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
/** Copy image attachments into the chat workspace and update their paths before logging/reading. */
|
|
68
|
-
export function createArchiveImagesTask(store) {
|
|
69
|
-
return async (chat, incoming, outgoing) => {
|
|
70
|
-
try {
|
|
71
|
-
const archived = await store.archiveImages(chat.chatGuid, incoming);
|
|
72
|
-
if (archived.length > 0) {
|
|
73
|
-
console.log(`[sid] archived ${archived.length} image(s) for ${chat.chatGuid}`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
console.error(`[sid] failed to archive image attachments for ${chat.chatGuid}:`, error);
|
|
78
|
-
}
|
|
79
|
-
return outgoing;
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/** Persist the incoming message to log.jsonl. Always passes through. */
|
|
83
|
-
export function createStoreIncomingTask(store) {
|
|
84
|
-
return (chat, incoming, outgoing) => {
|
|
85
|
-
store
|
|
86
|
-
.log(chat.chatGuid, {
|
|
87
|
-
sender: incoming.sender,
|
|
88
|
-
text: incoming.text,
|
|
89
|
-
attachments: incoming.attachments.map((a) => a.path),
|
|
90
|
-
fromAgent: false,
|
|
91
|
-
messageType: chat.messageType,
|
|
92
|
-
...(chat.messageType === "group" && { groupName: chat.groupName }),
|
|
93
|
-
})
|
|
94
|
-
.catch((error) => {
|
|
95
|
-
console.error(`[sid] failed to store incoming message for ${chat.chatGuid}:`, error);
|
|
96
|
-
});
|
|
97
|
-
return outgoing;
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
/** Drop messages that are echoes of the bot's own replies. */
|
|
101
|
-
export function createDropSelfEchoTask(echoFilter) {
|
|
102
|
-
return (chat, incoming, outgoing) => {
|
|
103
|
-
if (incoming.text && echoFilter.isEcho(chat.chatGuid, incoming.text)) {
|
|
104
|
-
console.warn(`[sid] drop self-echo ${chat.chatGuid}: ${incoming.text.substring(0, 40)}`);
|
|
105
|
-
return { ...outgoing, shouldContinue: false };
|
|
106
|
-
}
|
|
107
|
-
return outgoing;
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Drop messages when reply is disabled for this chat by settings.
|
|
112
|
-
*
|
|
113
|
-
* Resolution priority (highest to lowest):
|
|
114
|
-
* blacklist["chatGuid"] > whitelist["chatGuid"] > blacklist["*"] > whitelist["*"]
|
|
115
|
-
*
|
|
116
|
-
* Examples:
|
|
117
|
-
* whitelist: ["*"] → reply to everyone
|
|
118
|
-
* whitelist: ["1"] → reply only to "1"
|
|
119
|
-
* whitelist: ["*"], bl: ["2"] → reply to everyone except "2"
|
|
120
|
-
* blacklist: ["*"] → log-only for all
|
|
121
|
-
* whitelist: ["1"], bl: ["*"] → reply only to "1"
|
|
122
|
-
* whitelist: ["1"], bl: ["1"] → no reply (blacklist wins)
|
|
123
|
-
*/
|
|
124
|
-
export function createCheckReplyEnabledTask(getSettings) {
|
|
125
|
-
return (chat, _incoming, outgoing) => {
|
|
126
|
-
if (!isReplyEnabled(getSettings(), chat.chatGuid)) {
|
|
127
|
-
console.log(`[sid] reply disabled for ${chat.chatGuid}, log-only`);
|
|
128
|
-
return { ...outgoing, shouldContinue: false };
|
|
129
|
-
}
|
|
130
|
-
return outgoing;
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Read image attachments from local disk and populate incoming.images in-place.
|
|
135
|
-
* Non-image attachments are skipped; failed reads are logged and silently skipped.
|
|
136
|
-
*/
|
|
137
|
-
export function createDownloadImagesTask() {
|
|
138
|
-
return async (_chat, incoming, outgoing) => {
|
|
139
|
-
const images = [];
|
|
140
|
-
for (const attachment of incoming.attachments) {
|
|
141
|
-
const mimeType = attachment.mimeType;
|
|
142
|
-
if (!mimeType?.startsWith("image/")) {
|
|
143
|
-
console.warn(`[sid] skipping non-image attachment ${attachment.path} (mimeType: ${mimeType ?? "null"})`);
|
|
144
|
-
continue;
|
|
145
|
-
}
|
|
146
|
-
try {
|
|
147
|
-
const bytes = await readFile(attachment.path);
|
|
148
|
-
images.push({ type: "image", mimeType, data: bytes.toString("base64") });
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
console.error(`[sid] failed to read image attachment ${attachment.path}:`, error);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
incoming.images = images;
|
|
155
|
-
return outgoing;
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Normalize image attachments before sending them to the model.
|
|
160
|
-
*
|
|
161
|
-
* OpenAI only accepts JPEG, PNG, GIF, and WebP image payloads. iMessage often
|
|
162
|
-
* stores camera images as HEIC, and corrupted/iCloud-placeholder files can also
|
|
163
|
-
* be tagged as image/* by chat.db. Unsupported formats are converted to JPEG;
|
|
164
|
-
* invalid images are dropped so one bad attachment cannot fail the whole prompt.
|
|
165
|
-
*/
|
|
166
|
-
const MAX_EDGE_PX = 1024;
|
|
167
|
-
const MODEL_IMAGE_MIME_TYPES = new Set(["image/jpeg", "image/png", "image/gif", "image/webp"]);
|
|
168
|
-
export function createResizeImagesTask() {
|
|
169
|
-
return async (_chat, incoming, outgoing) => {
|
|
170
|
-
const normalized = [];
|
|
171
|
-
for (const image of incoming.images) {
|
|
172
|
-
try {
|
|
173
|
-
normalized.push(await normalizeImageForModel(image));
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
console.warn(`[sid] skipping invalid or unsupported image (${image.mimeType}):`, error);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
incoming.images = normalized;
|
|
180
|
-
return outgoing;
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Convert unsupported formats to JPEG and resize oversized images.
|
|
185
|
-
* Returns supported images unchanged when already within limits.
|
|
186
|
-
*/
|
|
187
|
-
const execFileAsync = promisify(execFile);
|
|
188
|
-
async function normalizeImageForModel(image) {
|
|
189
|
-
const originalBytes = Buffer.from(image.data, "base64");
|
|
190
|
-
const originalSizeKB = (originalBytes.length / 1024).toFixed(0);
|
|
191
|
-
const tempDir = await mkdtemp(join(tmpdir(), "pi-imessage-image-"));
|
|
192
|
-
const inputPath = join(tempDir, "input");
|
|
193
|
-
const outputPath = join(tempDir, "output.jpg");
|
|
194
|
-
try {
|
|
195
|
-
await writeFile(inputPath, originalBytes);
|
|
196
|
-
const { stdout } = await execFileAsync("sips", ["-g", "pixelWidth", "-g", "pixelHeight", inputPath]);
|
|
197
|
-
const widthMatch = stdout.match(/pixelWidth:\s*(\d+)/);
|
|
198
|
-
const heightMatch = stdout.match(/pixelHeight:\s*(\d+)/);
|
|
199
|
-
const width = widthMatch ? Number.parseInt(widthMatch[1], 10) : 0;
|
|
200
|
-
const height = heightMatch ? Number.parseInt(heightMatch[1], 10) : 0;
|
|
201
|
-
const longestEdge = Math.max(width, height);
|
|
202
|
-
if (longestEdge <= 0) {
|
|
203
|
-
throw new Error("sips could not read image dimensions");
|
|
204
|
-
}
|
|
205
|
-
const needsConversion = !MODEL_IMAGE_MIME_TYPES.has(image.mimeType);
|
|
206
|
-
const needsResize = longestEdge > MAX_EDGE_PX;
|
|
207
|
-
if (!needsConversion && !needsResize) {
|
|
208
|
-
return image;
|
|
209
|
-
}
|
|
210
|
-
const sipsArgs = needsResize
|
|
211
|
-
? [
|
|
212
|
-
"--resampleHeightWidthMax",
|
|
213
|
-
String(MAX_EDGE_PX),
|
|
214
|
-
"-s",
|
|
215
|
-
"format",
|
|
216
|
-
"jpeg",
|
|
217
|
-
"-s",
|
|
218
|
-
"formatOptions",
|
|
219
|
-
"80",
|
|
220
|
-
inputPath,
|
|
221
|
-
"--out",
|
|
222
|
-
outputPath,
|
|
223
|
-
]
|
|
224
|
-
: ["-s", "format", "jpeg", "-s", "formatOptions", "80", inputPath, "--out", outputPath];
|
|
225
|
-
await execFileAsync("sips", sipsArgs);
|
|
226
|
-
const normalizedBytes = await readFile(outputPath);
|
|
227
|
-
const normalizedSizeKB = (normalizedBytes.length / 1024).toFixed(0);
|
|
228
|
-
const reason = [needsConversion ? `converted ${image.mimeType}→image/jpeg` : null, needsResize ? "resized" : null]
|
|
229
|
-
.filter(Boolean)
|
|
230
|
-
.join(", ");
|
|
231
|
-
console.log(`[sid] normalized image: ${reason} ${width}x${height} ${originalSizeKB}KB → ${normalizedSizeKB}KB`);
|
|
232
|
-
return { type: "image", mimeType: "image/jpeg", data: normalizedBytes.toString("base64") };
|
|
233
|
-
}
|
|
234
|
-
finally {
|
|
235
|
-
await rm(tempDir, { recursive: true, force: true });
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
// ── start tasks ───────────────────────────────────────────────────────────────
|
|
239
|
-
/**
|
|
240
|
-
* Intercept slash commands (e.g. "/help", "/new", "/status") before they reach the agent.
|
|
241
|
-
* Sets shouldContinue=false on the outgoing message to skip subsequent start tasks.
|
|
242
|
-
*
|
|
243
|
-
* Supported commands:
|
|
244
|
-
* /help — list available commands.
|
|
245
|
-
* /new — reset the agent session for this chat (equivalent to /new in pi coding agent).
|
|
246
|
-
* /status — show session stats: tokens, cost, context usage, model, thinking level.
|
|
247
|
-
* /compact [text] — compact context with optional custom instructions.
|
|
248
|
-
* /stop — stop the current agent run (handled before the per-chat queue).
|
|
249
|
-
* /reload — reload models and clear all sessions.
|
|
250
|
-
*/
|
|
251
|
-
export function createCommandHandlerTask(agent) {
|
|
252
|
-
return async (chat, incoming, outgoing, emit) => {
|
|
253
|
-
const text = incoming.text?.trim();
|
|
254
|
-
if (text === "/help") {
|
|
255
|
-
console.log(`[sid] /help command: ${chat.chatGuid} → listed commands`);
|
|
256
|
-
emit({ ...outgoing, reply: { type: "message", text: HELP_TEXT } });
|
|
257
|
-
outgoing.shouldContinue = false;
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
if (text === "/new") {
|
|
261
|
-
await agent.newSession(chat.chatGuid);
|
|
262
|
-
const newSessionReply = "✓ New session started";
|
|
263
|
-
console.log(`[sid] /new command: ${chat.chatGuid} → ${newSessionReply}`);
|
|
264
|
-
emit({ ...outgoing, reply: { type: "message", text: newSessionReply } });
|
|
265
|
-
const statusReply = await agent.getSessionStatus(chat.chatGuid);
|
|
266
|
-
console.log(`[sid] /new status: ${chat.chatGuid} → ${statusReply}`);
|
|
267
|
-
emit({ ...outgoing, reply: { type: "message", text: statusReply } });
|
|
268
|
-
outgoing.shouldContinue = false;
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
if (text === "/status") {
|
|
272
|
-
const replyText = await agent.getSessionStatus(chat.chatGuid);
|
|
273
|
-
console.log(`[sid] /status command: ${chat.chatGuid} → ${replyText}`);
|
|
274
|
-
emit({ ...outgoing, reply: { type: "message", text: replyText } });
|
|
275
|
-
outgoing.shouldContinue = false;
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
if (text?.startsWith("/compact")) {
|
|
279
|
-
const customInstructions = text.slice("/compact".length).trim() || undefined;
|
|
280
|
-
const compactReply = await agent.compact(chat.chatGuid, customInstructions);
|
|
281
|
-
console.log(`[sid] /compact command: ${chat.chatGuid} → ${compactReply}`);
|
|
282
|
-
emit({ ...outgoing, reply: { type: "message", text: compactReply } });
|
|
283
|
-
const statusReply = await agent.getSessionStatus(chat.chatGuid);
|
|
284
|
-
console.log(`[sid] /compact status: ${chat.chatGuid} → ${statusReply}`);
|
|
285
|
-
emit({ ...outgoing, reply: { type: "message", text: statusReply } });
|
|
286
|
-
outgoing.shouldContinue = false;
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
if (text === "/reload") {
|
|
290
|
-
await agent.reload(chat.chatGuid);
|
|
291
|
-
const statusReply = await agent.getSessionStatus(chat.chatGuid);
|
|
292
|
-
const replyText = `✓ Models reloaded\n${statusReply}`;
|
|
293
|
-
console.log(`[sid] /reload command: ${chat.chatGuid} → ${replyText}`);
|
|
294
|
-
emit({ ...outgoing, reply: { type: "message", text: replyText } });
|
|
295
|
-
outgoing.shouldContinue = false;
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
/** Decorator: wrap a StartTask with retry logic for transient errors. */
|
|
301
|
-
function withRetry(task, options) {
|
|
302
|
-
return async (chat, incoming, outgoing, emit) => {
|
|
303
|
-
const { delays, retryable } = options;
|
|
304
|
-
for (let attempt = 0;; attempt++) {
|
|
305
|
-
try {
|
|
306
|
-
await task(chat, incoming, outgoing, emit);
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
309
|
-
catch (error) {
|
|
310
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
311
|
-
if (attempt >= delays.length || !retryable(message))
|
|
312
|
-
throw error;
|
|
313
|
-
const delay = delays[attempt];
|
|
314
|
-
console.log(`[agent] retrying ${chat.chatGuid} (attempt ${attempt + 2}/${delays.length + 1}) ` +
|
|
315
|
-
`in ${delay / 1000}s: ${message.substring(0, 80)}`);
|
|
316
|
-
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
/** Send the message to the agent and dispatch a reply for each agent turn. */
|
|
322
|
-
export function createCallAgentTask(agent) {
|
|
323
|
-
const task = async (_chat, incoming, outgoing, emit) => {
|
|
324
|
-
await agent.processMessage(incoming, async (agentReply) => {
|
|
325
|
-
const text = formatAgentReply(agentReply);
|
|
326
|
-
emit({ ...outgoing, reply: { type: "message", text } });
|
|
327
|
-
});
|
|
328
|
-
};
|
|
329
|
-
return withRetry(task, {
|
|
330
|
-
delays: [1000, 5000, 10000],
|
|
331
|
-
retryable: (msg) => msg.includes("timed out") || msg.includes("Authentication failed"),
|
|
332
|
-
});
|
|
333
|
-
}
|
|
334
|
-
// ── end tasks ─────────────────────────────────────────────────────────────────
|
|
335
|
-
/** Remember echo and send reply via Messages.app AppleScript. */
|
|
336
|
-
export function createSendReplyTask(echoFilter, sender, getSettings) {
|
|
337
|
-
return async (chat, outgoing) => {
|
|
338
|
-
if (outgoing.reply.type === "message") {
|
|
339
|
-
echoFilter.remember(chat.chatGuid, outgoing.reply.text);
|
|
340
|
-
await sender.sendMessage(chat.chatGuid, outgoing.reply.text, getSettings().richText);
|
|
341
|
-
}
|
|
342
|
-
return outgoing;
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Log the outgoing reply to console.
|
|
347
|
-
*
|
|
348
|
-
* Examples:
|
|
349
|
-
* [sid] -> [DM] +16501234567: sure, I'll check
|
|
350
|
-
* [sid] -> [SMS] +16501234567: got it
|
|
351
|
-
* [sid] -> [GROUP] Family: sounds good!
|
|
352
|
-
*/
|
|
353
|
-
export function createLogOutgoingTask(digestLogger) {
|
|
354
|
-
return (chat, outgoing) => {
|
|
355
|
-
const { reply } = outgoing;
|
|
356
|
-
if (reply.type === "message") {
|
|
357
|
-
const label = messageTypeLabel(chat);
|
|
358
|
-
const target = displayTarget(chat);
|
|
359
|
-
digestLogger.log(`[sid] -> [${label}] ${target}: ${reply.text.substring(0, 80)}`);
|
|
360
|
-
}
|
|
361
|
-
return outgoing;
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
/** Persist the outgoing reply to log.jsonl. */
|
|
365
|
-
export function createStoreOutgoingTask(store) {
|
|
366
|
-
return (chat, outgoing) => {
|
|
367
|
-
if (outgoing.reply.type === "message") {
|
|
368
|
-
store
|
|
369
|
-
.log(chat.chatGuid, {
|
|
370
|
-
sender: "bot",
|
|
371
|
-
text: outgoing.reply.text,
|
|
372
|
-
attachments: [],
|
|
373
|
-
fromAgent: true,
|
|
374
|
-
messageType: chat.messageType,
|
|
375
|
-
...(chat.messageType === "group" && { groupName: chat.groupName }),
|
|
376
|
-
})
|
|
377
|
-
.catch((error) => {
|
|
378
|
-
console.error(`[sid] failed to store outgoing message for ${chat.chatGuid}:`, error);
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
return outgoing;
|
|
382
|
-
};
|
|
383
|
-
}
|
|
384
|
-
//# sourceMappingURL=tasks.js.map
|
package/dist/tasks.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../src/tasks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE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,KAAK,CAAC,CAAC;YACtF,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared types for the iMessage bot pipeline.
|
|
3
|
-
*/
|
|
4
|
-
import type { ImageContent } from "@earendil-works/pi-ai";
|
|
5
|
-
/**
|
|
6
|
-
* Message type, derived from service and chatGuid structure:
|
|
7
|
-
*
|
|
8
|
-
* service chatGuid segment MessageType
|
|
9
|
-
* ────────── ─────────────── ───────────
|
|
10
|
-
* "SMS" (any) "sms"
|
|
11
|
-
* "iMessage" ";-;" (DM) "imessage"
|
|
12
|
-
* "iMessage" ";+;" (group) "group"
|
|
13
|
-
*/
|
|
14
|
-
export type MessageType = "sms" | "imessage" | "group";
|
|
15
|
-
/**
|
|
16
|
-
* Chat-level identity — fixed per chat session.
|
|
17
|
-
* Passed as a first-class parameter through all pipeline tasks.
|
|
18
|
-
*/
|
|
19
|
-
export interface ChatContext {
|
|
20
|
-
chatGuid: string;
|
|
21
|
-
messageType: MessageType;
|
|
22
|
-
groupName: string;
|
|
23
|
-
}
|
|
24
|
-
/** Extract ChatContext from an IncomingMessage. */
|
|
25
|
-
export declare function toChatContext(msg: IncomingMessage): ChatContext;
|
|
26
|
-
/**
|
|
27
|
-
* Human-readable display target for a chat.
|
|
28
|
-
* DM/SMS → address extracted from chatGuid ("iMessage;-;+1234" → "+1234")
|
|
29
|
-
* Group → group name
|
|
30
|
-
*/
|
|
31
|
-
export declare function displayTarget(chat: ChatContext): string;
|
|
32
|
-
/** Attachment metadata — local path on disk. */
|
|
33
|
-
export interface Attachment {
|
|
34
|
-
/** Local file path (e.g. ~/Library/Messages/Attachments/...). */
|
|
35
|
-
path: string;
|
|
36
|
-
mimeType: string | null;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Unified incoming message flowing through the entire pipeline.
|
|
40
|
-
*
|
|
41
|
-
* Fully assembled by the watcher — images starts empty and is populated
|
|
42
|
-
* by the downloadImages pipeline task.
|
|
43
|
-
*/
|
|
44
|
-
export interface IncomingMessage {
|
|
45
|
-
chatGuid: string;
|
|
46
|
-
text: string | null;
|
|
47
|
-
sender: string;
|
|
48
|
-
messageType: MessageType;
|
|
49
|
-
groupName: string;
|
|
50
|
-
/** Text of the message being replied to (inline reply / quote), if any. */
|
|
51
|
-
replyToText: string | null;
|
|
52
|
-
/** Attachment file paths — populated by the watcher from chat.db. */
|
|
53
|
-
attachments: Attachment[];
|
|
54
|
-
/** Image attachments, read and base64-encoded by the downloadImages pipeline task. */
|
|
55
|
-
images: ImageContent[];
|
|
56
|
-
}
|
|
57
|
-
/** Structured reply from the agent — preserves semantic type for formatting. */
|
|
58
|
-
export type AgentReply = {
|
|
59
|
-
kind: "assistant";
|
|
60
|
-
text: string;
|
|
61
|
-
} | {
|
|
62
|
-
kind: "tool_start";
|
|
63
|
-
label: string;
|
|
64
|
-
} | {
|
|
65
|
-
kind: "tool_end";
|
|
66
|
-
toolName: string;
|
|
67
|
-
symbol: string;
|
|
68
|
-
duration: string;
|
|
69
|
-
result: string;
|
|
70
|
-
};
|
|
71
|
-
/** Format an AgentReply into a plain-text iMessage string. */
|
|
72
|
-
export declare function formatAgentReply(reply: AgentReply): string;
|
|
73
|
-
/** What kind of reply the bot should send back. */
|
|
74
|
-
export type ReplyAction = {
|
|
75
|
-
type: "message";
|
|
76
|
-
text: string;
|
|
77
|
-
} | {
|
|
78
|
-
type: "none";
|
|
79
|
-
};
|
|
80
|
-
/**
|
|
81
|
-
* Structured pipeline response, carried as context through all phases.
|
|
82
|
-
*
|
|
83
|
-
* reply — the reply action to perform (text or nothing).
|
|
84
|
-
* shouldContinue — if false, remaining tasks in the current phase and all
|
|
85
|
-
* later phases are skipped.
|
|
86
|
-
*/
|
|
87
|
-
export interface OutgoingMessage {
|
|
88
|
-
reply: ReplyAction;
|
|
89
|
-
shouldContinue: boolean;
|
|
90
|
-
}
|
|
91
|
-
/** Create a default OutgoingMessage (no reply, continue processing). */
|
|
92
|
-
export declare function createOutgoingMessage(): OutgoingMessage;
|
|
93
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,UAAU,GAAG,OAAO,CAAC;AAIvD;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED,mDAAmD;AACnD,wBAAgB,aAAa,CAAC,GAAG,EAAE,eAAe,GAAG,WAAW,CAE/D;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAGvD;AAED,gDAAgD;AAChD,MAAM,WAAW,UAAU;IAC1B,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,qEAAqE;IACrE,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,sFAAsF;IACtF,MAAM,EAAE,YAAY,EAAE,CAAC;CACvB;AAID,gFAAgF;AAChF,MAAM,MAAM,UAAU,GACnB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAI5F,8DAA8D;AAC9D,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAY1D;AAID,mDAAmD;AACnD,MAAM,MAAM,WAAW,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC/B,KAAK,EAAE,WAAW,CAAC;IACnB,cAAc,EAAE,OAAO,CAAC;CACxB;AAED,wEAAwE;AACxE,wBAAgB,qBAAqB,IAAI,eAAe,CAEvD"}
|
package/dist/types.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared types for the iMessage bot pipeline.
|
|
3
|
-
*/
|
|
4
|
-
/** Extract ChatContext from an IncomingMessage. */
|
|
5
|
-
export function toChatContext(msg) {
|
|
6
|
-
return { chatGuid: msg.chatGuid, messageType: msg.messageType, groupName: msg.groupName };
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Human-readable display target for a chat.
|
|
10
|
-
* DM/SMS → address extracted from chatGuid ("iMessage;-;+1234" → "+1234")
|
|
11
|
-
* Group → group name
|
|
12
|
-
*/
|
|
13
|
-
export function displayTarget(chat) {
|
|
14
|
-
if (chat.messageType === "group")
|
|
15
|
-
return chat.groupName;
|
|
16
|
-
return chat.chatGuid.split(";").pop() ?? chat.chatGuid;
|
|
17
|
-
}
|
|
18
|
-
const MAX_TOOL_RESULT_LINES = 5;
|
|
19
|
-
/** Format an AgentReply into a plain-text iMessage string. */
|
|
20
|
-
export function formatAgentReply(reply) {
|
|
21
|
-
if (reply.kind === "assistant")
|
|
22
|
-
return reply.text;
|
|
23
|
-
if (reply.kind === "tool_start")
|
|
24
|
-
return `→ ${reply.label}`;
|
|
25
|
-
// tool_end: header + result truncated to MAX_TOOL_RESULT_LINES
|
|
26
|
-
const header = `${reply.symbol} ${reply.toolName} (${reply.duration}s)`;
|
|
27
|
-
const lines = reply.result.split("\n");
|
|
28
|
-
if (lines.length > MAX_TOOL_RESULT_LINES) {
|
|
29
|
-
const truncated = lines.slice(0, MAX_TOOL_RESULT_LINES).join("\n");
|
|
30
|
-
return `${header}\n${truncated}\n…`;
|
|
31
|
-
}
|
|
32
|
-
return `${header}\n${reply.result}`;
|
|
33
|
-
}
|
|
34
|
-
/** Create a default OutgoingMessage (no reply, continue processing). */
|
|
35
|
-
export function createOutgoingMessage() {
|
|
36
|
-
return { reply: { type: "none" }, shouldContinue: true };
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AA2BH,mDAAmD;AACnD,MAAM,UAAU,aAAa,CAAC,GAAoB;IACjD,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC;AAC3F,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAiB;IAC9C,IAAI,IAAI,CAAC,WAAW,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC;IACxD,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,QAAQ,CAAC;AACxD,CAAC;AAqCD,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEhC,8DAA8D;AAC9D,MAAM,UAAU,gBAAgB,CAAC,KAAiB;IACjD,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC;IAClD,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY;QAAE,OAAO,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;IAE3D,+DAA+D;IAC/D,MAAM,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,IAAI,CAAC;IACxE,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,KAAK,CAAC,MAAM,GAAG,qBAAqB,EAAE,CAAC;QAC1C,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnE,OAAO,GAAG,MAAM,KAAK,SAAS,KAAK,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;AACrC,CAAC;AAmBD,wEAAwE;AACxE,MAAM,UAAU,qBAAqB;IACpC,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC;AAC1D,CAAC"}
|
package/dist/watch.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Watch for new iMessages by polling ~/Library/Messages/chat.db.
|
|
3
|
-
*
|
|
4
|
-
* ┌──────────┐ poll ┌──────────┐ push ┌───────┐
|
|
5
|
-
* │ chat.db │ ──────> │ watch.ts │ ──────> │ queue │
|
|
6
|
-
* └──────────┘ └──────────┘ └───────┘
|
|
7
|
-
*
|
|
8
|
-
* Replaces BlueBubbles webhook monitor — no server, no external dependency.
|
|
9
|
-
* Requires Full Disk Access for the terminal / Node process.
|
|
10
|
-
*/
|
|
11
|
-
import type { AsyncQueue } from "./queue.js";
|
|
12
|
-
import type { IncomingMessage } from "./types.js";
|
|
13
|
-
export interface WatcherConfig {
|
|
14
|
-
queue: AsyncQueue<IncomingMessage>;
|
|
15
|
-
pollIntervalMs?: number;
|
|
16
|
-
}
|
|
17
|
-
export declare function createWatcher(config: WatcherConfig): {
|
|
18
|
-
start(): void;
|
|
19
|
-
stop(): void;
|
|
20
|
-
};
|
|
21
|
-
//# sourceMappingURL=watch.d.ts.map
|
package/dist/watch.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../src/watch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAc,eAAe,EAAe,MAAM,YAAY,CAAC;AA0E3E,MAAM,WAAW,aAAa;IAC7B,KAAK,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;IACnC,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa;aAsJxC,IAAI;YAOL,IAAI;EAUb"}
|