@wirecat/cli-core 0.678.0 → 0.680.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 +69 -0
- package/dist/background/budget.d.ts +9 -0
- package/dist/background/budget.js +16 -0
- package/dist/calendar/cli/answers.d.ts +2 -0
- package/dist/calendar/cli/answers.js +7 -1
- package/dist/calendar/cli/index.js +3 -0
- package/dist/cli/documents/sync.d.ts +1 -1
- package/dist/cli/help/first-screen.d.ts +2 -10
- package/dist/cli/help/first-screen.js +2 -54
- package/dist/cli/setup-command.js +28 -10
- package/dist/cli/skill-refresh.js +4 -3
- package/dist/crm/index.d.ts +1 -0
- package/dist/crm/index.js +1 -0
- package/dist/documents/scope.d.ts +3 -3
- package/dist/documents/scope.js +8 -4
- package/dist/entities/business-context.js +4 -0
- package/dist/entities/recorded-meeting.d.ts +1 -0
- package/dist/entities/recorded-meeting.js +2 -0
- package/dist/mcp/app-server.js +4 -5
- package/dist/mcp/bot/server.js +4 -5
- package/dist/mcp/server.js +5 -6
- package/dist/ports/wirecat-tools.d.ts +12 -0
- package/dist/ports/wirecat-tools.js +81 -0
- package/dist/sends/upload.d.ts +4 -1
- package/dist/sends/upload.js +22 -8
- package/dist/services/communications.d.ts +35 -0
- package/dist/services/communications.js +52 -2
- package/dist/services/documents/plan.js +25 -6
- package/dist/services/documents/ports.d.ts +2 -0
- package/dist/services/documents/sync.js +3 -1
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.js +1 -0
- package/dist/services/notes-search.d.ts +8 -0
- package/dist/services/notes-search.js +29 -1
- package/dist/services/person-meetings.d.ts +2 -0
- package/dist/services/person-meetings.js +16 -1
- package/dist/skills/validate.d.ts +2 -0
- package/dist/skills/validate.js +28 -5
- package/dist/store/sqlite/agent-links.js +2 -2
- package/dist/store/sqlite/event-search.d.ts +2 -0
- package/dist/store/sqlite/event-search.js +10 -0
- package/dist/store/sqlite/note-search.d.ts +2 -0
- package/dist/store/sqlite/note-search.js +10 -0
- package/dist/store/sqlite/person-match-scan.d.ts +5 -0
- package/dist/store/sqlite/person-match-scan.js +15 -8
- package/package.json +3 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** Every WireCat tool, as "Works with" names it; a tool's own entry is left out of its screen. */
|
|
2
|
+
export const WIRECAT_TOOLS = [
|
|
3
|
+
{
|
|
4
|
+
command: "tg",
|
|
5
|
+
appName: "tg-cli",
|
|
6
|
+
envPrefix: "TG",
|
|
7
|
+
package: "@wirecat/tg-cli",
|
|
8
|
+
does: "Telegram in the same local store: search, review and tasks offline",
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
command: "max",
|
|
12
|
+
appName: "max-cli",
|
|
13
|
+
envPrefix: "MAX",
|
|
14
|
+
package: "@wirecat/max-cli",
|
|
15
|
+
does: "MAX in the same local store: search, review and tasks offline",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
command: "wa",
|
|
19
|
+
appName: "whatsapp-cli",
|
|
20
|
+
envPrefix: "WA",
|
|
21
|
+
package: "@wirecat/whatsapp-cli",
|
|
22
|
+
does: "WhatsApp in the same local store: search, review and tasks offline",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
command: "zm",
|
|
26
|
+
appName: "zoom-cli",
|
|
27
|
+
envPrefix: "ZM",
|
|
28
|
+
package: "@wirecat/zoom-cli",
|
|
29
|
+
does: "Zoom meetings: transcripts and summaries, searchable with your other WireCat data",
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
command: "drive",
|
|
33
|
+
appName: "drive-cli",
|
|
34
|
+
envPrefix: "DRIVE",
|
|
35
|
+
package: "@wirecat/drive-cli",
|
|
36
|
+
does: "Google Drive and Docs as local text, searchable with your other WireCat data",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
command: "gcal",
|
|
40
|
+
appName: "gcal-cli",
|
|
41
|
+
envPrefix: "GCAL",
|
|
42
|
+
package: "@wirecat/gcal-cli",
|
|
43
|
+
does: "Google Calendar events, searchable with your other WireCat data",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
command: "memo",
|
|
47
|
+
appName: "cli-memo",
|
|
48
|
+
envPrefix: "MEMO",
|
|
49
|
+
package: "@wirecat/cli-memo",
|
|
50
|
+
shown: "memo context <person>",
|
|
51
|
+
does: "one person across messengers, mail, notes and meetings",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
command: "mail",
|
|
55
|
+
appName: "mail-cli",
|
|
56
|
+
envPrefix: "MAIL",
|
|
57
|
+
package: "@wirecat/mail-cli",
|
|
58
|
+
does: "IMAP mail in the same local store: search your mailbox offline, next to your other WireCat data",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
command: "b24",
|
|
62
|
+
appName: "bitrix24-cli",
|
|
63
|
+
envPrefix: "B24",
|
|
64
|
+
package: "@wirecat/bitrix24-cli",
|
|
65
|
+
does: "Bitrix24 CRM: deals, leads and pipelines, searchable with your other WireCat data",
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
command: "pbx",
|
|
69
|
+
appName: "asterisk-cli",
|
|
70
|
+
envPrefix: "PBX",
|
|
71
|
+
package: "@wirecat/asterisk-cli",
|
|
72
|
+
does: "Asterisk PBX calls and recordings, searchable with your other WireCat data",
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
command: "notion",
|
|
76
|
+
appName: "notion-cli",
|
|
77
|
+
envPrefix: "WCNOTION",
|
|
78
|
+
package: "@wirecat/notion-cli",
|
|
79
|
+
does: "Notion pages and databases as local text, searchable with your other WireCat data",
|
|
80
|
+
},
|
|
81
|
+
];
|
package/dist/sends/upload.d.ts
CHANGED
|
@@ -16,7 +16,10 @@ export declare const typesText: (types: readonly string[]) => string;
|
|
|
16
16
|
* or another tool's settings. Locked with no run's folder, it writes no file.
|
|
17
17
|
*/
|
|
18
18
|
export declare const refuseLockedOutput: (path: string, app: AppIdentity, env: NodeJS.ProcessEnv, flag: string) => void;
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Protect known credential/state paths and the kernel's and devices' files, through any link, without refusing
|
|
21
|
+
* ordinary hidden developer folders.
|
|
22
|
+
*/
|
|
20
23
|
export declare const refusedPlace: (path: string, app: AppIdentity, env: NodeJS.ProcessEnv, platform?: NodeJS.Platform) => boolean;
|
|
21
24
|
export declare const readUpload: (kind: UploadKind, path: string, { app, env, anyFile, photoTypes, }: {
|
|
22
25
|
app: AppIdentity;
|
package/dist/sends/upload.js
CHANGED
|
@@ -3,6 +3,7 @@ import { open, stat } from "node:fs/promises";
|
|
|
3
3
|
import { basename, dirname, extname, isAbsolute, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { CliError, resolvePaths } from "@wirecat/cli-base";
|
|
5
5
|
import { ancestorValue, envName, readOnlyLockOf } from "../ports/app.js";
|
|
6
|
+
import { WIRECAT_TOOLS } from "../ports/wirecat-tools.js";
|
|
6
7
|
import { storePath, wirecatDirectory } from "../store/path.js";
|
|
7
8
|
/** The most `uploadBytes` holds in memory; an adapter that can stream uses `uploadBlob` and has no such cap. */
|
|
8
9
|
export const MAX_BUFFERED_UPLOAD_BYTES = 256 * 1024 * 1024;
|
|
@@ -107,17 +108,22 @@ const CREDENTIAL_RUNS = [
|
|
|
107
108
|
["AppData", "Roaming", "gcloud"],
|
|
108
109
|
["AppData", "Roaming", "GitHub CLI"],
|
|
109
110
|
];
|
|
110
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* Every WireCat app's folders hold its sessions and tokens; `max` must not send `tg`'s, nor the other way round. The
|
|
113
|
+
* tools come from `WIRECAT_TOOLS`, so a new tool is covered once it is listed there; the rest are apps no first
|
|
114
|
+
* screen names yet, the shared packages' own folders, and the name zoom-cli's folders had before.
|
|
115
|
+
*/
|
|
111
116
|
const WIRECAT_APPS = [
|
|
112
|
-
{ appName
|
|
113
|
-
{ appName: "
|
|
114
|
-
{ appName: "
|
|
115
|
-
{ appName: "cli-memo", prefix: "MEMO" },
|
|
116
|
-
{ appName: "drive-cli", prefix: "DRIVE" },
|
|
117
|
+
...WIRECAT_TOOLS.map(({ appName, envPrefix }) => ({ appName, prefix: envPrefix })),
|
|
118
|
+
{ appName: "amo-cli", prefix: "AMO" },
|
|
119
|
+
{ appName: "beeline-cli", prefix: "BEELINE" },
|
|
117
120
|
{ appName: "zm", prefix: "ZM" },
|
|
118
121
|
{ appName: "cli-messaging", prefix: "MESSAGING" },
|
|
119
122
|
{ appName: "cli-common", prefix: "CLI_COMMON" },
|
|
120
123
|
];
|
|
124
|
+
/** Kernel and device files: `/proc/self/environ` holds the process's tokens, and a device is no file to send. */
|
|
125
|
+
const SYSTEM_ROOTS = ["/proc", "/sys", "/dev"];
|
|
126
|
+
const systemPlace = (path, platform) => platform !== "win32" && SYSTEM_ROOTS.some((root) => inside(path, root));
|
|
121
127
|
/** Where `path` really is: its nearest existing ancestor's real path, as a write may create the rest under a symlink. */
|
|
122
128
|
const realPathOf = (path) => {
|
|
123
129
|
let ancestor = resolve(path);
|
|
@@ -152,7 +158,10 @@ export const refuseLockedOutput = (path, app, env, flag) => {
|
|
|
152
158
|
? `this process is read-only (${lock}) — ${flag} writes a file only inside a scheduled run's work folder`
|
|
153
159
|
: `this process is read-only (${lock}) — ${flag} writes only inside its run's work folder, ${work}`, { reason: "read-only.output-outside", param: flag });
|
|
154
160
|
};
|
|
155
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* Protect known credential/state paths and the kernel's and devices' files, through any link, without refusing
|
|
163
|
+
* ordinary hidden developer folders.
|
|
164
|
+
*/
|
|
156
165
|
export const refusedPlace = (path, app, env, platform = process.platform) => {
|
|
157
166
|
const own = [
|
|
158
167
|
...[{ appName: app.appName, prefix: app.envPrefix }, ...WIRECAT_APPS].flatMap((one) => Object.values(resolvePaths({ ...one, env, platform }))),
|
|
@@ -174,7 +183,8 @@ export const refusedPlace = (path, app, env, platform = process.platform) => {
|
|
|
174
183
|
runs.some((run) => run.every((part, offset) => names[index + offset] === part)));
|
|
175
184
|
};
|
|
176
185
|
const same = (a, b) => fold(a) === fold(b);
|
|
177
|
-
return [resolve(path), real].some((candidate) =>
|
|
186
|
+
return [resolve(path), real].some((candidate) => systemPlace(candidate, platform) ||
|
|
187
|
+
named(candidate) ||
|
|
178
188
|
own.some((dir) => inside(fold(candidate), fold(dir))) ||
|
|
179
189
|
[store, `${store}-wal`, `${store}-shm`].some((file) => same(candidate, file)));
|
|
180
190
|
};
|
|
@@ -193,6 +203,10 @@ export const readUpload = async (kind, path, { app, env = process.env, anyFile =
|
|
|
193
203
|
if (kind === "voice" && !VOICE.has(extension)) {
|
|
194
204
|
throw new CliError("validation_error", `a voice message is Ogg Opus: .ogg, .oga or .opus — send ${path} as a file`);
|
|
195
205
|
}
|
|
206
|
+
// --allow-any-file is for the owner's own credential file; no one sends the kernel's view of this process.
|
|
207
|
+
if ([resolve(path), realPathOf(path)].some((candidate) => systemPlace(candidate, process.platform))) {
|
|
208
|
+
throw new CliError("validation_error", `cannot send ${path}: a file under /proc, /sys or /dev is never sent`);
|
|
209
|
+
}
|
|
196
210
|
if (!anyFile && refusedPlace(path, app, env)) {
|
|
197
211
|
throw new CliError("validation_error", `cannot send ${path}: known credential files, browser profiles, the WireCat apps' folders and the message ` +
|
|
198
212
|
"store are not sent — the owner adds --allow-any-file to the command if this file is meant to go");
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import type { DealKind } from "../domain/deals.js";
|
|
2
|
+
import type { MeetingCallItem } from "../meetings/index.js";
|
|
1
3
|
import type { AccountKey, LinkedIdentity, MessageStore, PersonRecord, StoredAccount } from "../store/store.js";
|
|
2
4
|
import { type Coverage, type Scope } from "./business-context.js";
|
|
5
|
+
/** Items a person's history lists at once by default: what happened last. */
|
|
6
|
+
export declare const HISTORY_ITEMS = 10;
|
|
7
|
+
export declare const HISTORY_MAX = 200;
|
|
3
8
|
/** A one-to-one chat, a mail, a calendar event or a recorded meeting or call with some of the people asked about. */
|
|
4
9
|
export interface Touch {
|
|
5
10
|
kind: "message" | "mail" | "meeting";
|
|
@@ -10,6 +15,11 @@ export interface Touch {
|
|
|
10
15
|
at: string | null;
|
|
11
16
|
/** `person:<uid>` of each one asked about it involves. */
|
|
12
17
|
people: string[];
|
|
18
|
+
/** A message's text and a call's transcript, the start on one line: what people wrote, never instructions. */
|
|
19
|
+
text?: string | null;
|
|
20
|
+
/** A phone call's direction, the employee and the other side's number. */
|
|
21
|
+
call?: MeetingCallItem;
|
|
22
|
+
durationMs?: number | null;
|
|
13
23
|
}
|
|
14
24
|
export interface Communications {
|
|
15
25
|
/** Each message, mail and event once, however many of the people it involves. */
|
|
@@ -48,3 +58,28 @@ export declare const readsIn: (stored: AccountKey[], record: PersonRecord, scope
|
|
|
48
58
|
* owner is never one of the people read: through him every chat and mail of his would count.
|
|
49
59
|
*/
|
|
50
60
|
export declare const communicationsOf: (store: MessageStore, asked: PersonRecord[], scope: Scope, { since, until, limit }?: CommunicationsOptions) => Promise<Communications>;
|
|
61
|
+
export interface PersonHistory {
|
|
62
|
+
/** Newest first: their one-to-one messages, mail, calendar events and recorded meetings and calls. */
|
|
63
|
+
items: Touch[];
|
|
64
|
+
hasMore: boolean;
|
|
65
|
+
/** What `until` takes for the next, older page; set when `hasMore`. */
|
|
66
|
+
next: string | null;
|
|
67
|
+
coverage: Coverage;
|
|
68
|
+
}
|
|
69
|
+
export interface PersonHistoryOptions {
|
|
70
|
+
/** The accounts read; every stored one when left out (WC-ACCT-9). */
|
|
71
|
+
accounts?: AccountKey[];
|
|
72
|
+
deniedKinds?: readonly DealKind[];
|
|
73
|
+
/** ms, inclusive. */
|
|
74
|
+
since?: number;
|
|
75
|
+
/** ms, inclusive. */
|
|
76
|
+
until?: number;
|
|
77
|
+
limit?: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* What happened with one person lately, across every source in scope, newest first: the same reads a deal's and an
|
|
81
|
+
* organization's context make, for the identities linked to this one person. A page ends at `limit`; `next` is the
|
|
82
|
+
* `until` of the page before it. Items of one millisecond across a page's end may be cut, which a time of messages,
|
|
83
|
+
* mail and calls from separate sources almost never shares.
|
|
84
|
+
*/
|
|
85
|
+
export declare const personHistory: (store: MessageStore, reference: string, { accounts, deniedKinds, since, until, limit }?: PersonHistoryOptions) => Promise<PersonHistory>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
1
2
|
import { formatLocator } from "../domain/locator.js";
|
|
2
3
|
import { kindIn } from "../domain/providers.js";
|
|
3
|
-
import { keyOf, newestFirst } from "./business-context.js";
|
|
4
|
+
import { keyOf, newestFirst, scopeOf } from "./business-context.js";
|
|
5
|
+
import { excerpt } from "./excerpt.js";
|
|
4
6
|
import { eventsOnce } from "./person-context.js";
|
|
5
7
|
import { personMeetings } from "./person-meetings.js";
|
|
6
8
|
/** Mail read per address when counting: past it the count says `hasMore`. */
|
|
@@ -8,6 +10,11 @@ const MAIL_ROWS = 500;
|
|
|
8
10
|
const EVENT_ROWS = 1000;
|
|
9
11
|
/** Recorded meetings and calls listed: past it the count still counts each, and the read says `hasMore`. */
|
|
10
12
|
const RECORDED_ROWS = 100;
|
|
13
|
+
/** Characters of a message's text in a touch: enough to know what it was about. */
|
|
14
|
+
const TEXT = 200;
|
|
15
|
+
/** Items a person's history lists at once by default: what happened last. */
|
|
16
|
+
export const HISTORY_ITEMS = 10;
|
|
17
|
+
export const HISTORY_MAX = 200;
|
|
11
18
|
/** The stored accounts that hold a calendar: what a person's events are read from. */
|
|
12
19
|
export const calendarsOf = async (store, stored) => {
|
|
13
20
|
const held = [];
|
|
@@ -112,6 +119,7 @@ export const communicationsOf = async (store, asked, scope, { since, until, limi
|
|
|
112
119
|
ref: formatLocator({ ...key, chat: chat.id, message: message.id }),
|
|
113
120
|
title: chat.title,
|
|
114
121
|
at: message.timestamp,
|
|
122
|
+
text: message.text ? excerpt(message.text, "", TEXT) : null,
|
|
115
123
|
}, person.uid);
|
|
116
124
|
}
|
|
117
125
|
}
|
|
@@ -141,7 +149,14 @@ export const communicationsOf = async (store, asked, scope, { since, until, limi
|
|
|
141
149
|
for (const meeting of recorded.items) {
|
|
142
150
|
read.add(keyOf(meeting.account));
|
|
143
151
|
const event = meeting.event === null ? undefined : Number(meeting.event.slice("event:".length));
|
|
144
|
-
|
|
152
|
+
const recording = {
|
|
153
|
+
text: meeting.snippet,
|
|
154
|
+
durationMs: meeting.durationMs,
|
|
155
|
+
...(meeting.call ? { call: meeting.call } : {}),
|
|
156
|
+
};
|
|
157
|
+
const calendar = event === undefined ? undefined : meetings.get(event);
|
|
158
|
+
if (calendar) {
|
|
159
|
+
Object.assign(calendar, recording);
|
|
145
160
|
held++;
|
|
146
161
|
continue;
|
|
147
162
|
}
|
|
@@ -151,6 +166,7 @@ export const communicationsOf = async (store, asked, scope, { since, until, limi
|
|
|
151
166
|
title: meeting.title,
|
|
152
167
|
at: meeting.startedAt,
|
|
153
168
|
people: meeting.people,
|
|
169
|
+
...recording,
|
|
154
170
|
});
|
|
155
171
|
}
|
|
156
172
|
return {
|
|
@@ -160,3 +176,37 @@ export const communicationsOf = async (store, asked, scope, { since, until, limi
|
|
|
160
176
|
coverage: coverageOf(people, read, calendars.length > 0),
|
|
161
177
|
};
|
|
162
178
|
};
|
|
179
|
+
/**
|
|
180
|
+
* What happened with one person lately, across every source in scope, newest first: the same reads a deal's and an
|
|
181
|
+
* organization's context make, for the identities linked to this one person. A page ends at `limit`; `next` is the
|
|
182
|
+
* `until` of the page before it. Items of one millisecond across a page's end may be cut, which a time of messages,
|
|
183
|
+
* mail and calls from separate sources almost never shares.
|
|
184
|
+
*/
|
|
185
|
+
export const personHistory = async (store, reference, { accounts, deniedKinds, since, until, limit = HISTORY_ITEMS } = {}) => {
|
|
186
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > HISTORY_MAX)
|
|
187
|
+
throw new CliError("validation_error", `the history's limit takes 1–${HISTORY_MAX}`);
|
|
188
|
+
if (since !== undefined && until !== undefined && since > until)
|
|
189
|
+
throw new CliError("validation_error", "the start of the range is after its end");
|
|
190
|
+
const uid = /^person:(\d+)$/.exec(reference.trim())?.[1];
|
|
191
|
+
if (uid === undefined)
|
|
192
|
+
throw new CliError("validation_error", "a person is person:<id>");
|
|
193
|
+
const record = await store.people.personByUid(uid);
|
|
194
|
+
if (!record)
|
|
195
|
+
throw new CliError("not_found", `no person:${uid} in the store`);
|
|
196
|
+
const talks = await communicationsOf(store, [record], scopeOf(accounts, deniedKinds), {
|
|
197
|
+
...(since === undefined ? {} : { since }),
|
|
198
|
+
...(until === undefined ? {} : { until }),
|
|
199
|
+
// One past the page per chat: a dialog alone may hold the next page's first message.
|
|
200
|
+
limit: limit + 1,
|
|
201
|
+
});
|
|
202
|
+
const dated = talks.items.filter((item) => item.at !== null);
|
|
203
|
+
const items = dated.slice(0, limit);
|
|
204
|
+
const last = items.at(-1);
|
|
205
|
+
const hasMore = dated.length > limit;
|
|
206
|
+
return {
|
|
207
|
+
items,
|
|
208
|
+
hasMore,
|
|
209
|
+
next: hasMore && last?.at ? new Date(Date.parse(last.at) - 1).toISOString() : null,
|
|
210
|
+
coverage: talks.coverage,
|
|
211
|
+
};
|
|
212
|
+
};
|
|
@@ -17,6 +17,20 @@ const SAVE_EVERY_MS = 2000;
|
|
|
17
17
|
const changesScope = (scope, cursor) => `${scope}:changes:${cursor}`;
|
|
18
18
|
export const planDocuments = async (options, source, state, roots, limit, pictures, walks) => {
|
|
19
19
|
const { isFolder, skipReason, retryable, maxEntries, errorOf, query, budget } = options;
|
|
20
|
+
const answers = new Map();
|
|
21
|
+
// Asked once per node, as every file below a folder asks about it again on its way up.
|
|
22
|
+
const cut = query?.mode === "exclude"
|
|
23
|
+
? (file) => {
|
|
24
|
+
const known = answers.get(file.id);
|
|
25
|
+
if (known !== undefined)
|
|
26
|
+
return known;
|
|
27
|
+
const found = query.matches(file);
|
|
28
|
+
answers.set(file.id, found);
|
|
29
|
+
return found;
|
|
30
|
+
}
|
|
31
|
+
: undefined;
|
|
32
|
+
const scoped = cut && query ? { ...query, matches: cut } : query;
|
|
33
|
+
const excluded = (folder) => !roots.includes(folder.id) && cut?.(folder) === true;
|
|
20
34
|
const scope = scopeHash(roots, query, options.isDocument !== undefined);
|
|
21
35
|
if (!roots.length && query?.mode !== "include")
|
|
22
36
|
return {
|
|
@@ -116,7 +130,7 @@ export const planDocuments = async (options, source, state, roots, limit, pictur
|
|
|
116
130
|
}
|
|
117
131
|
}
|
|
118
132
|
const stack = entering
|
|
119
|
-
.filter((folder) => within(folder, roots, folders))
|
|
133
|
+
.filter((folder) => !excluded(folder) && within(folder, roots, folders, new Set(), cut))
|
|
120
134
|
.reverse()
|
|
121
135
|
.map((folder) => ({ id: folder.id, ancestry: [], folder }));
|
|
122
136
|
if (stack.length)
|
|
@@ -171,11 +185,14 @@ export const planDocuments = async (options, source, state, roots, limit, pictur
|
|
|
171
185
|
}
|
|
172
186
|
// One listing at least per call, so a folder with more children than the bound still moves on.
|
|
173
187
|
// The run's own signal too: a cooperative sync is not cut from outside, and a CLI may pass no budget.
|
|
174
|
-
|
|
188
|
+
// The time budget keeps a margin of 5 s or more, so a short run would never list a folder: its first request
|
|
189
|
+
// goes ahead while one still fits before the deadline itself.
|
|
190
|
+
const taken = options.signal?.aborted
|
|
175
191
|
? "cancelled"
|
|
176
192
|
: listed > 0 && spent >= maxEntries
|
|
177
193
|
? "entries"
|
|
178
|
-
:
|
|
194
|
+
: budget?.take();
|
|
195
|
+
stopped = taken === "deadline" && budget?.first?.() ? null : (taken ?? null);
|
|
179
196
|
if (stopped)
|
|
180
197
|
break;
|
|
181
198
|
const folder = step.folder ?? (await source.metadata(step.id));
|
|
@@ -223,6 +240,8 @@ export const planDocuments = async (options, source, state, roots, limit, pictur
|
|
|
223
240
|
for (const file of children)
|
|
224
241
|
if (isFolder(file)) {
|
|
225
242
|
container(file);
|
|
243
|
+
if (excluded(file))
|
|
244
|
+
continue;
|
|
226
245
|
if (walked(file.id))
|
|
227
246
|
folders[file.id] = file;
|
|
228
247
|
else
|
|
@@ -278,7 +297,7 @@ export const planDocuments = async (options, source, state, roots, limit, pictur
|
|
|
278
297
|
if (folders[root]?.trashed)
|
|
279
298
|
skipped.push({ id: root, reason: "selected folder is unavailable" });
|
|
280
299
|
for (const [id, file] of files) {
|
|
281
|
-
if (!inScope(file, roots, folders, matched,
|
|
300
|
+
if (!inScope(file, roots, folders, matched, scoped))
|
|
282
301
|
continue;
|
|
283
302
|
const previousSkip = state.skipped.find((item) => item.id === id);
|
|
284
303
|
const reason = skipReason(file);
|
|
@@ -302,11 +321,11 @@ export const planDocuments = async (options, source, state, roots, limit, pictur
|
|
|
302
321
|
}
|
|
303
322
|
for (const id of Object.keys(state.documents)) {
|
|
304
323
|
const file = files.get(id);
|
|
305
|
-
if (!file || !inScope(file, roots, folders, matched,
|
|
324
|
+
if (!file || !inScope(file, roots, folders, matched, scoped))
|
|
306
325
|
jobs.push({ id, kind: "remove" });
|
|
307
326
|
}
|
|
308
327
|
// Only retain metadata for selected ancestry; the account-wide feed includes unrelated folders.
|
|
309
|
-
const scopedFolders = Object.fromEntries(Object.entries(folders).filter(([, file]) => within(file, roots, folders
|
|
328
|
+
const scopedFolders = Object.fromEntries(Object.entries(folders).filter(([, file]) => roots.includes(file.id) || (!excluded(file) && within(file, roots, folders, new Set(), cut))));
|
|
310
329
|
return {
|
|
311
330
|
pending: {
|
|
312
331
|
scope,
|
|
@@ -21,6 +21,8 @@ export interface SyncOptions<M extends SourceFile> {
|
|
|
21
21
|
/** Asked before each folder listing and each file read: a stop ends the call with its work saved. */
|
|
22
22
|
budget?: {
|
|
23
23
|
take(): "requests" | "deadline" | "cancelled" | null;
|
|
24
|
+
/** The call's first request, when `take()` said "deadline" and nothing has gone yet (`RunBudget.first`). */
|
|
25
|
+
first?(): boolean;
|
|
24
26
|
readonly stopped?: string | null;
|
|
25
27
|
};
|
|
26
28
|
/** The run's hard limit: the word index at the end of a sync stops before it, less its margin. */
|
|
@@ -166,7 +166,9 @@ export const syncDocuments = async (options) => {
|
|
|
166
166
|
else {
|
|
167
167
|
if (!source)
|
|
168
168
|
throw new CliError("configuration_error", "a pending save requires source sign-in");
|
|
169
|
-
const
|
|
169
|
+
const taken = options.budget?.take();
|
|
170
|
+
// A call that has listed nothing reads one page, or a short run never saves one.
|
|
171
|
+
const stop = taken === "deadline" && options.budget?.first?.() ? null : taken;
|
|
170
172
|
if (stop) {
|
|
171
173
|
result.stopped = stop;
|
|
172
174
|
break;
|
package/dist/services/index.d.ts
CHANGED
|
@@ -71,7 +71,8 @@ export { CATEGORIES, organizationCategories, SECTION_LIMIT } from "./business-co
|
|
|
71
71
|
export { type CallStatsAnswer, type CallStatsRequest, readCallStats } from "./call-stats.js";
|
|
72
72
|
export type { ChatsService, MarkedRead, PageWindow } from "./chats.js";
|
|
73
73
|
export { chatsService, EVENTS_DAYS } from "./chats.js";
|
|
74
|
-
export type { Communications, Touch } from "./communications.js";
|
|
74
|
+
export type { Communications, PersonHistory, PersonHistoryOptions, Touch } from "./communications.js";
|
|
75
|
+
export { HISTORY_ITEMS, HISTORY_MAX, personHistory } from "./communications.js";
|
|
75
76
|
export type { BatchStatus, Built, ConversationsService, MessageLinks } from "./conversations.js";
|
|
76
77
|
export { BATCH_SIZE, conversationsService } from "./conversations.js";
|
|
77
78
|
export type { DealBrief, DealContext, DealContextOptions, DealTouch } from "./deal-context.js";
|
package/dist/services/index.js
CHANGED
|
@@ -55,6 +55,7 @@ export { attachmentsService } from "./attachments.js";
|
|
|
55
55
|
export { CATEGORIES, organizationCategories, SECTION_LIMIT } from "./business-context.js";
|
|
56
56
|
export { readCallStats } from "./call-stats.js";
|
|
57
57
|
export { chatsService, EVENTS_DAYS } from "./chats.js";
|
|
58
|
+
export { HISTORY_ITEMS, HISTORY_MAX, personHistory } from "./communications.js";
|
|
58
59
|
export { BATCH_SIZE, conversationsService } from "./conversations.js";
|
|
59
60
|
export { dealBrief, dealContext } from "./deal-context.js";
|
|
60
61
|
export { accountStore, crossAccount, OFFLINE, onlineDeps, storedDeps, storeOnlyDeps } from "./deps.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type KeyringStore } from "@wirecat/cli-base";
|
|
2
2
|
import { type QueryNode } from "@wirecat/cli-base/query";
|
|
3
|
+
import { type Deadline } from "../background/budget.js";
|
|
3
4
|
import { type Embedder, type WarmEmbedders } from "../embeddings/embed.js";
|
|
4
5
|
import { type TextModel } from "../embeddings/models.js";
|
|
5
6
|
import type { PictureEmbedder } from "../images/picture/embedder.js";
|
|
@@ -54,12 +55,19 @@ export interface NotesEmbedOptions {
|
|
|
54
55
|
keyring?: KeyringStore;
|
|
55
56
|
/** Tests give a fake model here; nothing in the suite reaches a provider. */
|
|
56
57
|
enrichWith?: Pick<EnrichOptions, "adapters" | "fetch" | "key">;
|
|
58
|
+
/** The run's hard limit: the run stops between batches before it, less its margin, as a sync's last step does. */
|
|
59
|
+
deadline?: Deadline;
|
|
60
|
+
signal?: AbortSignal;
|
|
57
61
|
}
|
|
58
62
|
export interface NotesEmbedded {
|
|
59
63
|
model: string;
|
|
60
64
|
embedded: number;
|
|
61
65
|
/** Chunks still without a vector, when `maxChunks` stopped the run, or records still to enrich. */
|
|
62
66
|
left: boolean;
|
|
67
|
+
/** The run stopped early to end in time, or was cancelled; the next run goes on. */
|
|
68
|
+
stopped?: "deadline" | "cancelled";
|
|
69
|
+
/** After a stop: the chunks still without a vector, when the store can count them. */
|
|
70
|
+
remaining?: number;
|
|
63
71
|
/** What the owner's enrichment did first; absent when it is off. */
|
|
64
72
|
/** The run, or `failed` with no counts when enrichment threw before it could count. */
|
|
65
73
|
enrichment?: Exclude<EnrichRun, {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { dateRange, parseLucene, timezoneOf } from "@wirecat/cli-base/query";
|
|
3
|
+
import { deadlineMargin } from "../background/budget.js";
|
|
3
4
|
import { INTERNAL_NOTES, isImportedProvider } from "../domain/providers.js";
|
|
4
5
|
import { normalizeTag } from "../domain/tags.js";
|
|
5
6
|
import { defaultThreads, isTextModelInstalled, openEmbedder, textModelsDirectory, } from "../embeddings/embed.js";
|
|
@@ -101,14 +102,31 @@ export const withLocal = async (model, directory, threads, work, shared) => {
|
|
|
101
102
|
* as conversations, so a chunk whose text a conversation shares is embedded once. A missing model is
|
|
102
103
|
* an error naming the download command; nothing is downloaded.
|
|
103
104
|
*/
|
|
104
|
-
|
|
105
|
+
/** When a run with this deadline stops: its margin before the end, as the word index after a sync does. */
|
|
106
|
+
const stopsAt = (deadline) => deadline ? deadline.endsAt - deadlineMargin(deadline) : Number.POSITIVE_INFINITY;
|
|
107
|
+
const embedChunks = async (store, source, { model: choice, maxChunks = Number.POSITIVE_INFINITY, env, threads, command, deadline, signal, } = {}) => {
|
|
105
108
|
const { model, directory, key } = localModel(choice, env, command);
|
|
106
109
|
if ((await source.chunksToEmbed(key, { limit: 1 })).length === 0)
|
|
107
110
|
return { model: model.id, embedded: 0, left: false };
|
|
111
|
+
const until = stopsAt(deadline);
|
|
112
|
+
const stopped = (slowest) => signal?.aborted ? "cancelled" : Date.now() + slowest >= until ? "deadline" : undefined;
|
|
113
|
+
const stop = async (embedded, why) => {
|
|
114
|
+
const remaining = await source.chunksLeft?.(key);
|
|
115
|
+
return { model: model.id, embedded, left: true, stopped: why, ...(remaining === undefined ? {} : { remaining }) };
|
|
116
|
+
};
|
|
117
|
+
// Loading the model alone takes seconds.
|
|
118
|
+
const early = stopped(0);
|
|
119
|
+
if (early)
|
|
120
|
+
return stop(0, early);
|
|
108
121
|
return withLocal(model, directory, threads, async (embedder) => {
|
|
109
122
|
let embedded = 0;
|
|
110
123
|
let after;
|
|
124
|
+
let slowest = 0;
|
|
111
125
|
while (embedded < maxChunks) {
|
|
126
|
+
const why = stopped(slowest);
|
|
127
|
+
if (why)
|
|
128
|
+
return stop(embedded, why);
|
|
129
|
+
const started = Date.now();
|
|
112
130
|
const batch = await source.chunksToEmbed(key, {
|
|
113
131
|
limit: Math.min(NOTE_BATCH, maxChunks - embedded),
|
|
114
132
|
...(after === undefined ? {} : { after }),
|
|
@@ -119,6 +137,7 @@ const embedChunks = async (store, source, { model: choice, maxChunks = Number.PO
|
|
|
119
137
|
const vectors = await embedder.embed(batch.map(({ text }) => text), "passage");
|
|
120
138
|
await store.vectors.saveVectors(key, model.dims, batch.map(({ hash }, index) => ({ hash, vector: vectors[index] })));
|
|
121
139
|
embedded += batch.length;
|
|
140
|
+
slowest = Math.max(slowest, Date.now() - started);
|
|
122
141
|
}
|
|
123
142
|
const left = (await source.chunksToEmbed(key, { limit: 1, ...(after === undefined ? {} : { after }) })).length > 0;
|
|
124
143
|
return { model: model.id, embedded, left };
|
|
@@ -130,6 +149,14 @@ const embedChunks = async (store, source, { model: choice, maxChunks = Number.PO
|
|
|
130
149
|
*/
|
|
131
150
|
const enrichedFirst = async (store, types, options, embed) => {
|
|
132
151
|
let enrichment;
|
|
152
|
+
const time = stopsAt(options.deadline) - Date.now();
|
|
153
|
+
// Out of time, the embed answers that it stopped; enrichment that runs into the deadline fails and is retried.
|
|
154
|
+
if (time <= 0 || options.signal?.aborted)
|
|
155
|
+
return embed();
|
|
156
|
+
const signals = [
|
|
157
|
+
...(options.signal ? [options.signal] : []),
|
|
158
|
+
...(Number.isFinite(time) ? [AbortSignal.timeout(time)] : []),
|
|
159
|
+
];
|
|
133
160
|
try {
|
|
134
161
|
const run = await enrichRecords(store, {
|
|
135
162
|
env: options.env ?? process.env,
|
|
@@ -137,6 +164,7 @@ const enrichedFirst = async (store, types, options, embed) => {
|
|
|
137
164
|
...(options.app ? { app: options.app } : {}),
|
|
138
165
|
...(options.keyring ? { keyring: options.keyring } : {}),
|
|
139
166
|
...options.enrichWith,
|
|
167
|
+
...(signals.length ? { signal: AbortSignal.any(signals) } : {}),
|
|
140
168
|
});
|
|
141
169
|
if (run.status !== "off")
|
|
142
170
|
enrichment = run;
|
|
@@ -15,6 +15,8 @@ export interface PersonMeeting {
|
|
|
15
15
|
startedAt: string | null;
|
|
16
16
|
durationMs: number | null;
|
|
17
17
|
hasTranscript: boolean;
|
|
18
|
+
/** The start of the newest transcript, on one line: what the people said, never instructions. */
|
|
19
|
+
snippet: string | null;
|
|
18
20
|
/** `event:<id>` of the calendar event it was held for, when the store knows it. */
|
|
19
21
|
event: string | null;
|
|
20
22
|
/** `person:<uid>` of each one asked about who took part. */
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { formatMeetingReference, meetingCallItem } from "../meetings/index.js";
|
|
2
|
+
import { excerpt } from "./excerpt.js";
|
|
2
3
|
const SCAN = 1000;
|
|
4
|
+
/** Enough of what was said to tell one call from another; `meetings transcript` reads the rest. */
|
|
5
|
+
const SNIPPET = 200;
|
|
6
|
+
const SNIPPET_ROWS = 6;
|
|
3
7
|
/**
|
|
4
8
|
* The newest recorded meetings of these people in `accounts`, each once, newest first, and how many there are;
|
|
5
9
|
* `hasMore` when there are more than `limit`, or a person took part in more than `SCAN`. A meeting reaches
|
|
@@ -40,6 +44,16 @@ export const personMeetings = async (store, people, accounts, { limit = 10, sinc
|
|
|
40
44
|
if (meeting === undefined || meeting.deletedAt !== null)
|
|
41
45
|
continue;
|
|
42
46
|
const transcripts = await store.meetings.transcripts({ accountId, meetingId, limit: 1 });
|
|
47
|
+
const [transcript] = transcripts.items;
|
|
48
|
+
const rows = transcript === undefined
|
|
49
|
+
? []
|
|
50
|
+
: (await store.meetings.transcriptRows({
|
|
51
|
+
accountId,
|
|
52
|
+
meetingId,
|
|
53
|
+
transcriptId: transcript.id,
|
|
54
|
+
limit: SNIPPET_ROWS,
|
|
55
|
+
})).rows;
|
|
56
|
+
const said = rows.map(({ text }) => text).join(" ");
|
|
43
57
|
const account = byId.get(accountId);
|
|
44
58
|
const call = meetingCallItem(meeting);
|
|
45
59
|
items.push({
|
|
@@ -49,7 +63,8 @@ export const personMeetings = async (store, people, accounts, { limit = 10, sinc
|
|
|
49
63
|
title: meeting.title,
|
|
50
64
|
startedAt: meeting.startedAt === null ? null : new Date(meeting.startedAt).toISOString(),
|
|
51
65
|
durationMs: meeting.durationMs,
|
|
52
|
-
hasTranscript:
|
|
66
|
+
hasTranscript: transcript !== undefined,
|
|
67
|
+
snippet: said.trim() ? excerpt(said, "", SNIPPET) : null,
|
|
53
68
|
event: meeting.eventId === null ? null : `event:${meeting.eventId}`,
|
|
54
69
|
people: who,
|
|
55
70
|
...(call ? { call } : {}),
|
|
@@ -4,5 +4,7 @@ export interface SkillValidation {
|
|
|
4
4
|
file?: string;
|
|
5
5
|
version?: string;
|
|
6
6
|
program?: Command;
|
|
7
|
+
/** The most SKILL.md may weigh, in bytes: an agent carries it in every later turn, the linked files only when read. */
|
|
8
|
+
maxBytes?: number;
|
|
7
9
|
}
|
|
8
10
|
export declare const validateSkill: (content: string, options?: SkillValidation) => string[];
|
package/dist/skills/validate.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import { dirname, resolve } from "node:path";
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, resolve } from "node:path";
|
|
3
3
|
import { parseDocument } from "yaml";
|
|
4
4
|
// The Agent Skills specification asks for string values; OpenClaw and ClawHub read their install and requirement
|
|
5
5
|
// declarations only from an object at `metadata.openclaw`, so that one key is a mapping.
|
|
@@ -44,14 +44,37 @@ export const validateSkill = (content, options = {}) => {
|
|
|
44
44
|
problems.push("skill metadata must contain string values, and metadata.openclaw a mapping");
|
|
45
45
|
if (options.version && fields.metadata?.version !== options.version)
|
|
46
46
|
problems.push("emitted skill version must match the binary");
|
|
47
|
-
|
|
47
|
+
if (options.maxBytes !== undefined) {
|
|
48
|
+
const bytes = Buffer.byteLength(content);
|
|
49
|
+
if (bytes > options.maxBytes)
|
|
50
|
+
problems.push(`SKILL.md is ${bytes} bytes, over ${options.maxBytes}: move what only some tasks need into linked files`);
|
|
51
|
+
}
|
|
52
|
+
const seen = new Set(options.file ? [options.file] : []);
|
|
53
|
+
for (const problem of bodyProblems(content.slice(match[0].length), options, seen))
|
|
54
|
+
problems.push(problem);
|
|
55
|
+
return [...new Set(problems)];
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Relative links that lead nowhere and command paths the program does not have, in a skill's body and, through its
|
|
59
|
+
* relative Markdown links, in every file beside it that it links: those are loaded in its place.
|
|
60
|
+
*/
|
|
61
|
+
const bodyProblems = (body, options, seen) => {
|
|
62
|
+
const problems = [];
|
|
48
63
|
if (options.file) {
|
|
49
64
|
for (const link of body.matchAll(/\[[^\]]*\]\(([^\s)]+)\)/g)) {
|
|
50
65
|
const target = (link[1] ?? "").split("#")[0] ?? "";
|
|
51
66
|
if (!target || /^(?:[a-z]+:|\/)/i.test(target))
|
|
52
67
|
continue;
|
|
53
|
-
|
|
68
|
+
const path = resolve(dirname(options.file), target);
|
|
69
|
+
if (!existsSync(path)) {
|
|
54
70
|
problems.push(`missing skill reference: ${target}`);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (!path.endsWith(".md") || seen.has(path))
|
|
74
|
+
continue;
|
|
75
|
+
seen.add(path);
|
|
76
|
+
for (const problem of bodyProblems(readFileSync(path, "utf8"), { ...options, file: path }, seen))
|
|
77
|
+
problems.push(`${basename(path)}: ${problem}`);
|
|
55
78
|
}
|
|
56
79
|
}
|
|
57
80
|
if (options.program) {
|
|
@@ -82,5 +105,5 @@ export const validateSkill = (content, options = {}) => {
|
|
|
82
105
|
}
|
|
83
106
|
}
|
|
84
107
|
}
|
|
85
|
-
return
|
|
108
|
+
return problems;
|
|
86
109
|
};
|