@wirecat/cli-core 0.348.0 → 0.349.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 +28 -0
- package/dist/cli/messenger/observed.js +6 -3
- package/dist/context/evidence.d.ts +10 -0
- package/dist/services/context-evidence.d.ts +1 -1
- package/dist/services/index.d.ts +5 -3
- package/dist/services/index.js +1 -0
- package/dist/services/project-gathering-around.d.ts +37 -0
- package/dist/services/project-gathering-around.js +57 -0
- package/dist/services/project-gathering-request.d.ts +13 -1
- package/dist/services/project-gathering-request.js +23 -5
- package/dist/services/project-gathering.d.ts +15 -1
- package/dist/services/project-gathering.js +32 -1
- package/dist/store/sqlite/context-evidence.d.ts +4 -1
- package/dist/store/sqlite/context-evidence.js +12 -0
- package/dist/store/store.d.ts +2 -1
- package/dist/store/store.js +5 -1
- package/package.json +1 -1
- package/parity.json +2 -12
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,34 @@ shape of this file.
|
|
|
7
7
|
|
|
8
8
|
## Unreleased
|
|
9
9
|
|
|
10
|
+
## 0.349.0 — 19.10.2026
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`gatherProjectEvidence` brings the mail and document index up to date before reading** through the new
|
|
15
|
+
optional `MessageStore.contextIndex` port (`ContextIndex.catchUp`), the same fills a mail search and the notes
|
|
16
|
+
search run. `index: "as-is"` skips it; the result's `index` says what happened. On a store just synced, new
|
|
17
|
+
mail and imported documents were missed before.
|
|
18
|
+
- **The project key is a search lane of its own** (`project.key`, lane kind `key`), and an explicit window may
|
|
19
|
+
give `after` alone: `before` is `asOf`, frozen with the run.
|
|
20
|
+
- **Each message hit of `gatherProjectEvidence` carries the messages next to it** (`around`, default 2 before and 2
|
|
21
|
+
after, at most 5) through the new `neighbours` port; `storedMessageNeighbours(store.messages)` builds it. They
|
|
22
|
+
are cited context, not matches, and their bytes count against `maxReadBytes`. A reply that names nothing was
|
|
23
|
+
out of reach of every search.
|
|
24
|
+
- **The default read budget covers one full round**: one read per search × source × 90-day chunk when that is more
|
|
25
|
+
than 48 (at most 512), so `--source all` with several searches no longer stops before every search ran once.
|
|
26
|
+
- **`ProjectFetchState`, `ProjectUnitState`, `ProjectIndexCatchUp` and `ContextIndex` are exported** from
|
|
27
|
+
`@wirecat/cli-core/services`, so a host can name the result type.
|
|
28
|
+
|
|
29
|
+
### Changed — may break callers
|
|
30
|
+
|
|
31
|
+
- **`feed` and a one-shot command's passive listen keep one operation name in their run records and warnings**:
|
|
32
|
+
`history.feed` for `feed`, `messages.listen` for `listen` and `history.listen` for `listenHistory`, as
|
|
33
|
+
`messages.watch` does for `watch`. Before, the run record said `adapter.feed`, `adapter.listen` or
|
|
34
|
+
`adapter.listenHistory`, so `runs --operation adapter.feed` and `adapter.listen` stop matching new runs.
|
|
35
|
+
- **`parity.json` expects `--qr-file` on `session start` and `setup` in all three CLIs**: max has it since
|
|
36
|
+
max-cli#736, so the rows are `all` instead of planned for max.
|
|
37
|
+
|
|
10
38
|
## 0.348.0 — 19.10.2026
|
|
11
39
|
|
|
12
40
|
### Added
|
|
@@ -40,7 +40,7 @@ export const observed = (messenger, events) => {
|
|
|
40
40
|
}), () => ({ counts }));
|
|
41
41
|
};
|
|
42
42
|
const mint = messenger.newSendId;
|
|
43
|
-
const { chats, history, contact, around, watch, listen, listenHistory } = messenger;
|
|
43
|
+
const { chats, history, contact, around, watch, feed, listen, listenHistory } = messenger;
|
|
44
44
|
// A method not listed here is timed under its own name, with no ids until a line here names them.
|
|
45
45
|
return throughWrapper(messenger, {
|
|
46
46
|
self: () => messenger.self(),
|
|
@@ -87,14 +87,17 @@ export const observed = (messenger, events) => {
|
|
|
87
87
|
watch: (onEvent, signal, onReady) => counted("messages.watch", onEvent, (counting) => watch.call(messenger, counting, signal, onReady), byEvent),
|
|
88
88
|
}
|
|
89
89
|
: {}),
|
|
90
|
+
...(feed
|
|
91
|
+
? { feed: (onBatch, signal) => timed("history.feed", {}, () => feed.call(messenger, onBatch, signal)) }
|
|
92
|
+
: {}),
|
|
90
93
|
...(listen
|
|
91
94
|
? {
|
|
92
|
-
listen: (onEvent, signal) => counted("
|
|
95
|
+
listen: (onEvent, signal) => counted("messages.listen", onEvent, (counting) => listen.call(messenger, counting, signal), byEvent),
|
|
93
96
|
}
|
|
94
97
|
: {}),
|
|
95
98
|
...(listenHistory
|
|
96
99
|
? {
|
|
97
|
-
listenHistory: (onBatch, signal) => counted("
|
|
100
|
+
listenHistory: (onBatch, signal) => counted("history.listen", onBatch, (counting) => listenHistory.call(messenger, counting, signal), byPart),
|
|
98
101
|
}
|
|
99
102
|
: {}),
|
|
100
103
|
logout: () => timed("session.logout", {}, () => messenger.logout()),
|
|
@@ -53,6 +53,16 @@ export interface ContextEvidencePage {
|
|
|
53
53
|
export interface ContextEvidenceReader {
|
|
54
54
|
read(request: ContextEvidenceRequest): Promise<ContextEvidencePage>;
|
|
55
55
|
}
|
|
56
|
+
/** Brings the word index of stored mail and imported documents up to date, so the reads that follow find new text. */
|
|
57
|
+
export interface ContextIndex {
|
|
58
|
+
catchUp(request: {
|
|
59
|
+
kinds: readonly ContextSource["kind"][];
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
}): Promise<{
|
|
62
|
+
mail: number;
|
|
63
|
+
documents: number;
|
|
64
|
+
}>;
|
|
65
|
+
}
|
|
56
66
|
export declare const contextCursorScope: (request: Pick<ContextEvidenceRequest, "source" | "query" | "after" | "before">) => string;
|
|
57
67
|
export declare const contextSource: (value: ContextSource) => ContextSource;
|
|
58
68
|
export declare const contextEvidenceRequest: (input: ContextEvidenceRequest) => {
|
|
@@ -5,5 +5,5 @@ export interface ScopedContextEvidenceReader extends ContextEvidenceReader {
|
|
|
5
5
|
usage(): ContextReadUsage;
|
|
6
6
|
}
|
|
7
7
|
export declare const createContextEvidenceReader: (port: ContextEvidenceReader, allowed: readonly ContextSource[], limits?: ContextReadLimits) => ScopedContextEvidenceReader;
|
|
8
|
-
export type { ContextEvidenceItem, ContextEvidencePage, ContextEvidenceReader, ContextEvidenceRequest, ContextSource, } from "../context/evidence.js";
|
|
8
|
+
export type { ContextEvidenceItem, ContextEvidencePage, ContextEvidenceReader, ContextEvidenceRequest, ContextIndex, ContextSource, } from "../context/evidence.js";
|
|
9
9
|
export type { ContextReadLimits, ContextReadUsage } from "../context/read-budget.js";
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type BotCheckService } from "../botcheck/service.js";
|
|
2
|
-
export type { ContextEvidenceItem, ContextEvidencePage, ContextEvidenceReader, ContextEvidenceRequest, ContextReadLimits, ContextReadUsage, ContextSource, ScopedContextEvidenceReader, } from "./context-evidence.js";
|
|
2
|
+
export type { ContextEvidenceItem, ContextEvidencePage, ContextEvidenceReader, ContextEvidenceRequest, ContextIndex, ContextReadLimits, ContextReadUsage, ContextSource, ScopedContextEvidenceReader, } from "./context-evidence.js";
|
|
3
3
|
export { createContextEvidenceReader } from "./context-evidence.js";
|
|
4
4
|
export { type DownloadedModel, downloadImageModel, downloadTextModel, type ModelDownloadOptions, } from "./model-downloads.js";
|
|
5
|
-
export type { ProjectEvidenceItem, ProjectGathering, ProjectGatheringPorts, ProjectGatheringStop, ProjectSourceFetcher, } from "./project-gathering.js";
|
|
5
|
+
export type { ProjectEvidenceItem, ProjectGathering, ProjectGatheringPorts, ProjectGatheringStop, ProjectIndexCatchUp, ProjectSourceFetcher, } from "./project-gathering.js";
|
|
6
6
|
export { gatherProjectEvidence } from "./project-gathering.js";
|
|
7
|
-
export type {
|
|
7
|
+
export type { ProjectNeighbour, ProjectNeighbourReader } from "./project-gathering-around.js";
|
|
8
|
+
export { storedMessageNeighbours } from "./project-gathering-around.js";
|
|
9
|
+
export type { ProjectFetchState, ProjectGatheringBudgets, ProjectGatheringRequest, ProjectLane, ProjectLaneKind, ProjectUnitState, } from "./project-gathering-request.js";
|
|
8
10
|
import { type AccountService } from "./account.js";
|
|
9
11
|
import { type AdminService } from "./admin.js";
|
|
10
12
|
import { type AdminStatisticsService } from "./admin-statistics.js";
|
package/dist/services/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { botCheckService } from "../botcheck/service.js";
|
|
|
2
2
|
export { createContextEvidenceReader } from "./context-evidence.js";
|
|
3
3
|
export { downloadImageModel, downloadTextModel, } from "./model-downloads.js";
|
|
4
4
|
export { gatherProjectEvidence } from "./project-gathering.js";
|
|
5
|
+
export { storedMessageNeighbours } from "./project-gathering-around.js";
|
|
5
6
|
import { accountService } from "./account.js";
|
|
6
7
|
import { adminService } from "./admin.js";
|
|
7
8
|
import { adminStatisticsService } from "./admin-statistics.js";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { MessagesStore } from "../store/messages.js";
|
|
2
|
+
export interface ProjectNeighbour {
|
|
3
|
+
ref: string;
|
|
4
|
+
at: number;
|
|
5
|
+
sender: string | null;
|
|
6
|
+
text: string;
|
|
7
|
+
found: boolean;
|
|
8
|
+
}
|
|
9
|
+
/** The stored messages next to a hit in its chat, oldest first, without the hit itself. */
|
|
10
|
+
export interface ProjectNeighbourReader {
|
|
11
|
+
around(ref: string, window: {
|
|
12
|
+
before: number;
|
|
13
|
+
after: number;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
ref: string;
|
|
16
|
+
at: number;
|
|
17
|
+
sender: string | null;
|
|
18
|
+
text: string;
|
|
19
|
+
}[]>;
|
|
20
|
+
}
|
|
21
|
+
export declare const storedMessageNeighbours: (messages: Pick<MessagesStore, "around">) => ProjectNeighbourReader;
|
|
22
|
+
/**
|
|
23
|
+
* Neighbours are context for reading a hit, not matches: they never join `items`, and their text counts against
|
|
24
|
+
* the run's read bytes.
|
|
25
|
+
*/
|
|
26
|
+
export declare const attachNeighbours: (items: {
|
|
27
|
+
ref: string;
|
|
28
|
+
kind: string;
|
|
29
|
+
around?: ProjectNeighbour[] | null;
|
|
30
|
+
aroundIssue?: string | null;
|
|
31
|
+
}[], reader: ProjectNeighbourReader | undefined, window: {
|
|
32
|
+
before: number;
|
|
33
|
+
after: number;
|
|
34
|
+
}, budget: {
|
|
35
|
+
remaining: () => number;
|
|
36
|
+
charge: (bytes: number) => void;
|
|
37
|
+
}, known: (ref: string) => boolean, signal?: AbortSignal) => Promise<void>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { formatLocator, parseLocator } from "../domain/locator.js";
|
|
3
|
+
import { excerpt } from "./excerpt.js";
|
|
4
|
+
export const storedMessageNeighbours = (messages) => ({
|
|
5
|
+
async around(ref, window) {
|
|
6
|
+
const at = parseLocator(ref);
|
|
7
|
+
const rows = await messages.around({ provider: at.provider, account: at.account }, at.chat, at.message, window);
|
|
8
|
+
return rows
|
|
9
|
+
.filter((row) => !row.anchor)
|
|
10
|
+
.map((row) => ({
|
|
11
|
+
ref: formatLocator({ ...at, message: row.id }),
|
|
12
|
+
at: Date.parse(row.timestamp),
|
|
13
|
+
sender: row.senderName,
|
|
14
|
+
text: row.text ?? "",
|
|
15
|
+
}));
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Neighbours are context for reading a hit, not matches: they never join `items`, and their text counts against
|
|
20
|
+
* the run's read bytes.
|
|
21
|
+
*/
|
|
22
|
+
export const attachNeighbours = async (items, reader, window, budget, known, signal) => {
|
|
23
|
+
if (!reader || window.before + window.after === 0)
|
|
24
|
+
return;
|
|
25
|
+
for (const item of items) {
|
|
26
|
+
if (item.kind !== "message")
|
|
27
|
+
continue;
|
|
28
|
+
if (budget.remaining() <= 0) {
|
|
29
|
+
item.around = null;
|
|
30
|
+
item.aroundIssue = "read-bytes";
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
signal?.throwIfAborted();
|
|
34
|
+
try {
|
|
35
|
+
const rows = await reader.around(item.ref, window);
|
|
36
|
+
const around = [];
|
|
37
|
+
for (const row of rows.slice(0, window.before + window.after)) {
|
|
38
|
+
const text = excerpt(row.text, "", 200);
|
|
39
|
+
const bytes = Buffer.byteLength(text);
|
|
40
|
+
if (bytes > budget.remaining()) {
|
|
41
|
+
item.aroundIssue = "read-bytes";
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
budget.charge(bytes);
|
|
45
|
+
around.push({ ...row, text, found: known(row.ref) });
|
|
46
|
+
}
|
|
47
|
+
item.around = around;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
signal?.throwIfAborted();
|
|
51
|
+
if (!(error instanceof CliError))
|
|
52
|
+
throw error;
|
|
53
|
+
item.around = null;
|
|
54
|
+
item.aroundIssue = error.code;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
@@ -2,6 +2,7 @@ import { type ContextSource } from "../context/evidence.js";
|
|
|
2
2
|
export interface ProjectGatheringRequest {
|
|
3
3
|
project: {
|
|
4
4
|
name: string;
|
|
5
|
+
key?: string;
|
|
5
6
|
background?: string;
|
|
6
7
|
aliases?: string[];
|
|
7
8
|
};
|
|
@@ -17,6 +18,11 @@ export interface ProjectGatheringRequest {
|
|
|
17
18
|
before?: number;
|
|
18
19
|
asOf?: number;
|
|
19
20
|
fetch?: "none" | "before-read";
|
|
21
|
+
index?: "update" | "as-is";
|
|
22
|
+
around?: {
|
|
23
|
+
before: number;
|
|
24
|
+
after: number;
|
|
25
|
+
};
|
|
20
26
|
budgets?: ProjectGatheringBudgets;
|
|
21
27
|
runKey?: string;
|
|
22
28
|
checkpoint?: string;
|
|
@@ -29,7 +35,7 @@ export interface ProjectGatheringBudgets {
|
|
|
29
35
|
maxElapsedMs?: number;
|
|
30
36
|
maxItems?: number;
|
|
31
37
|
}
|
|
32
|
-
export type ProjectLaneKind = "project" | "alias" | "keyword" | "person";
|
|
38
|
+
export type ProjectLaneKind = "project" | "key" | "alias" | "keyword" | "person";
|
|
33
39
|
export interface ProjectLane {
|
|
34
40
|
id: string;
|
|
35
41
|
kinds: ProjectLaneKind[];
|
|
@@ -73,6 +79,7 @@ export declare const CONTEXT_CHUNK_DAYS = 90;
|
|
|
73
79
|
export declare const projectGatheringRequest: (input: ProjectGatheringRequest, now: number) => {
|
|
74
80
|
project: {
|
|
75
81
|
name: string;
|
|
82
|
+
key: string | null;
|
|
76
83
|
background: string | null;
|
|
77
84
|
aliases: string[];
|
|
78
85
|
};
|
|
@@ -91,6 +98,11 @@ export declare const projectGatheringRequest: (input: ProjectGatheringRequest, n
|
|
|
91
98
|
asOf: number;
|
|
92
99
|
};
|
|
93
100
|
fetch: "before-read" | "none";
|
|
101
|
+
index: "as-is" | "update";
|
|
102
|
+
around: {
|
|
103
|
+
before: number;
|
|
104
|
+
after: number;
|
|
105
|
+
};
|
|
94
106
|
budgets: Required<ProjectGatheringBudgets>;
|
|
95
107
|
fingerprint: string;
|
|
96
108
|
runKey: string;
|
|
@@ -55,6 +55,8 @@ export const projectGatheringRequest = (input, now) => {
|
|
|
55
55
|
"before",
|
|
56
56
|
"asOf",
|
|
57
57
|
"fetch",
|
|
58
|
+
"index",
|
|
59
|
+
"around",
|
|
58
60
|
"budgets",
|
|
59
61
|
"runKey",
|
|
60
62
|
"checkpoint",
|
|
@@ -62,9 +64,10 @@ export const projectGatheringRequest = (input, now) => {
|
|
|
62
64
|
], "");
|
|
63
65
|
if (!input.project || typeof input.project !== "object")
|
|
64
66
|
fail("project needs a name", "project");
|
|
65
|
-
known(input.project, ["name", "background", "aliases"], "project.");
|
|
67
|
+
known(input.project, ["name", "key", "background", "aliases"], "project.");
|
|
66
68
|
const project = {
|
|
67
69
|
name: text(input.project.name, "project.name", 512),
|
|
70
|
+
key: input.project.key === undefined ? null : text(input.project.key, "project.key", 64),
|
|
68
71
|
background: input.project.background === undefined ? null : text(input.project.background, "project.background", 8192),
|
|
69
72
|
aliases: list(input.project.aliases, "project.aliases", LIMITS.lanes).map((a, i) => text(a, `project.aliases.${i}`, 512)),
|
|
70
73
|
};
|
|
@@ -104,6 +107,8 @@ export const projectGatheringRequest = (input, now) => {
|
|
|
104
107
|
found.people.push(person);
|
|
105
108
|
};
|
|
106
109
|
lane("project", laneQuery(project.name, "project.name"));
|
|
110
|
+
if (project.key)
|
|
111
|
+
lane("key", laneQuery(project.key, "project.key"));
|
|
107
112
|
for (const [i, a] of project.aliases.entries())
|
|
108
113
|
lane("alias", laneQuery(a, `project.aliases.${i}`));
|
|
109
114
|
for (const k of keywords)
|
|
@@ -113,19 +118,30 @@ export const projectGatheringRequest = (input, now) => {
|
|
|
113
118
|
if (lanes.length > LIMITS.lanes)
|
|
114
119
|
fail(`at most ${LIMITS.lanes} distinct search lanes`, "keywords");
|
|
115
120
|
const fetch = input.fetch ?? "none";
|
|
121
|
+
const index = input.index ?? "update";
|
|
122
|
+
if (index !== "update" && index !== "as-is")
|
|
123
|
+
fail("index must be update or as-is", "index");
|
|
124
|
+
if (input.around !== undefined && (!input.around || typeof input.around !== "object"))
|
|
125
|
+
fail("around needs before and after", "around");
|
|
126
|
+
if (input.around)
|
|
127
|
+
known(input.around, ["before", "after"], "around.");
|
|
128
|
+
const around = {
|
|
129
|
+
before: whole(input.around?.before ?? 2, "around.before", 0, 5),
|
|
130
|
+
after: whole(input.around?.after ?? 2, "around.after", 0, 5),
|
|
131
|
+
};
|
|
116
132
|
if (fetch !== "none" && fetch !== "before-read")
|
|
117
133
|
fail("fetch must be none or before-read", "fetch");
|
|
118
134
|
const explicit = input.after !== undefined || input.before !== undefined;
|
|
119
135
|
if (explicit && input.lookbackDays !== undefined)
|
|
120
136
|
fail("give lookbackDays or after/before, not both", "lookbackDays");
|
|
121
|
-
if (explicit &&
|
|
122
|
-
fail("an explicit window needs
|
|
137
|
+
if (explicit && input.after === undefined)
|
|
138
|
+
fail("an explicit window needs after; before defaults to asOf", "after");
|
|
123
139
|
const asOf = input.asOf === undefined ? null : whole(input.asOf, "asOf", 1, MAX_TIME);
|
|
124
140
|
const lookbackDays = explicit ? null : whole(input.lookbackDays ?? 60, "lookbackDays", 1, LIMITS.lookbackDays);
|
|
125
141
|
const window = explicit
|
|
126
142
|
? (() => {
|
|
127
143
|
const after = whole(input.after, "after", 0, MAX_TIME);
|
|
128
|
-
const before = whole(input.before, "before", after + 1, MAX_TIME);
|
|
144
|
+
const before = whole(input.before ?? asOf ?? now, "before", after + 1, MAX_TIME);
|
|
129
145
|
if (before - after > LIMITS.lookbackDays * DAY)
|
|
130
146
|
fail(`window must not exceed ${LIMITS.lookbackDays} days`, "after");
|
|
131
147
|
return { after, before, asOf: asOf ?? before };
|
|
@@ -150,7 +166,7 @@ export const projectGatheringRequest = (input, now) => {
|
|
|
150
166
|
sources.map(contextSourceKey),
|
|
151
167
|
input.scope,
|
|
152
168
|
lookbackDays,
|
|
153
|
-
explicit ? [window.after,
|
|
169
|
+
explicit ? [window.after, input.before ?? null] : null,
|
|
154
170
|
asOf,
|
|
155
171
|
fetch,
|
|
156
172
|
]))
|
|
@@ -168,6 +184,8 @@ export const projectGatheringRequest = (input, now) => {
|
|
|
168
184
|
lookbackDays,
|
|
169
185
|
window,
|
|
170
186
|
fetch,
|
|
187
|
+
index,
|
|
188
|
+
around,
|
|
171
189
|
budgets,
|
|
172
190
|
fingerprint,
|
|
173
191
|
runKey,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ContextEvidenceItem, ContextEvidenceReader, ContextSource } from "../context/evidence.js";
|
|
1
|
+
import type { ContextEvidenceItem, ContextEvidenceReader, ContextIndex, ContextSource } from "../context/evidence.js";
|
|
2
|
+
import { type ProjectNeighbour, type ProjectNeighbourReader } from "./project-gathering-around.js";
|
|
2
3
|
import { type ProjectFetchState, type ProjectGatheringRequest, type ProjectLane } from "./project-gathering-request.js";
|
|
3
4
|
/** A connector's history fetch into the store; the store reads that follow find what it saved. */
|
|
4
5
|
export interface ProjectSourceFetcher {
|
|
@@ -15,8 +16,16 @@ export interface ProjectSourceFetcher {
|
|
|
15
16
|
export interface ProjectGatheringPorts {
|
|
16
17
|
evidence: ContextEvidenceReader;
|
|
17
18
|
fetcher?: ProjectSourceFetcher;
|
|
19
|
+
index?: ContextIndex;
|
|
20
|
+
neighbours?: ProjectNeighbourReader;
|
|
18
21
|
now?: () => number;
|
|
19
22
|
}
|
|
23
|
+
export interface ProjectIndexCatchUp {
|
|
24
|
+
state: "updated" | "as-is" | "unavailable" | "failed";
|
|
25
|
+
mail: number;
|
|
26
|
+
documents: number;
|
|
27
|
+
code: string | null;
|
|
28
|
+
}
|
|
20
29
|
export interface ProjectEvidenceItem extends Omit<ContextEvidenceItem, "text"> {
|
|
21
30
|
kind: ContextSource["kind"];
|
|
22
31
|
source: number;
|
|
@@ -24,6 +33,8 @@ export interface ProjectEvidenceItem extends Omit<ContextEvidenceItem, "text"> {
|
|
|
24
33
|
textTruncated: boolean;
|
|
25
34
|
lanes: string[];
|
|
26
35
|
context: "project" | "person-only";
|
|
36
|
+
around?: ProjectNeighbour[] | null;
|
|
37
|
+
aroundIssue?: string | null;
|
|
27
38
|
}
|
|
28
39
|
export type ProjectGatheringStop = "reads" | "read-bytes" | "elapsed" | "items" | null;
|
|
29
40
|
export declare const gatherProjectEvidence: (ports: ProjectGatheringPorts, request: ProjectGatheringRequest) => Promise<{
|
|
@@ -33,6 +44,7 @@ export declare const gatherProjectEvidence: (ports: ProjectGatheringPorts, reque
|
|
|
33
44
|
resumed: boolean;
|
|
34
45
|
project: {
|
|
35
46
|
name: string;
|
|
47
|
+
key: string | null;
|
|
36
48
|
background: string | null;
|
|
37
49
|
aliases: string[];
|
|
38
50
|
};
|
|
@@ -55,6 +67,7 @@ export declare const gatherProjectEvidence: (ports: ProjectGatheringPorts, reque
|
|
|
55
67
|
code: string | null;
|
|
56
68
|
source: number;
|
|
57
69
|
}[];
|
|
70
|
+
index: ProjectIndexCatchUp;
|
|
58
71
|
units: {
|
|
59
72
|
lane: string;
|
|
60
73
|
source: number;
|
|
@@ -72,6 +85,7 @@ export declare const gatherProjectEvidence: (ports: ProjectGatheringPorts, reque
|
|
|
72
85
|
usage: {
|
|
73
86
|
reads: number;
|
|
74
87
|
readBytes: number;
|
|
88
|
+
aroundBytes: number;
|
|
75
89
|
items: number;
|
|
76
90
|
elapsedMs: number;
|
|
77
91
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { createContextEvidenceReader } from "./context-evidence.js";
|
|
3
3
|
import { excerpt } from "./excerpt.js";
|
|
4
|
+
import { attachNeighbours } from "./project-gathering-around.js";
|
|
4
5
|
import { decodeCheckpoint, encodeCheckpoint, projectGatheringRequest, projectUnits, seenKey, } from "./project-gathering-request.js";
|
|
5
6
|
const terminal = new Set(["done", "unavailable", "failed"]);
|
|
6
7
|
export const gatherProjectEvidence = async (ports, request) => {
|
|
@@ -12,6 +13,9 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
12
13
|
const previous = plan.checkpoint === undefined ? null : decodeCheckpoint(plan.checkpoint, plan);
|
|
13
14
|
const window = previous ?? plan.window;
|
|
14
15
|
const units = projectUnits(plan, window);
|
|
16
|
+
// A default that cannot finish one round would leave whole searches or sources unread; an explicit one is kept.
|
|
17
|
+
if (request.budgets?.maxReads === undefined)
|
|
18
|
+
plan.budgets.maxReads = Math.min(512, Math.max(48, units.length));
|
|
15
19
|
if (previous && (previous.units.length !== units.length || previous.fetched.length !== plan.sources.length))
|
|
16
20
|
throw new CliError("validation_error", "invalid project gathering checkpoint", { param: "checkpoint" });
|
|
17
21
|
const progress = previous?.units.map((u) => ({ ...u })) ??
|
|
@@ -43,7 +47,27 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
43
47
|
fetched[index] = { state: "failed", history: null, code: error.code };
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
|
-
const
|
|
50
|
+
const indexed = { state: "as-is", mail: 0, documents: 0, code: null };
|
|
51
|
+
const kinds = [...new Set(plan.sources.map((source) => source.kind))].filter((kind) => kind !== "message");
|
|
52
|
+
if (plan.index === "update" && kinds.length) {
|
|
53
|
+
signal?.throwIfAborted();
|
|
54
|
+
if (!ports.index || typeof ports.index.catchUp !== "function")
|
|
55
|
+
indexed.state = "unavailable";
|
|
56
|
+
else
|
|
57
|
+
try {
|
|
58
|
+
const done = await ports.index.catchUp({ kinds, signal });
|
|
59
|
+
if (!Number.isSafeInteger(done?.mail) || !Number.isSafeInteger(done?.documents))
|
|
60
|
+
throw new CliError("invalid_response", "index catch-up returned invalid counts");
|
|
61
|
+
Object.assign(indexed, { state: "updated", mail: done.mail, documents: done.documents });
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
signal?.throwIfAborted();
|
|
65
|
+
if (!(error instanceof CliError))
|
|
66
|
+
throw error;
|
|
67
|
+
Object.assign(indexed, { state: "failed", code: error.code });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const usage = { reads: 0, readBytes: 0, aroundBytes: 0, items: 0 };
|
|
47
71
|
const items = [];
|
|
48
72
|
const byRef = new Map();
|
|
49
73
|
const matchedAgain = new Map();
|
|
@@ -145,6 +169,12 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
145
169
|
}
|
|
146
170
|
}
|
|
147
171
|
}
|
|
172
|
+
await attachNeighbours(items, ports.neighbours, plan.around, {
|
|
173
|
+
remaining: () => plan.budgets.maxReadBytes - usage.readBytes - usage.aroundBytes,
|
|
174
|
+
charge: (bytes) => {
|
|
175
|
+
usage.aroundBytes += bytes;
|
|
176
|
+
},
|
|
177
|
+
}, (ref) => byRef.has(ref) || seen.has(seenKey(ref)), signal);
|
|
148
178
|
const totals = {
|
|
149
179
|
reads: (previous?.totals.reads ?? 0) + usage.reads,
|
|
150
180
|
readBytes: (previous?.totals.readBytes ?? 0) + usage.readBytes,
|
|
@@ -181,6 +211,7 @@ export const gatherProjectEvidence = async (ports, request) => {
|
|
|
181
211
|
scope: { origin: plan.scope, sources: plan.sources },
|
|
182
212
|
lanes: plan.lanes,
|
|
183
213
|
fetch: fetched.map((f, index) => ({ source: index, ...f })),
|
|
214
|
+
index: indexed,
|
|
184
215
|
units: units.map((unit, index) => ({
|
|
185
216
|
lane: unit.lane.id,
|
|
186
217
|
source: unit.sourceIndex,
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { type ContextEvidenceReader } from "../../context/evidence.js";
|
|
1
|
+
import { type ContextEvidenceReader, type ContextIndex } from "../../context/evidence.js";
|
|
2
|
+
import type { Stemmer, Stemmers } from "../../search/stem.js";
|
|
2
3
|
import type { StoreContext } from "./open.js";
|
|
3
4
|
/** No index fills, model loads or record hydration outside the read transaction. */
|
|
4
5
|
export declare const contextEvidenceOver: ({ database }: Pick<StoreContext, "database">) => ContextEvidenceReader;
|
|
6
|
+
/** The same fills a mail search and the notes search run before reading; a message is indexed when it is saved. */
|
|
7
|
+
export declare const contextIndexOver: ({ database }: Pick<StoreContext, "database">, stemmerFor: (stemmers: Stemmers) => Stemmer) => ContextIndex;
|
|
@@ -3,6 +3,8 @@ import { contextCursorScope, contextEvidenceRequest, } from "../../context/evide
|
|
|
3
3
|
import { formatLocator } from "../../domain/locator.js";
|
|
4
4
|
import { NORMALIZER_VERSION, normalize } from "../normalize.js";
|
|
5
5
|
import { contextDocumentTime, contextDocumentTimeKind, contextDocumentUrl } from "./context-document-source.js";
|
|
6
|
+
import { drainEmailIndex } from "./email-index.js";
|
|
7
|
+
import { drainNoteIndex } from "./note-index.js";
|
|
6
8
|
import { read } from "./transaction.js";
|
|
7
9
|
const corpora = {
|
|
8
10
|
message: {
|
|
@@ -163,3 +165,13 @@ export const contextEvidenceOver = ({ database }) => ({
|
|
|
163
165
|
});
|
|
164
166
|
},
|
|
165
167
|
});
|
|
168
|
+
/** The same fills a mail search and the notes search run before reading; a message is indexed when it is saved. */
|
|
169
|
+
export const contextIndexOver = ({ database }, stemmerFor) => ({
|
|
170
|
+
async catchUp({ kinds, signal }) {
|
|
171
|
+
signal?.throwIfAborted();
|
|
172
|
+
const mail = kinds.includes("mail") ? drainEmailIndex(database, stemmerFor) : 0;
|
|
173
|
+
signal?.throwIfAborted();
|
|
174
|
+
const documents = kinds.includes("document") ? drainNoteIndex(database, stemmerFor) : 0;
|
|
175
|
+
return { mail, documents };
|
|
176
|
+
},
|
|
177
|
+
});
|
package/dist/store/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ContextEvidenceReader } from "../context/evidence.js";
|
|
1
|
+
import type { ContextEvidenceReader, ContextIndex } from "../context/evidence.js";
|
|
2
2
|
import { type AccountStore } from "./account-store.js";
|
|
3
3
|
import { type AccountsStore } from "./accounts.js";
|
|
4
4
|
import { type AttachmentsStore } from "./attachments.js";
|
|
@@ -34,6 +34,7 @@ import type { AccountKey } from "./types.js";
|
|
|
34
34
|
import { type VectorsStore } from "./vectors.js";
|
|
35
35
|
export interface MessageStore {
|
|
36
36
|
readonly contextEvidence?: ContextEvidenceReader;
|
|
37
|
+
readonly contextIndex?: ContextIndex;
|
|
37
38
|
/** Accounts, account groups and which account each app profile is. */
|
|
38
39
|
readonly accounts: AccountsStore;
|
|
39
40
|
/** One account's chats: the list, what left, what is complete, their metadata. */
|
package/dist/store/store.js
CHANGED
|
@@ -16,7 +16,7 @@ import { agentActionsStoreOver } from "./sqlite/agent-actions.js";
|
|
|
16
16
|
import * as attachmentTexts from "./sqlite/attachment-texts.js";
|
|
17
17
|
import { botUpdateStoreOver } from "./sqlite/bot-updates.js";
|
|
18
18
|
import { catalogStoreOver } from "./sqlite/catalog.js";
|
|
19
|
-
import { contextEvidenceOver } from "./sqlite/context-evidence.js";
|
|
19
|
+
import { contextEvidenceOver, contextIndexOver } from "./sqlite/context-evidence.js";
|
|
20
20
|
import { mailStoreOver } from "./sqlite/emails.js";
|
|
21
21
|
import { factsStoreOver } from "./sqlite/facts.js";
|
|
22
22
|
import { involvementStoreOver } from "./sqlite/involvements.js";
|
|
@@ -81,6 +81,7 @@ const storeOver = (context) => {
|
|
|
81
81
|
mentions: areaOf(() => accountMentionsOver(context), (keyed) => mentionsStoreOver(context, keyed)),
|
|
82
82
|
};
|
|
83
83
|
const contextEvidence = once(() => contextEvidenceOver(context));
|
|
84
|
+
const contextIndex = once(() => contextIndexOver(context, stemmerFor));
|
|
84
85
|
const searches = once(() => searchesStoreOver(context));
|
|
85
86
|
const queries = once(() => queriesStoreOver(context, stemmerFor));
|
|
86
87
|
const searchIndex = once(() => searchIndexStoreOver(context));
|
|
@@ -101,6 +102,9 @@ const storeOver = (context) => {
|
|
|
101
102
|
get contextEvidence() {
|
|
102
103
|
return contextEvidence();
|
|
103
104
|
},
|
|
105
|
+
get contextIndex() {
|
|
106
|
+
return contextIndex();
|
|
107
|
+
},
|
|
104
108
|
meetingVectors: meetingVectorsOver(context),
|
|
105
109
|
get accounts() {
|
|
106
110
|
return areas.accounts().whole;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.349.0",
|
|
4
4
|
"description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|
package/parity.json
CHANGED
|
@@ -4053,12 +4053,7 @@
|
|
|
4053
4053
|
"in": ["tg"],
|
|
4054
4054
|
"reason": "Telegram asks each client for its own app from my.telegram.org; MAX has no such step; WhatsApp has no application registration"
|
|
4055
4055
|
},
|
|
4056
|
-
"--qr-file":
|
|
4057
|
-
"in": ["tg", "wa"],
|
|
4058
|
-
"planned": {
|
|
4059
|
-
"max": "max-cli#736, on the cli-core release that exports loginQr"
|
|
4060
|
-
}
|
|
4061
|
-
},
|
|
4056
|
+
"--qr-file": "all",
|
|
4062
4057
|
"--sms": {
|
|
4063
4058
|
"in": ["tg"],
|
|
4064
4059
|
"reason": "asks Telegram to resend its login code by SMS; MAX has no such choice; WhatsApp links a device by QR or pairing code, never by an SMS code"
|
|
@@ -4074,12 +4069,7 @@
|
|
|
4074
4069
|
"reason": "Telegram requires an application from my.telegram.org; MAX has no application registration step; WhatsApp has no application registration"
|
|
4075
4070
|
},
|
|
4076
4071
|
"--method": "all",
|
|
4077
|
-
"--qr-file":
|
|
4078
|
-
"in": ["tg", "wa"],
|
|
4079
|
-
"planned": {
|
|
4080
|
-
"max": "max-cli#736, on the cli-core release that exports loginQr"
|
|
4081
|
-
}
|
|
4082
|
-
}
|
|
4072
|
+
"--qr-file": "all"
|
|
4083
4073
|
}
|
|
4084
4074
|
},
|
|
4085
4075
|
"skill": {
|