@wirecat/cli-core 0.685.0 → 0.686.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 +20 -0
- package/dist/documents/model.d.ts +1 -0
- package/dist/services/documents/ingestion.d.ts +4 -1
- package/dist/services/documents/ingestion.js +11 -0
- package/dist/services/documents/knowledge.js +18 -3
- package/dist/services/documents/ports.d.ts +2 -0
- package/dist/services/documents/sync.js +2 -0
- package/dist/store/sqlite/note-search.js +4 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,26 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.686.0 — 16.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **The documents engine records which account a CLI's profile is.** `documentIngestion` takes the CLI's `command`
|
|
13
|
+
and answers `registerProfile(name, principal)`, and `syncDocuments` calls it with its new `profile` option once the
|
|
14
|
+
signed-in account is checked. A search hit from a documents CLI then names the CLI and the profile (`notion`,
|
|
15
|
+
`work`), not `notes` and a store id. drive did this on its own; every documents CLI now gets it by passing both.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- **An agent's `relationships add` on a shared documents CLI is saved.** It is written as an unconfirmed suggestion
|
|
20
|
+
for the owner, with the agent and its reason in the provenance. The store used to refuse it, so nothing was written
|
|
21
|
+
although the error said it would be saved unconfirmed. The owner decides it in the same commands: adding the same
|
|
22
|
+
relationship confirms it, and removing it rejects it.
|
|
23
|
+
- **A folder in a documents account stays out of search.** A Drive folder, a Notion workspace or a Notion database
|
|
24
|
+
is a catalog entry, not a document: word search, the newest-first read memo's digest makes, meaning search and
|
|
25
|
+
embedding now leave it out, as document lists already did. It used to show up with an empty excerpt, and
|
|
26
|
+
`documents show` could not open it.
|
|
27
|
+
|
|
8
28
|
## 0.685.0 — 16.11.2026
|
|
9
29
|
|
|
10
30
|
### Added
|
|
@@ -123,6 +123,7 @@ export interface SourceIndex<M extends SourceFile = SourceFile> {
|
|
|
123
123
|
settle?(options: {
|
|
124
124
|
until: () => boolean;
|
|
125
125
|
}): Promise<unknown>;
|
|
126
|
+
registerProfile?(name: string, principal: string): Promise<void>;
|
|
126
127
|
}
|
|
127
128
|
export interface SourceStatePort<M extends SourceFile = SourceFile> {
|
|
128
129
|
read(): SourceState<M>;
|
|
@@ -6,13 +6,16 @@ export interface IngestionOptions<M extends SourceFile> {
|
|
|
6
6
|
* `{ provider, account: principal }`. Without it they live in a notes folder named `collectionName(principal)`.
|
|
7
7
|
*/
|
|
8
8
|
provider?: string;
|
|
9
|
+
/** The CLI's command (`notion`), which names its profiles: with `provider`, a sync records which account each is. */
|
|
10
|
+
command?: string;
|
|
9
11
|
collectionName?(principal: string): string;
|
|
10
12
|
externalId(id: string): string;
|
|
11
13
|
catalogInput(file: M): CatalogInput;
|
|
12
14
|
frontMatter(content: SourceContent<M>): Record<string, unknown>;
|
|
13
15
|
observed?(principal: string, file: M, documentId: string): Promise<void>;
|
|
14
16
|
}
|
|
15
|
-
export declare const documentIngestion: <M extends SourceFile>(store: Pick<MessageStore, "notes" | "catalog" | "memories">, options: IngestionOptions<M>) => {
|
|
17
|
+
export declare const documentIngestion: <M extends SourceFile>(store: Pick<MessageStore, "notes" | "catalog" | "memories" | "accounts">, options: IngestionOptions<M>) => {
|
|
18
|
+
registerProfile?: ((name: string, principal: string) => Promise<void>) | undefined;
|
|
16
19
|
catalog: {
|
|
17
20
|
import: (principal: string, files: M[]) => Promise<{
|
|
18
21
|
entries: number;
|
|
@@ -25,7 +25,18 @@ export const documentIngestion = (store, options) => {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
+
const { provider, command } = options;
|
|
28
29
|
return {
|
|
30
|
+
// Only where both are known: a sync calls it whenever it is there and a profile is given.
|
|
31
|
+
...(provider && command
|
|
32
|
+
? {
|
|
33
|
+
/** Names the profile's account in the store, so a search hit says `notion`/`work`, not `notes`/`1`. */
|
|
34
|
+
registerProfile: async (name, principal) => {
|
|
35
|
+
await folder(principal, true);
|
|
36
|
+
await store.accounts.saveProfile(command, name, { provider, account: principal });
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
: {}),
|
|
29
40
|
catalog: {
|
|
30
41
|
import: async (principal, files) => {
|
|
31
42
|
const selected = await folder(principal, true);
|
|
@@ -76,11 +76,26 @@ export const documentKnowledge = (store, folder) => {
|
|
|
76
76
|
},
|
|
77
77
|
addLink: async (principal, ref, input) => {
|
|
78
78
|
await document(principal, ref);
|
|
79
|
-
|
|
79
|
+
const by = writer(input.by);
|
|
80
|
+
const link = await store.notes.addLink({
|
|
81
|
+
...input,
|
|
82
|
+
from: ref,
|
|
83
|
+
...(by === "owner"
|
|
84
|
+
? { origin: "owner" }
|
|
85
|
+
: { origin: "suggested", confirmed: false, provenance: `agent:${by.bot}: ${by.reason.trim()}` }),
|
|
86
|
+
});
|
|
87
|
+
// The store answers an agent's pending link for the same pair; the owner adding it is the owner confirming it.
|
|
88
|
+
if (by !== "owner" || link.confirmed)
|
|
89
|
+
return link;
|
|
90
|
+
return (await store.knowledge.decideSuggestedLink(link.id, { confirm: true, by })) ?? link;
|
|
80
91
|
},
|
|
81
92
|
removeLink: async (principal, ref, id, by) => {
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
93
|
+
const link = (await port.links(principal, ref)).find((item) => item.id === id);
|
|
94
|
+
if (link && !link.confirmed) {
|
|
95
|
+
await store.knowledge.decideSuggestedLink(id, { confirm: false, by });
|
|
96
|
+
return { id, removed: true };
|
|
97
|
+
}
|
|
98
|
+
if (link?.origin !== "owner")
|
|
84
99
|
throw new CliError("not_found", "owner link is not attached to this document");
|
|
85
100
|
return store.notes.removeLink(id, by);
|
|
86
101
|
},
|
|
@@ -7,6 +7,8 @@ export interface SyncOptions<M extends SourceFile> {
|
|
|
7
7
|
index: SourceIndex<M>;
|
|
8
8
|
state: SourceStatePort<M>;
|
|
9
9
|
principal: string;
|
|
10
|
+
/** The profile being synced, recorded against `principal` once the signed-in account is checked. */
|
|
11
|
+
profile?: string;
|
|
10
12
|
roots: string[];
|
|
11
13
|
query?: SourceQuery<M>;
|
|
12
14
|
textLimit: number;
|
|
@@ -46,6 +46,8 @@ export const syncDocuments = async (options) => {
|
|
|
46
46
|
const state = statePort.read();
|
|
47
47
|
if (state.principal !== principal)
|
|
48
48
|
throw new CliError("configuration_error", "sync state belongs to another source account");
|
|
49
|
+
if (options.profile !== undefined)
|
|
50
|
+
await index.registerProfile?.(options.profile, principal);
|
|
49
51
|
const currentScope = scopeHash(profile.roots, query, options.isDocument !== undefined);
|
|
50
52
|
if (state.pending && (state.pending.scope !== currentScope || rescan)) {
|
|
51
53
|
// Work the new plan cannot see: a file saved to the index before its state was.
|
|
@@ -47,11 +47,12 @@ const CORPORA = [
|
|
|
47
47
|
noun: "note",
|
|
48
48
|
fields: NOTE_FIELDS,
|
|
49
49
|
get view() {
|
|
50
|
-
return `(SELECT n.id, n.account_id AS folder_id, n.external_id AS path, n.title, coalesce(n.body, '') AS text, n.metadata, ${contextDocumentTime()} AS at, n.deleted_at FROM documents n)`;
|
|
50
|
+
return `(SELECT n.id, n.account_id AS folder_id, n.external_id AS path, n.title, coalesce(n.body, '') AS text, n.metadata, ${contextDocumentTime()} AS at, n.deleted_at, n.kind FROM documents n)`;
|
|
51
51
|
},
|
|
52
52
|
words: "document_words",
|
|
53
53
|
stems: "document_stems",
|
|
54
|
-
|
|
54
|
+
// A folder (a Drive folder, a Notion workspace or database) is a catalog entry, not a document to open.
|
|
55
|
+
live: "n.kind <> 'folder' AND coalesce(json_extract(n.metadata, '$.catalog.active'), 1)=1",
|
|
55
56
|
inAccounts: (ids) => bound("n.folder_id IN (SELECT CAST(value AS INTEGER) FROM json_each(?))", ids),
|
|
56
57
|
tagged: (tag) => bound("(n.id IN (SELECT g.taggable_id FROM taggings g JOIN resolved_tags t ON t.id=g.tag_id WHERE t.name = ? AND g.taggable_type = 'document') " +
|
|
57
58
|
"OR n.folder_id IN (SELECT g.taggable_id FROM taggings g JOIN resolved_tags t ON t.id=g.tag_id WHERE t.name = ? AND g.taggable_type = 'account') " +
|
|
@@ -339,7 +340,7 @@ export const searchCorpus = (context, query, corpus) => {
|
|
|
339
340
|
const SCAN_PAGE = 5_000;
|
|
340
341
|
const SETTLE_BATCH = 50;
|
|
341
342
|
/** The live documents and notes of a chunk scan, narrowed by folder and source. */
|
|
342
|
-
const LIVE = "((k.chunkable_type = 'document' AND EXISTS (SELECT 1 FROM documents d WHERE d.id = k.chunkable_id AND d.deleted_at IS NULL AND coalesce(json_extract(d.metadata, '$.catalog.active'), 1)=1 " +
|
|
343
|
+
const LIVE = "((k.chunkable_type = 'document' AND EXISTS (SELECT 1 FROM documents d WHERE d.id = k.chunkable_id AND d.deleted_at IS NULL AND d.kind <> 'folder' AND coalesce(json_extract(d.metadata, '$.catalog.active'), 1)=1 " +
|
|
343
344
|
"AND (? IS NULL OR d.account_id IN (SELECT CAST(value AS INTEGER) FROM json_each(?))))) " +
|
|
344
345
|
"OR (k.chunkable_type = 'note' AND ? IS NULL AND EXISTS (SELECT 1 FROM notes n WHERE n.id = k.chunkable_id AND n.deleted_at IS NULL)))";
|
|
345
346
|
export const noteSearchOver = (context) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.686.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",
|