birdclaw 0.5.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +92 -1
- package/README.md +75 -5
- package/package.json +8 -2
- package/scripts/browser-perf.mjs +1 -0
- package/scripts/start-test-server.mjs +16 -3
- package/src/cli.ts +812 -37
- package/src/components/AccountSwitcher.tsx +186 -0
- package/src/components/AppNav.tsx +37 -7
- package/src/components/AvatarChip.tsx +9 -3
- package/src/components/DmWorkspace.tsx +18 -8
- package/src/components/LinkPreviewCard.tsx +40 -18
- package/src/components/MarkdownViewer.tsx +818 -0
- package/src/components/ProfileAnalysisStream.tsx +428 -0
- package/src/components/ProfilePreview.tsx +120 -9
- package/src/components/SavedTimelineView.tsx +30 -8
- package/src/components/SyncNowButton.tsx +60 -25
- package/src/components/ThemeSlider.tsx +55 -50
- package/src/components/TimelineCard.tsx +240 -92
- package/src/components/TimelineRouteFrame.tsx +38 -8
- package/src/components/TweetMediaGrid.tsx +87 -38
- package/src/components/TweetRichText.tsx +45 -17
- package/src/components/account-selection.ts +64 -0
- package/src/components/useTimelineRouteData.ts +97 -13
- package/src/lib/account-sync-job.ts +666 -0
- package/src/lib/actions-transport.ts +216 -146
- package/src/lib/api-client.ts +128 -53
- package/src/lib/archive-finder.ts +78 -63
- package/src/lib/archive-import.ts +1593 -1291
- package/src/lib/authored-live.ts +262 -204
- package/src/lib/avatar-cache.ts +208 -43
- package/src/lib/backup.ts +1536 -954
- package/src/lib/bird-actions.ts +139 -57
- package/src/lib/bird-command.ts +101 -28
- package/src/lib/bird.ts +582 -194
- package/src/lib/blocklist.ts +40 -23
- package/src/lib/blocks-write.ts +129 -80
- package/src/lib/blocks.ts +165 -97
- package/src/lib/bookmark-sync-job.ts +250 -160
- package/src/lib/config.ts +35 -2
- package/src/lib/conversation-surface.ts +79 -48
- package/src/lib/data-sources.ts +219 -0
- package/src/lib/db.ts +95 -4
- package/src/lib/dms-live.ts +720 -66
- package/src/lib/effect-runtime.ts +45 -0
- package/src/lib/follow-graph.ts +224 -180
- package/src/lib/geocoding.ts +296 -0
- package/src/lib/http-effect.ts +222 -0
- package/src/lib/inbox.ts +74 -43
- package/src/lib/link-index.ts +88 -76
- package/src/lib/link-insights.ts +24 -0
- package/src/lib/link-preview-metadata.ts +472 -52
- package/src/lib/location.ts +137 -0
- package/src/lib/media-fetch.ts +286 -213
- package/src/lib/mention-threads-live.ts +445 -288
- package/src/lib/mentions-live.ts +549 -354
- package/src/lib/moderation-target.ts +102 -65
- package/src/lib/moderation-write.ts +77 -18
- package/src/lib/mutes-write.ts +129 -80
- package/src/lib/mutes.ts +8 -1
- package/src/lib/network-map.ts +382 -0
- package/src/lib/openai.ts +84 -53
- package/src/lib/period-digest.ts +1317 -0
- package/src/lib/profile-affiliation-hydration.ts +93 -54
- package/src/lib/profile-analysis.ts +1272 -0
- package/src/lib/profile-bio-entities.ts +1 -1
- package/src/lib/profile-hydration.ts +124 -72
- package/src/lib/profile-replies.ts +60 -43
- package/src/lib/profile-resolver.ts +402 -294
- package/src/lib/queries.ts +983 -203
- package/src/lib/research.ts +165 -120
- package/src/lib/search-discussion.ts +1016 -0
- package/src/lib/sqlite.ts +1 -0
- package/src/lib/timeline-collections-live.ts +204 -167
- package/src/lib/timeline-live.ts +325 -51
- package/src/lib/tweet-account-edges.ts +2 -0
- package/src/lib/tweet-lookup.ts +30 -19
- package/src/lib/tweet-render.ts +141 -1
- package/src/lib/tweet-search-live.ts +565 -0
- package/src/lib/types.ts +75 -3
- package/src/lib/ui.ts +31 -8
- package/src/lib/url-expansion.ts +226 -55
- package/src/lib/url-safety.ts +220 -0
- package/src/lib/web-sync.ts +222 -149
- package/src/lib/whois.ts +166 -147
- package/src/lib/x-web.ts +102 -71
- package/src/lib/xurl-rate-limits.ts +267 -0
- package/src/lib/xurl.ts +1185 -405
- package/src/routeTree.gen.ts +273 -0
- package/src/routes/__root.tsx +24 -5
- package/src/routes/api/action.tsx +127 -78
- package/src/routes/api/avatar.tsx +39 -30
- package/src/routes/api/blocks.tsx +26 -23
- package/src/routes/api/conversation.tsx +25 -14
- package/src/routes/api/data-sources.tsx +24 -0
- package/src/routes/api/inbox.tsx +27 -21
- package/src/routes/api/link-insights.tsx +31 -25
- package/src/routes/api/link-preview.tsx +25 -21
- package/src/routes/api/network-map.tsx +55 -0
- package/src/routes/api/period-digest.tsx +133 -0
- package/src/routes/api/profile-analysis.tsx +152 -0
- package/src/routes/api/profile-hydrate.tsx +31 -28
- package/src/routes/api/query.tsx +80 -55
- package/src/routes/api/search-discussion.tsx +169 -0
- package/src/routes/api/status.tsx +18 -10
- package/src/routes/api/sync.tsx +75 -29
- package/src/routes/api/xurl-rate-limits.tsx +24 -0
- package/src/routes/data-sources.tsx +255 -0
- package/src/routes/discuss.tsx +419 -0
- package/src/routes/dms.tsx +95 -28
- package/src/routes/inbox.tsx +32 -19
- package/src/routes/network-map.tsx +1035 -0
- package/src/routes/profile-analyze.tsx +112 -0
- package/src/routes/profiles.$handle.tsx +228 -0
- package/src/routes/rate-limits.tsx +309 -0
- package/src/routes/today.tsx +455 -0
- package/src/styles.css +22 -0
|
@@ -3,12 +3,17 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
|
+
import { Effect } from "effect";
|
|
6
7
|
import type { Database } from "./sqlite";
|
|
7
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
maybeAutoSyncBackupEffect,
|
|
10
|
+
type BackupAutoUpdateResult,
|
|
11
|
+
} from "./backup";
|
|
8
12
|
import { ensureBirdclawDirs, getBirdclawPaths } from "./config";
|
|
9
13
|
import { getNativeDb } from "./db";
|
|
14
|
+
import { runEffectPromise, tryPromise } from "./effect-runtime";
|
|
10
15
|
import {
|
|
11
|
-
|
|
16
|
+
syncTimelineCollectionEffect,
|
|
12
17
|
type TimelineCollectionMode,
|
|
13
18
|
} from "./timeline-collections-live";
|
|
14
19
|
|
|
@@ -124,53 +129,98 @@ function countBookmarks(db: Database) {
|
|
|
124
129
|
return row.count;
|
|
125
130
|
}
|
|
126
131
|
|
|
127
|
-
|
|
132
|
+
function toError(error: unknown) {
|
|
133
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function trySync<T>(try_: () => T) {
|
|
137
|
+
return Effect.try({
|
|
138
|
+
try: try_,
|
|
139
|
+
catch: toError,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function appendAuditEntryEffect(
|
|
128
144
|
logPath: string,
|
|
129
145
|
entry: BookmarkSyncAuditEntry,
|
|
130
146
|
) {
|
|
131
|
-
|
|
132
|
-
|
|
147
|
+
return Effect.gen(function* () {
|
|
148
|
+
yield* tryPromise(() =>
|
|
149
|
+
fs.mkdir(path.dirname(logPath), { recursive: true }),
|
|
150
|
+
);
|
|
151
|
+
yield* tryPromise(() =>
|
|
152
|
+
fs.appendFile(logPath, `${JSON.stringify(entry)}\n`, "utf8"),
|
|
153
|
+
);
|
|
154
|
+
});
|
|
133
155
|
}
|
|
134
156
|
|
|
135
157
|
function messageFromError(error: unknown) {
|
|
136
158
|
return error instanceof Error ? error.message : String(error);
|
|
137
159
|
}
|
|
138
160
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
161
|
+
function isFileExistsError(error: unknown) {
|
|
162
|
+
return (
|
|
163
|
+
typeof error === "object" &&
|
|
164
|
+
error !== null &&
|
|
165
|
+
"code" in error &&
|
|
166
|
+
error.code === "EEXIST"
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function acquireLockEffect(
|
|
171
|
+
lockPath: string,
|
|
172
|
+
): Effect.Effect<(() => Effect.Effect<void, never>) | undefined, unknown> {
|
|
173
|
+
return Effect.gen(function* () {
|
|
174
|
+
yield* tryPromise(() =>
|
|
175
|
+
fs.mkdir(path.dirname(lockPath), { recursive: true }),
|
|
150
176
|
);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
) {
|
|
162
|
-
const stats =
|
|
177
|
+
const handleResult = yield* tryPromise(() => fs.open(lockPath, "wx")).pipe(
|
|
178
|
+
Effect.map((handle) => ({ handle, ok: true as const })),
|
|
179
|
+
Effect.catchAll((error) => {
|
|
180
|
+
if (isFileExistsError(error)) {
|
|
181
|
+
return Effect.succeed({ error, ok: false as const });
|
|
182
|
+
}
|
|
183
|
+
return Effect.fail(error);
|
|
184
|
+
}),
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
if (!handleResult.ok) {
|
|
188
|
+
const stats = yield* tryPromise(() => fs.stat(lockPath)).pipe(
|
|
189
|
+
Effect.catchAll(() => Effect.succeed(undefined)),
|
|
190
|
+
);
|
|
163
191
|
if (stats && Date.now() - stats.mtimeMs > DEFAULT_LOCK_STALE_MS) {
|
|
164
|
-
|
|
165
|
-
return
|
|
192
|
+
yield* tryPromise(() => fs.rm(lockPath, { force: true }));
|
|
193
|
+
return yield* acquireLockEffect(lockPath);
|
|
166
194
|
}
|
|
167
195
|
return undefined;
|
|
168
196
|
}
|
|
169
|
-
|
|
170
|
-
|
|
197
|
+
|
|
198
|
+
const { handle } = handleResult;
|
|
199
|
+
yield* tryPromise(() =>
|
|
200
|
+
handle.writeFile(
|
|
201
|
+
`${JSON.stringify({
|
|
202
|
+
pid: process.pid,
|
|
203
|
+
host: os.hostname(),
|
|
204
|
+
startedAt: new Date().toISOString(),
|
|
205
|
+
})}\n`,
|
|
206
|
+
"utf8",
|
|
207
|
+
),
|
|
208
|
+
).pipe(
|
|
209
|
+
Effect.ensuring(
|
|
210
|
+
tryPromise(() => handle.close()).pipe(
|
|
211
|
+
Effect.catchAll(() => Effect.void),
|
|
212
|
+
),
|
|
213
|
+
),
|
|
214
|
+
);
|
|
215
|
+
return () =>
|
|
216
|
+
tryPromise(() => fs.rm(lockPath, { force: true })).pipe(
|
|
217
|
+
Effect.asVoid,
|
|
218
|
+
Effect.catchAll(() => Effect.void),
|
|
219
|
+
);
|
|
220
|
+
});
|
|
171
221
|
}
|
|
172
222
|
|
|
173
|
-
export
|
|
223
|
+
export function runBookmarkSyncJobEffect({
|
|
174
224
|
account,
|
|
175
225
|
mode = "auto",
|
|
176
226
|
limit = DEFAULT_BOOKMARK_SYNC_LIMIT,
|
|
@@ -181,107 +231,127 @@ export async function runBookmarkSyncJob({
|
|
|
181
231
|
logPath,
|
|
182
232
|
lockPath,
|
|
183
233
|
db,
|
|
184
|
-
}: BookmarkSyncJobOptions = {}):
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const releaseLock = await acquireLock(resolvedLockPath);
|
|
208
|
-
if (!releaseLock) {
|
|
209
|
-
const finished = Date.now();
|
|
210
|
-
const entry: BookmarkSyncAuditEntry = {
|
|
211
|
-
job: "bookmarks-sync",
|
|
212
|
-
ok: true,
|
|
213
|
-
startedAt,
|
|
214
|
-
finishedAt: new Date(finished).toISOString(),
|
|
215
|
-
durationMs: finished - started,
|
|
216
|
-
host: os.hostname(),
|
|
217
|
-
pid: process.pid,
|
|
218
|
-
options,
|
|
219
|
-
before,
|
|
220
|
-
after: before,
|
|
221
|
-
added: 0,
|
|
222
|
-
skipped: "already-running",
|
|
223
|
-
};
|
|
224
|
-
await appendAuditEntry(resolvedLogPath, entry);
|
|
225
|
-
return entry;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
try {
|
|
229
|
-
const sync = await syncTimelineCollection({
|
|
230
|
-
kind: "bookmarks",
|
|
231
|
-
account,
|
|
234
|
+
}: BookmarkSyncJobOptions = {}): Effect.Effect<
|
|
235
|
+
BookmarkSyncAuditEntry,
|
|
236
|
+
unknown
|
|
237
|
+
> {
|
|
238
|
+
return Effect.gen(function* () {
|
|
239
|
+
yield* trySync(() => ensureBirdclawDirs());
|
|
240
|
+
const database =
|
|
241
|
+
db ?? (yield* trySync(() => getNativeDb({ seedDemoData: false })));
|
|
242
|
+
const resolvedLogPath = yield* trySync(() =>
|
|
243
|
+
resolvePath(logPath ?? getDefaultBookmarkSyncAuditLogPath()),
|
|
244
|
+
);
|
|
245
|
+
const resolvedLockPath = yield* trySync(() =>
|
|
246
|
+
resolvePath(lockPath ?? getDefaultBookmarkSyncLockPath()),
|
|
247
|
+
);
|
|
248
|
+
const effectiveAll = all ?? maxPages !== undefined;
|
|
249
|
+
const started = Date.now();
|
|
250
|
+
const startedAt = new Date(started).toISOString();
|
|
251
|
+
const before = yield* trySync(() => ({
|
|
252
|
+
bookmarks: countBookmarks(database),
|
|
253
|
+
}));
|
|
254
|
+
const options = {
|
|
255
|
+
...(account ? { account } : {}),
|
|
232
256
|
mode,
|
|
233
257
|
limit,
|
|
234
258
|
all: effectiveAll,
|
|
235
|
-
maxPages,
|
|
259
|
+
...(maxPages === undefined ? {} : { maxPages }),
|
|
236
260
|
refresh,
|
|
237
|
-
cacheTtlMs,
|
|
238
|
-
});
|
|
239
|
-
const backup = await maybeAutoSyncBackup(database);
|
|
240
|
-
const finished = Date.now();
|
|
241
|
-
const after = { bookmarks: countBookmarks(database) };
|
|
242
|
-
const entry: BookmarkSyncAuditEntry = {
|
|
243
|
-
job: "bookmarks-sync",
|
|
244
|
-
ok: true,
|
|
245
|
-
startedAt,
|
|
246
|
-
finishedAt: new Date(finished).toISOString(),
|
|
247
|
-
durationMs: finished - started,
|
|
248
|
-
host: os.hostname(),
|
|
249
|
-
pid: process.pid,
|
|
250
|
-
options,
|
|
251
|
-
before,
|
|
252
|
-
after,
|
|
253
|
-
added: Math.max(0, after.bookmarks - before.bookmarks),
|
|
254
|
-
sync: {
|
|
255
|
-
source: sync.source,
|
|
256
|
-
count: sync.count,
|
|
257
|
-
accountId: sync.accountId,
|
|
258
|
-
},
|
|
259
|
-
backup,
|
|
261
|
+
...(cacheTtlMs === undefined ? {} : { cacheTtlMs }),
|
|
260
262
|
};
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
263
|
+
|
|
264
|
+
const releaseLock = yield* acquireLockEffect(resolvedLockPath);
|
|
265
|
+
if (!releaseLock) {
|
|
266
|
+
const finished = Date.now();
|
|
267
|
+
const entry: BookmarkSyncAuditEntry = {
|
|
268
|
+
job: "bookmarks-sync",
|
|
269
|
+
ok: true,
|
|
270
|
+
startedAt,
|
|
271
|
+
finishedAt: new Date(finished).toISOString(),
|
|
272
|
+
durationMs: finished - started,
|
|
273
|
+
host: os.hostname(),
|
|
274
|
+
pid: process.pid,
|
|
275
|
+
options,
|
|
276
|
+
before,
|
|
277
|
+
after: before,
|
|
278
|
+
added: 0,
|
|
279
|
+
skipped: "already-running",
|
|
280
|
+
};
|
|
281
|
+
yield* appendAuditEntryEffect(resolvedLogPath, entry);
|
|
282
|
+
return entry;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return yield* Effect.gen(function* () {
|
|
286
|
+
const result = yield* Effect.gen(function* () {
|
|
287
|
+
const sync = yield* syncTimelineCollectionEffect({
|
|
288
|
+
kind: "bookmarks",
|
|
289
|
+
account,
|
|
290
|
+
mode,
|
|
291
|
+
limit,
|
|
292
|
+
all: effectiveAll,
|
|
293
|
+
maxPages,
|
|
294
|
+
refresh,
|
|
295
|
+
cacheTtlMs,
|
|
296
|
+
});
|
|
297
|
+
const backup = yield* maybeAutoSyncBackupEffect(database);
|
|
298
|
+
const finished = Date.now();
|
|
299
|
+
const after = yield* trySync(() => ({
|
|
300
|
+
bookmarks: countBookmarks(database),
|
|
301
|
+
}));
|
|
302
|
+
return {
|
|
303
|
+
job: "bookmarks-sync",
|
|
304
|
+
ok: true,
|
|
305
|
+
startedAt,
|
|
306
|
+
finishedAt: new Date(finished).toISOString(),
|
|
307
|
+
durationMs: finished - started,
|
|
308
|
+
host: os.hostname(),
|
|
309
|
+
pid: process.pid,
|
|
310
|
+
options,
|
|
311
|
+
before,
|
|
312
|
+
after,
|
|
313
|
+
added: Math.max(0, after.bookmarks - before.bookmarks),
|
|
314
|
+
sync: {
|
|
315
|
+
source: sync.source,
|
|
316
|
+
count: sync.count,
|
|
317
|
+
accountId: sync.accountId,
|
|
318
|
+
},
|
|
319
|
+
backup,
|
|
320
|
+
} satisfies BookmarkSyncAuditEntry;
|
|
321
|
+
}).pipe(
|
|
322
|
+
Effect.catchAll((error) =>
|
|
323
|
+
Effect.gen(function* () {
|
|
324
|
+
const finished = Date.now();
|
|
325
|
+
const after = yield* trySync(() => ({
|
|
326
|
+
bookmarks: countBookmarks(database),
|
|
327
|
+
}));
|
|
328
|
+
return {
|
|
329
|
+
job: "bookmarks-sync",
|
|
330
|
+
ok: false,
|
|
331
|
+
startedAt,
|
|
332
|
+
finishedAt: new Date(finished).toISOString(),
|
|
333
|
+
durationMs: finished - started,
|
|
334
|
+
host: os.hostname(),
|
|
335
|
+
pid: process.pid,
|
|
336
|
+
options,
|
|
337
|
+
before,
|
|
338
|
+
after,
|
|
339
|
+
added: Math.max(0, after.bookmarks - before.bookmarks),
|
|
340
|
+
error: messageFromError(error),
|
|
341
|
+
} satisfies BookmarkSyncAuditEntry;
|
|
342
|
+
}),
|
|
343
|
+
),
|
|
344
|
+
);
|
|
345
|
+
yield* appendAuditEntryEffect(resolvedLogPath, result);
|
|
346
|
+
return result;
|
|
347
|
+
}).pipe(Effect.ensuring(releaseLock()));
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export function runBookmarkSyncJob(
|
|
352
|
+
options: BookmarkSyncJobOptions = {},
|
|
353
|
+
): Promise<BookmarkSyncAuditEntry> {
|
|
354
|
+
return runEffectPromise(runBookmarkSyncJobEffect(options));
|
|
285
355
|
}
|
|
286
356
|
|
|
287
357
|
function xmlEscape(value: string) {
|
|
@@ -409,38 +479,58 @@ export function buildBookmarkSyncLaunchAgentPlist(
|
|
|
409
479
|
};
|
|
410
480
|
}
|
|
411
481
|
|
|
412
|
-
export
|
|
482
|
+
export function installBookmarkSyncLaunchAgentEffect(
|
|
413
483
|
options: BookmarkSyncLaunchAgentOptions = {},
|
|
414
|
-
):
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
484
|
+
): Effect.Effect<BookmarkSyncLaunchAgentInstallResult, unknown> {
|
|
485
|
+
return Effect.gen(function* () {
|
|
486
|
+
yield* trySync(() => ensureBirdclawDirs());
|
|
487
|
+
const agent = yield* trySync(() =>
|
|
488
|
+
buildBookmarkSyncLaunchAgentPlist(options),
|
|
489
|
+
);
|
|
490
|
+
const launchAgentsDir = yield* trySync(() =>
|
|
491
|
+
resolvePath(options.launchAgentsDir ?? "~/Library/LaunchAgents"),
|
|
492
|
+
);
|
|
493
|
+
const plistPath = path.join(launchAgentsDir, `${agent.label}.plist`);
|
|
494
|
+
yield* tryPromise(() => fs.mkdir(launchAgentsDir, { recursive: true }));
|
|
495
|
+
yield* tryPromise(() =>
|
|
496
|
+
fs.mkdir(path.dirname(agent.logPath), { recursive: true }),
|
|
497
|
+
);
|
|
498
|
+
yield* tryPromise(() =>
|
|
499
|
+
fs.mkdir(path.dirname(agent.stdoutPath), { recursive: true }),
|
|
500
|
+
);
|
|
501
|
+
yield* tryPromise(() =>
|
|
502
|
+
fs.mkdir(path.dirname(agent.stderrPath), { recursive: true }),
|
|
503
|
+
);
|
|
504
|
+
yield* tryPromise(() => fs.writeFile(plistPath, agent.plist, "utf8"));
|
|
426
505
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
506
|
+
let loaded = false;
|
|
507
|
+
if (options.load !== false) {
|
|
508
|
+
yield* tryPromise(() =>
|
|
509
|
+
execFileAsync("launchctl", ["unload", plistPath]),
|
|
510
|
+
).pipe(Effect.catchAll(() => Effect.void));
|
|
511
|
+
yield* tryPromise(() =>
|
|
512
|
+
execFileAsync("launchctl", ["load", "-w", plistPath]),
|
|
513
|
+
);
|
|
514
|
+
loaded = true;
|
|
515
|
+
}
|
|
433
516
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
517
|
+
return {
|
|
518
|
+
ok: true,
|
|
519
|
+
label: agent.label,
|
|
520
|
+
plistPath,
|
|
521
|
+
loaded,
|
|
522
|
+
programArguments: agent.programArguments,
|
|
523
|
+
logPath: agent.logPath,
|
|
524
|
+
stdoutPath: agent.stdoutPath,
|
|
525
|
+
stderrPath: agent.stderrPath,
|
|
526
|
+
intervalSeconds: agent.intervalSeconds,
|
|
527
|
+
...(agent.envFile ? { envFile: agent.envFile } : {}),
|
|
528
|
+
};
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export function installBookmarkSyncLaunchAgent(
|
|
533
|
+
options: BookmarkSyncLaunchAgentOptions = {},
|
|
534
|
+
): Promise<BookmarkSyncLaunchAgentInstallResult> {
|
|
535
|
+
return runEffectPromise(installBookmarkSyncLaunchAgentEffect(options));
|
|
446
536
|
}
|
package/src/lib/config.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
existsSync,
|
|
5
5
|
mkdirSync,
|
|
6
6
|
readFileSync,
|
|
7
|
+
writeFileSync,
|
|
7
8
|
} from "node:fs";
|
|
8
9
|
import os from "node:os";
|
|
9
10
|
import path from "node:path";
|
|
@@ -16,7 +17,7 @@ export interface BirdclawPaths {
|
|
|
16
17
|
configPath: string;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
export type MentionsDataSource = "birdclaw" | "xurl" | "bird";
|
|
20
|
+
export type MentionsDataSource = "birdclaw" | "auto" | "xurl" | "bird";
|
|
20
21
|
export type ActionsTransport = "auto" | "bird" | "xurl";
|
|
21
22
|
|
|
22
23
|
export interface BirdclawConfig {
|
|
@@ -82,11 +83,37 @@ export function getBirdclawConfig(): BirdclawConfig {
|
|
|
82
83
|
return cachedConfig;
|
|
83
84
|
}
|
|
84
85
|
|
|
86
|
+
function getConfigPath() {
|
|
87
|
+
return process.env.BIRDCLAW_CONFIG?.trim() || getBirdclawPaths().configPath;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function writeBirdclawConfig(config: BirdclawConfig) {
|
|
91
|
+
const configPath = getConfigPath();
|
|
92
|
+
mkdirSync(path.dirname(configPath), { recursive: true });
|
|
93
|
+
writeFileSync(configPath, `${JSON.stringify(config, null, "\t")}\n`, "utf8");
|
|
94
|
+
cachedConfig = config;
|
|
95
|
+
return configPath;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function setActionsTransport(transport: ActionsTransport) {
|
|
99
|
+
const config = getBirdclawConfig();
|
|
100
|
+
const nextConfig: BirdclawConfig = {
|
|
101
|
+
...config,
|
|
102
|
+
actions: {
|
|
103
|
+
...config.actions,
|
|
104
|
+
transport,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
const configPath = writeBirdclawConfig(nextConfig);
|
|
108
|
+
return { configPath, transport };
|
|
109
|
+
}
|
|
110
|
+
|
|
85
111
|
export function resolveMentionsDataSource(
|
|
86
112
|
requestedMode?: string,
|
|
87
113
|
): MentionsDataSource {
|
|
88
114
|
if (
|
|
89
115
|
requestedMode === "birdclaw" ||
|
|
116
|
+
requestedMode === "auto" ||
|
|
90
117
|
requestedMode === "xurl" ||
|
|
91
118
|
requestedMode === "bird"
|
|
92
119
|
) {
|
|
@@ -94,13 +121,19 @@ export function resolveMentionsDataSource(
|
|
|
94
121
|
}
|
|
95
122
|
|
|
96
123
|
const envMode = process.env.BIRDCLAW_MENTIONS_DATA_SOURCE?.trim();
|
|
97
|
-
if (
|
|
124
|
+
if (
|
|
125
|
+
envMode === "birdclaw" ||
|
|
126
|
+
envMode === "auto" ||
|
|
127
|
+
envMode === "xurl" ||
|
|
128
|
+
envMode === "bird"
|
|
129
|
+
) {
|
|
98
130
|
return envMode;
|
|
99
131
|
}
|
|
100
132
|
|
|
101
133
|
const configMode = getBirdclawConfig().mentions?.dataSource;
|
|
102
134
|
if (
|
|
103
135
|
configMode === "birdclaw" ||
|
|
136
|
+
configMode === "auto" ||
|
|
104
137
|
configMode === "xurl" ||
|
|
105
138
|
configMode === "bird"
|
|
106
139
|
) {
|