@wirecat/cli-core 0.632.0 → 0.633.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 +11 -0
- package/dist/cli/messenger/archive-commands.js +4 -1
- package/dist/cli/messenger/store-import-command.d.ts +4 -0
- package/dist/cli/messenger/store-import-command.js +166 -0
- package/dist/cli/messenger/stored.d.ts +7 -1
- package/dist/cli/messenger/stored.js +1 -1
- package/dist/entities/index.d.ts +17 -2
- package/dist/entities/index.js +3 -2
- package/dist/entities/store-maintenance.d.ts +16 -0
- package/dist/entities/store-maintenance.js +10 -0
- package/dist/sends/permissions.js +1 -0
- package/dist/store/path.d.ts +3 -0
- package/dist/store/path.js +25 -6
- package/package.json +1 -1
- package/parity.json +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ 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.633.0 — 10.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **`<tool> <profile> store import <file.json>` loads made-up chats, people and messages into a test store**, for
|
|
13
|
+
WireCat Desktop's sandbox: Search and Analytics get messenger data without anyone signing in. The file is the
|
|
14
|
+
adapter kit's `Seed` shape plus `"synthetic": true` (the format: the API reference, "Made-up data for a test store");
|
|
15
|
+
it is written as a pushed sync writes, so the same file twice adds nothing and a changed message is updated in
|
|
16
|
+
place. Without `--yes` it only says what it would load. It refuses a file not marked synthetic, the owner's real
|
|
17
|
+
store (whatever `HOME` says), and a profile recorded as another account. New permission key `store.import`, `ask`.
|
|
18
|
+
|
|
8
19
|
## 0.632.0 — 10.11.2026
|
|
9
20
|
|
|
10
21
|
### Added
|
|
@@ -20,6 +20,7 @@ import { gapsCommand } from "./gaps-command.js";
|
|
|
20
20
|
import { historyLimitGaps } from "./history-gaps.js";
|
|
21
21
|
import { messageItems } from "./message-items.js";
|
|
22
22
|
import { ENCRYPT_OPTION, passwordOf } from "./password.js";
|
|
23
|
+
import { storeImportCommand } from "./store-import-command.js";
|
|
23
24
|
import { storeMaintenanceCommands } from "./store-maintenance-command.js";
|
|
24
25
|
/** `store`: the local store of messages — what it holds, filling it, reading it out, and looking after the file. */
|
|
25
26
|
export const storeCommand = (messenger) => {
|
|
@@ -30,7 +31,8 @@ export const storeCommand = (messenger) => {
|
|
|
30
31
|
.addCommand(gapsCommand(messenger))
|
|
31
32
|
.addCommand(jobsCommand(messenger))
|
|
32
33
|
.addCommand(exportCommand(messenger))
|
|
33
|
-
.addCommand(clearCommand(messenger))
|
|
34
|
+
.addCommand(clearCommand(messenger))
|
|
35
|
+
.addCommand(storeImportCommand(messenger));
|
|
34
36
|
for (const command of storeMaintenanceCommands(messenger))
|
|
35
37
|
store.addCommand(command);
|
|
36
38
|
const examples = {
|
|
@@ -43,6 +45,7 @@ export const storeCommand = (messenger) => {
|
|
|
43
45
|
export: '"Book club" --output ./messages.jsonl',
|
|
44
46
|
"gaps show": '"Book club"',
|
|
45
47
|
"gaps repair": '"Book club" --limit 100',
|
|
48
|
+
import: "./synthetic-chats.json --yes",
|
|
46
49
|
info: "",
|
|
47
50
|
"jobs cancel": "job-101",
|
|
48
51
|
"jobs clear": "",
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { type Messenger } from "./context.js";
|
|
3
|
+
/** `store import` — made-up chats, people and messages into a test or sandbox store, through the sync's own writes. */
|
|
4
|
+
export declare const storeImportCommand: (messenger: Messenger) => Command;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { CliError } from "@wirecat/cli-base";
|
|
3
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import * as v from "valibot";
|
|
6
|
+
import { accountHome, inOwnerFolder, storePath } from "../../store/path.js";
|
|
7
|
+
import { openStore } from "../../store/store.js";
|
|
8
|
+
import { changesStore, LOCAL_WRITE } from "../effects.js";
|
|
9
|
+
import { itemOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
10
|
+
import { accountFileFor, recalledAccount, rememberAccount } from "./accounts.js";
|
|
11
|
+
import { messengerContext } from "./context.js";
|
|
12
|
+
import { fill } from "./stored.js";
|
|
13
|
+
const id = v.pipe(v.string(), v.nonEmpty());
|
|
14
|
+
const time = v.pipe(v.string(), v.isoTimestamp(), v.transform((at) => new Date(at).toISOString()));
|
|
15
|
+
const name = v.nullish(v.string(), null);
|
|
16
|
+
const person = v.object({ id, name, username: name });
|
|
17
|
+
/** The adapter kit's `Seed` (`src/kit/seed.ts`) as a file: what a sync would have read, with the defaults filled in. */
|
|
18
|
+
const importFile = v.object({
|
|
19
|
+
synthetic: v.literal(true),
|
|
20
|
+
account: person,
|
|
21
|
+
people: v.optional(v.array(person), []),
|
|
22
|
+
chats: v.array(v.object({
|
|
23
|
+
id,
|
|
24
|
+
title: name,
|
|
25
|
+
kind: v.picklist(["dialog", "group", "channel", "saved", "unknown"]),
|
|
26
|
+
unreadCount: v.nullish(v.pipe(v.number(), v.integer(), v.minValue(0)), null),
|
|
27
|
+
lastMessageAt: v.nullish(time, null),
|
|
28
|
+
participantsCount: v.nullish(v.pipe(v.number(), v.integer(), v.minValue(0)), null),
|
|
29
|
+
})),
|
|
30
|
+
members: v.optional(v.record(v.string(), v.array(person)), {}),
|
|
31
|
+
messages: v.optional(v.array(v.object({
|
|
32
|
+
id,
|
|
33
|
+
chatId: id,
|
|
34
|
+
senderId: v.nullish(id, null),
|
|
35
|
+
senderName: name,
|
|
36
|
+
timestamp: time,
|
|
37
|
+
editedAt: v.nullish(time, null),
|
|
38
|
+
text: v.string(),
|
|
39
|
+
outgoing: v.optional(v.boolean()),
|
|
40
|
+
replyToId: v.optional(id),
|
|
41
|
+
})), []),
|
|
42
|
+
});
|
|
43
|
+
const readImport = (path) => {
|
|
44
|
+
let raw;
|
|
45
|
+
try {
|
|
46
|
+
raw = JSON.parse(readFileSync(path, "utf8"));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// The parser's message quotes the file, which may be anything its caller can read.
|
|
50
|
+
throw new CliError("validation_error", `cannot read ${path} as JSON`);
|
|
51
|
+
}
|
|
52
|
+
if (raw?.synthetic !== true)
|
|
53
|
+
throw new CliError("validation_error", `${path} does not say "synthetic": true — store import loads made-up test data only, never a real account's`);
|
|
54
|
+
const parsed = v.safeParse(importFile, raw);
|
|
55
|
+
if (!parsed.success) {
|
|
56
|
+
const issue = parsed.issues[0];
|
|
57
|
+
const at = v.getDotPath(issue) ?? "the file";
|
|
58
|
+
throw new CliError("validation_error", `${path}: ${at}: expected ${issue.expected ?? "another value"}`);
|
|
59
|
+
}
|
|
60
|
+
const file = parsed.output;
|
|
61
|
+
const chats = new Set(file.chats.map((chat) => chat.id));
|
|
62
|
+
for (const message of file.messages)
|
|
63
|
+
if (!chats.has(message.chatId))
|
|
64
|
+
throw new CliError("validation_error", `${path}: message ${message.id} names chat ${message.chatId}, not in chats`);
|
|
65
|
+
for (const chatId of Object.keys(file.members))
|
|
66
|
+
if (!chats.has(chatId))
|
|
67
|
+
throw new CliError("validation_error", `${path}: members name chat ${chatId}, not in chats`);
|
|
68
|
+
return file;
|
|
69
|
+
};
|
|
70
|
+
const messagesOf = (file) => file.messages.map(({ outgoing, ...message }) => ({
|
|
71
|
+
...message,
|
|
72
|
+
outgoing: outgoing === undefined ? message.senderId === file.account.id : outgoing,
|
|
73
|
+
attachments: [],
|
|
74
|
+
replyTo: null,
|
|
75
|
+
forwardedFrom: null,
|
|
76
|
+
reactions: null,
|
|
77
|
+
}));
|
|
78
|
+
/** A chat's newest message stands in for its `lastMessageAt` when the file leaves it out, as a chat list would say. */
|
|
79
|
+
const chatsOf = (file, messages) => {
|
|
80
|
+
const newest = new Map();
|
|
81
|
+
for (const { chatId, timestamp } of messages)
|
|
82
|
+
if ((newest.get(chatId) ?? "") < timestamp)
|
|
83
|
+
newest.set(chatId, timestamp);
|
|
84
|
+
return file.chats.map((chat) => ({ ...chat, lastMessageAt: chat.lastMessageAt ?? newest.get(chat.id) ?? null }));
|
|
85
|
+
};
|
|
86
|
+
const heldCounts = async (store, key) => ({
|
|
87
|
+
chats: await store.chats.countChats(key),
|
|
88
|
+
messages: (await store.chats.chatStats(key)).reduce((sum, chat) => sum + chat.messages, 0),
|
|
89
|
+
});
|
|
90
|
+
const refuseOwnerFolders = (messenger, profile, env, target) => {
|
|
91
|
+
const home = accountHome();
|
|
92
|
+
const ownState = home !== undefined &&
|
|
93
|
+
accountFileFor(messenger.app, profile, env) === accountFileFor(messenger.app, profile, { HOME: home });
|
|
94
|
+
if (!inOwnerFolder(target, home) && !ownState)
|
|
95
|
+
return;
|
|
96
|
+
throw new CliError("permission_error", `store import writes made-up data, and ${ownState ? `profile ${profile}'s state` : target} is the owner's real ` +
|
|
97
|
+
"one — run it in a sandbox (WireCat Desktop's bin/sandbox), with HOME, MESSAGING_STORE and the tool's state " +
|
|
98
|
+
"folder of its own");
|
|
99
|
+
};
|
|
100
|
+
/** `store import` — made-up chats, people and messages into a test or sandbox store, through the sync's own writes. */
|
|
101
|
+
export const storeImportCommand = (messenger) => changesStore(annotate(new Command("import"), { output: { entity: "store_import" }, effects: LOCAL_WRITE })
|
|
102
|
+
.summary("load made-up chats, people and messages from a file into a test or sandbox store")
|
|
103
|
+
.description('load a JSON file marked "synthetic": true (account, people, chats, members, messages) into this profile\'s ' +
|
|
104
|
+
"account in the local store, as a sync would save them; the same file twice adds nothing and a changed " +
|
|
105
|
+
"message is updated in place. Refuses the owner's real store. Without --yes, says what it would load and " +
|
|
106
|
+
"changes nothing")
|
|
107
|
+
.argument("<file>", "the JSON file to load")
|
|
108
|
+
.action(async function (path) {
|
|
109
|
+
const context = messengerContext(this, messenger);
|
|
110
|
+
const { profile, env } = context;
|
|
111
|
+
const { command } = messenger.app;
|
|
112
|
+
const file = readImport(path);
|
|
113
|
+
const target = storePath(env);
|
|
114
|
+
refuseOwnerFolders(messenger, profile, env, target);
|
|
115
|
+
if (!context.settings.profilesHere.includes(profile))
|
|
116
|
+
throw new CliError("not_found", `no profile named "${profile}" — make it first with \`${command} ${profile} config set …\``);
|
|
117
|
+
const key = { provider: messenger.provider, account: file.account.id };
|
|
118
|
+
const remembered = recalledAccount(messenger.app, messenger.provider, profile, env);
|
|
119
|
+
if (remembered && remembered.account !== key.account)
|
|
120
|
+
throw new CliError("validation_error", `profile ${profile} is account ${remembered.account}, and ${path} is account ${key.account} — ` +
|
|
121
|
+
"import it into a profile of its own");
|
|
122
|
+
const messages = messagesOf(file);
|
|
123
|
+
const chats = chatsOf(file, messages);
|
|
124
|
+
const people = [...file.people, ...Object.values(file.members).flat()];
|
|
125
|
+
// Over MCP an `ask` write goes ahead (NEED-773): nobody is there to add --yes.
|
|
126
|
+
const yes = this.optsWithGlobals().yes === true || context.agent;
|
|
127
|
+
const planned = {
|
|
128
|
+
store: target,
|
|
129
|
+
profile,
|
|
130
|
+
account: key.account,
|
|
131
|
+
file: { chats: chats.length, people: new Set(people.map((one) => one.id)).size, messages: messages.length },
|
|
132
|
+
};
|
|
133
|
+
if (!yes) {
|
|
134
|
+
context.renderer.note(`would load ${messages.length} messages in ${chats.length} chats into ${target} as profile ${profile} ` +
|
|
135
|
+
`(account ${key.account}); nothing changed — add --yes to load them`);
|
|
136
|
+
renderAnswer(this, context, itemOf(snakeKeys({ ...planned, imported: false })));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const answer = await context.run(async () => {
|
|
140
|
+
const store = await openStore({ env, command, version: messenger.app.version });
|
|
141
|
+
try {
|
|
142
|
+
const mapped = (await store.accounts.profiles())[command]?.[profile];
|
|
143
|
+
if (mapped && (mapped.provider !== key.provider || mapped.account !== key.account))
|
|
144
|
+
throw new CliError("validation_error", `the store has profile ${profile} as account ${mapped.account}, and ${path} is account ` +
|
|
145
|
+
`${key.account} — import it into a profile of its own`);
|
|
146
|
+
const before = await heldCounts(store, key);
|
|
147
|
+
await store.accounts.saveAccount(key, { name: file.account.name });
|
|
148
|
+
await store.accounts.saveProfile(command, profile, key);
|
|
149
|
+
rememberAccount(messenger.app, profile, key.account, env);
|
|
150
|
+
await store.people.savePeople(key, [file.account, ...people]);
|
|
151
|
+
await fill(store, key, { chats, messages });
|
|
152
|
+
for (const [chatId, members] of Object.entries(file.members))
|
|
153
|
+
await store.roster.saveMembers(key, chatId, members.map((member) => member.id));
|
|
154
|
+
const after = await heldCounts(store, key);
|
|
155
|
+
return {
|
|
156
|
+
...planned,
|
|
157
|
+
imported: true,
|
|
158
|
+
added: { chats: after.chats - before.chats, messages: after.messages - before.messages },
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
await store.close();
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
renderAnswer(this, context, itemOf(snakeKeys(answer)));
|
|
166
|
+
}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Id } from "../../domain/models.js";
|
|
2
|
-
import { type MessengerAdapter } from "../../ports/messenger.js";
|
|
2
|
+
import { type HistoryBatch, type MessengerAdapter } from "../../ports/messenger.js";
|
|
3
3
|
import type { MessengerTraits } from "../../ports/traits.js";
|
|
4
4
|
import type { EventSink, Warn } from "../../runs/events.js";
|
|
5
5
|
import { type HistoryLimits } from "../../services/history-limits.js";
|
|
@@ -56,3 +56,9 @@ export interface Saving {
|
|
|
56
56
|
* known to be whole, and `saveMembers` replaces the list.
|
|
57
57
|
*/
|
|
58
58
|
export declare const stored: (messenger: MessengerAdapter, { account, store, warn, events, pending, announcing, deletedWithoutChat, profile, rekeyed, rekeyPacing, closing, namesFromStore, recipientIds, countsUnread, historyLimits, command, }: Saving) => MessengerAdapter;
|
|
59
|
+
/**
|
|
60
|
+
* A pushed batch as the store keeps it. No `markChatsLeft`: a push names some chats, never all of them.
|
|
61
|
+
* No `seenAt`: a pushed snapshot may be older than a deletion this store already holds. A chat's votes and stars go
|
|
62
|
+
* in the transaction of its messages, after them, so a message in the batch is held, or known deleted, before them.
|
|
63
|
+
*/
|
|
64
|
+
export declare const fill: (store: MessageStore, account: AccountKey, batch: HistoryBatch) => Promise<void>;
|
|
@@ -606,7 +606,7 @@ const onlyRekeys = (batch) => Object.entries(batch).every(([part, items]) => (pa
|
|
|
606
606
|
* No `seenAt`: a pushed snapshot may be older than a deletion this store already holds. A chat's votes and stars go
|
|
607
607
|
* in the transaction of its messages, after them, so a message in the batch is held, or known deleted, before them.
|
|
608
608
|
*/
|
|
609
|
-
const fill = async (store, account, batch) => {
|
|
609
|
+
export const fill = async (store, account, batch) => {
|
|
610
610
|
if (batch.chats?.length)
|
|
611
611
|
await store.chats.saveChats(account, batch.chats);
|
|
612
612
|
if (batch.people?.length)
|
package/dist/entities/index.d.ts
CHANGED
|
@@ -76,7 +76,7 @@ import { responseTimes, waitingChats } from "./reply-stats.js";
|
|
|
76
76
|
import { retention } from "./retention.js";
|
|
77
77
|
import { savedSearch, searchHistoryClear } from "./saved-search.js";
|
|
78
78
|
import { sendAttempt } from "./send-attempt.js";
|
|
79
|
-
import { storeBackup, storeCheck, storeCopyRemoval, storeDecrypt, storeInfo, storeMigration, storeReindex, storeRepair, storeReset, storeRestore } from "./store-maintenance.js";
|
|
79
|
+
import { storeBackup, storeCheck, storeCopyRemoval, storeDecrypt, storeImport, storeInfo, storeMigration, storeReindex, storeRepair, storeReset, storeRestore } from "./store-maintenance.js";
|
|
80
80
|
import { chatCoverage, storeChatStatus, storeClear, storeExport, storeGapPlan, storeGapRepair, storeJobCancel, storeJobClear, storeJobDetails, storeJobRetry } from "./store-records.js";
|
|
81
81
|
import { storeTable } from "./store-table.js";
|
|
82
82
|
import { automaticTags, tagChange } from "./tag-change.js";
|
|
@@ -91,7 +91,7 @@ import { topic } from "./topic.js";
|
|
|
91
91
|
* subset of its fields, never a renamed one. Commands move onto these one by one; until then, a schema
|
|
92
92
|
* is the target, not a description of today's output.
|
|
93
93
|
*/
|
|
94
|
-
export { account, accountChange, accountPrivacy, accountPrivacyChange, accountProfile, accountSession, adminReport, agenda, analysisConsent, analysisConsentRevocation, attachment, attachmentBytes, attachmentExtraction, attachmentTextChange, automaticTags, botAdmin, botMenuEntry, botProfile, botSeenChat, botTemplate, botWebhook, cachedChatMetadata, callRecord, chart, chat, chatAdminChange, chatArchive, chatCoverage, chatEvent, chatFolderChange, chatFolderOrder, chatFolderRemoval, chatGroupChange, chatInspection, chatInvite, chatInviteChange, chatMembersChange, chatMembersFetch, chatMetadata, chatMetadataRefresh, chatModeration, chatMuting, chatPin, chatRead, chatRemoval, chatRequestChange, chatRules, chatSender, chatStats, chatTracking, chatUnread, contact, contactActivity, contactAlias, contactCheck, contactContext, contactImport, contactLookup, contactNote, contactNoteRemoval, contactPreparation, contactStateChange, contactSync, contactUpdate, conversation, conversationBatch, conversationBatchStatus, conversationBuildResult, conversationChange, conversationDetails, conversationEmbedding, conversationEmbeddingStatus, conversationHit, conversationPreparation, conversationReadiness, counterRefresh, counters, document, documentLink, endedAccountSessions, evidence, evidencePacket, fact, folder, hit, identity, imageEmbedding, inviteLink, job, joinRequest, linkedPerson, mailCounts, mediaArchive, mediaArchiveCheck, mediaArchiveMove, mediaArchiveTimer, meeting, meetingProjectCandidates, meetingSeriesInventory, member, memory, mention, mentionDecision, mentionDetails, mentionDomain, mentionRebuild, message, messageContext, messageCounts, messageDeletion, messageDownload, messageEvent, messageLink, messageLinks, messagePin, messageStar, messageSync, messageTranscript, messageWrite, model, modelKey, note, officialStats, organization, person, place, poll, pollChange, pollVote, project, ranking, reaction, reactionChange, recipient, recipientAdded, recipientChange, recipientOff, recipientRemoved, recordedRun, reference, relationship, reminder, removedModelKey, responseTimes, retention, runDetails, runHit, runLocation, savedSearch, scheduledJob, searchHistoryClear, sendAttempt, serveSummary, stickerInventory, storeBackup, storeChatStatus, storeCheck, storeClear, storeCopyRemoval, storeDecrypt, storedModelKey, storeExport, storeGapPlan, storeGapRepair, storeInfo, storeJobCancel, storeJobClear, storeJobDetails, storeJobRetry, storeMigration, storeReindex, storeRepair, storeReset, storeRestore, storeTable, tagChange, tagging, task, taskAnalysis, taskAnalysisMark, taskCard, taskCategories, taskClosed, taskCreated, taskLinks, taskMerge, taskPair, taskScan, taskSimilar, taskStats, taskUnmerge, template, topic, topicIcon, trackedChat, trackedChatHistory, waitingChats, watchedMessage, watchItem, };
|
|
94
|
+
export { account, accountChange, accountPrivacy, accountPrivacyChange, accountProfile, accountSession, adminReport, agenda, analysisConsent, analysisConsentRevocation, attachment, attachmentBytes, attachmentExtraction, attachmentTextChange, automaticTags, botAdmin, botMenuEntry, botProfile, botSeenChat, botTemplate, botWebhook, cachedChatMetadata, callRecord, chart, chat, chatAdminChange, chatArchive, chatCoverage, chatEvent, chatFolderChange, chatFolderOrder, chatFolderRemoval, chatGroupChange, chatInspection, chatInvite, chatInviteChange, chatMembersChange, chatMembersFetch, chatMetadata, chatMetadataRefresh, chatModeration, chatMuting, chatPin, chatRead, chatRemoval, chatRequestChange, chatRules, chatSender, chatStats, chatTracking, chatUnread, contact, contactActivity, contactAlias, contactCheck, contactContext, contactImport, contactLookup, contactNote, contactNoteRemoval, contactPreparation, contactStateChange, contactSync, contactUpdate, conversation, conversationBatch, conversationBatchStatus, conversationBuildResult, conversationChange, conversationDetails, conversationEmbedding, conversationEmbeddingStatus, conversationHit, conversationPreparation, conversationReadiness, counterRefresh, counters, document, documentLink, endedAccountSessions, evidence, evidencePacket, fact, folder, hit, identity, imageEmbedding, inviteLink, job, joinRequest, linkedPerson, mailCounts, mediaArchive, mediaArchiveCheck, mediaArchiveMove, mediaArchiveTimer, meeting, meetingProjectCandidates, meetingSeriesInventory, member, memory, mention, mentionDecision, mentionDetails, mentionDomain, mentionRebuild, message, messageContext, messageCounts, messageDeletion, messageDownload, messageEvent, messageLink, messageLinks, messagePin, messageStar, messageSync, messageTranscript, messageWrite, model, modelKey, note, officialStats, organization, person, place, poll, pollChange, pollVote, project, ranking, reaction, reactionChange, recipient, recipientAdded, recipientChange, recipientOff, recipientRemoved, recordedRun, reference, relationship, reminder, removedModelKey, responseTimes, retention, runDetails, runHit, runLocation, savedSearch, scheduledJob, searchHistoryClear, sendAttempt, serveSummary, stickerInventory, storeBackup, storeChatStatus, storeCheck, storeClear, storeCopyRemoval, storeDecrypt, storedModelKey, storeExport, storeGapPlan, storeGapRepair, storeImport, storeInfo, storeJobCancel, storeJobClear, storeJobDetails, storeJobRetry, storeMigration, storeReindex, storeRepair, storeReset, storeRestore, storeTable, tagChange, tagging, task, taskAnalysis, taskAnalysisMark, taskCard, taskCategories, taskClosed, taskCreated, taskLinks, taskMerge, taskPair, taskScan, taskSimilar, taskStats, taskUnmerge, template, topic, topicIcon, trackedChat, trackedChatHistory, waitingChats, watchedMessage, watchItem, };
|
|
95
95
|
export declare const ENTITIES: {
|
|
96
96
|
readonly meeting_ingestion: v.StrictObjectSchema<{
|
|
97
97
|
readonly meetings: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
@@ -9851,6 +9851,21 @@ export declare const ENTITIES: {
|
|
|
9851
9851
|
}, undefined>, undefined>;
|
|
9852
9852
|
readonly schema: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
9853
9853
|
}, undefined>], undefined>;
|
|
9854
|
+
readonly store_import: v.StrictObjectSchema<{
|
|
9855
|
+
readonly store: v.StringSchema<undefined>;
|
|
9856
|
+
readonly profile: v.StringSchema<undefined>;
|
|
9857
|
+
readonly account: v.StringSchema<undefined>;
|
|
9858
|
+
readonly imported: v.BooleanSchema<undefined>;
|
|
9859
|
+
readonly file: v.StrictObjectSchema<{
|
|
9860
|
+
readonly chats: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
9861
|
+
readonly people: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
9862
|
+
readonly messages: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
9863
|
+
}, undefined>;
|
|
9864
|
+
readonly added: v.OptionalSchema<v.StrictObjectSchema<{
|
|
9865
|
+
readonly chats: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
9866
|
+
readonly messages: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
9867
|
+
}, undefined>, undefined>;
|
|
9868
|
+
}, undefined>;
|
|
9854
9869
|
readonly store_repair: v.UnionSchema<[v.StrictObjectSchema<{
|
|
9855
9870
|
readonly path: v.StringSchema<undefined>;
|
|
9856
9871
|
readonly exists: v.LiteralSchema<false, undefined>;
|
package/dist/entities/index.js
CHANGED
|
@@ -85,7 +85,7 @@ import { responseTimes, waitingChats } from "./reply-stats.js";
|
|
|
85
85
|
import { retention } from "./retention.js";
|
|
86
86
|
import { savedSearch, searchHistoryClear } from "./saved-search.js";
|
|
87
87
|
import { sendAttempt } from "./send-attempt.js";
|
|
88
|
-
import { storeBackup, storeCheck, storeCopyRemoval, storeDecrypt, storeInfo, storeMigration, storeReindex, storeRepair, storeReset, storeRestore, } from "./store-maintenance.js";
|
|
88
|
+
import { storeBackup, storeCheck, storeCopyRemoval, storeDecrypt, storeImport, storeInfo, storeMigration, storeReindex, storeRepair, storeReset, storeRestore, } from "./store-maintenance.js";
|
|
89
89
|
import { chatCoverage, storeChatStatus, storeClear, storeExport, storeGapPlan, storeGapRepair, storeJobCancel, storeJobClear, storeJobDetails, storeJobRetry, syncProgress, } from "./store-records.js";
|
|
90
90
|
import { storeTable } from "./store-table.js";
|
|
91
91
|
import { automaticTags, tagChange } from "./tag-change.js";
|
|
@@ -100,7 +100,7 @@ import { topic } from "./topic.js";
|
|
|
100
100
|
* subset of its fields, never a renamed one. Commands move onto these one by one; until then, a schema
|
|
101
101
|
* is the target, not a description of today's output.
|
|
102
102
|
*/
|
|
103
|
-
export { account, accountChange, accountPrivacy, accountPrivacyChange, accountProfile, accountSession, adminReport, agenda, analysisConsent, analysisConsentRevocation, attachment, attachmentBytes, attachmentExtraction, attachmentTextChange, automaticTags, botAdmin, botMenuEntry, botProfile, botSeenChat, botTemplate, botWebhook, cachedChatMetadata, callRecord, chart, chat, chatAdminChange, chatArchive, chatCoverage, chatEvent, chatFolderChange, chatFolderOrder, chatFolderRemoval, chatGroupChange, chatInspection, chatInvite, chatInviteChange, chatMembersChange, chatMembersFetch, chatMetadata, chatMetadataRefresh, chatModeration, chatMuting, chatPin, chatRead, chatRemoval, chatRequestChange, chatRules, chatSender, chatStats, chatTracking, chatUnread, contact, contactActivity, contactAlias, contactCheck, contactContext, contactImport, contactLookup, contactNote, contactNoteRemoval, contactPreparation, contactStateChange, contactSync, contactUpdate, conversation, conversationBatch, conversationBatchStatus, conversationBuildResult, conversationChange, conversationDetails, conversationEmbedding, conversationEmbeddingStatus, conversationHit, conversationPreparation, conversationReadiness, counterRefresh, counters, document, documentLink, endedAccountSessions, evidence, evidencePacket, fact, folder, hit, identity, imageEmbedding, inviteLink, job, joinRequest, linkedPerson, mailCounts, mediaArchive, mediaArchiveCheck, mediaArchiveMove, mediaArchiveTimer, meeting, meetingProjectCandidates, meetingSeriesInventory, member, memory, mention, mentionDecision, mentionDetails, mentionDomain, mentionRebuild, message, messageContext, messageCounts, messageDeletion, messageDownload, messageEvent, messageLink, messageLinks, messagePin, messageStar, messageSync, messageTranscript, messageWrite, model, modelKey, note, officialStats, organization, person, place, poll, pollChange, pollVote, project, ranking, reaction, reactionChange, recipient, recipientAdded, recipientChange, recipientOff, recipientRemoved, recordedRun, reference, relationship, reminder, removedModelKey, responseTimes, retention, runDetails, runHit, runLocation, savedSearch, scheduledJob, searchHistoryClear, sendAttempt, serveSummary, stickerInventory, storeBackup, storeChatStatus, storeCheck, storeClear, storeCopyRemoval, storeDecrypt, storedModelKey, storeExport, storeGapPlan, storeGapRepair, storeInfo, storeJobCancel, storeJobClear, storeJobDetails, storeJobRetry, storeMigration, storeReindex, storeRepair, storeReset, storeRestore, storeTable, tagChange, tagging, task, taskAnalysis, taskAnalysisMark, taskCard, taskCategories, taskClosed, taskCreated, taskLinks, taskMerge, taskPair, taskScan, taskSimilar, taskStats, taskUnmerge, template, topic, topicIcon, trackedChat, trackedChatHistory, waitingChats, watchedMessage, watchItem, };
|
|
103
|
+
export { account, accountChange, accountPrivacy, accountPrivacyChange, accountProfile, accountSession, adminReport, agenda, analysisConsent, analysisConsentRevocation, attachment, attachmentBytes, attachmentExtraction, attachmentTextChange, automaticTags, botAdmin, botMenuEntry, botProfile, botSeenChat, botTemplate, botWebhook, cachedChatMetadata, callRecord, chart, chat, chatAdminChange, chatArchive, chatCoverage, chatEvent, chatFolderChange, chatFolderOrder, chatFolderRemoval, chatGroupChange, chatInspection, chatInvite, chatInviteChange, chatMembersChange, chatMembersFetch, chatMetadata, chatMetadataRefresh, chatModeration, chatMuting, chatPin, chatRead, chatRemoval, chatRequestChange, chatRules, chatSender, chatStats, chatTracking, chatUnread, contact, contactActivity, contactAlias, contactCheck, contactContext, contactImport, contactLookup, contactNote, contactNoteRemoval, contactPreparation, contactStateChange, contactSync, contactUpdate, conversation, conversationBatch, conversationBatchStatus, conversationBuildResult, conversationChange, conversationDetails, conversationEmbedding, conversationEmbeddingStatus, conversationHit, conversationPreparation, conversationReadiness, counterRefresh, counters, document, documentLink, endedAccountSessions, evidence, evidencePacket, fact, folder, hit, identity, imageEmbedding, inviteLink, job, joinRequest, linkedPerson, mailCounts, mediaArchive, mediaArchiveCheck, mediaArchiveMove, mediaArchiveTimer, meeting, meetingProjectCandidates, meetingSeriesInventory, member, memory, mention, mentionDecision, mentionDetails, mentionDomain, mentionRebuild, message, messageContext, messageCounts, messageDeletion, messageDownload, messageEvent, messageLink, messageLinks, messagePin, messageStar, messageSync, messageTranscript, messageWrite, model, modelKey, note, officialStats, organization, person, place, poll, pollChange, pollVote, project, ranking, reaction, reactionChange, recipient, recipientAdded, recipientChange, recipientOff, recipientRemoved, recordedRun, reference, relationship, reminder, removedModelKey, responseTimes, retention, runDetails, runHit, runLocation, savedSearch, scheduledJob, searchHistoryClear, sendAttempt, serveSummary, stickerInventory, storeBackup, storeChatStatus, storeCheck, storeClear, storeCopyRemoval, storeDecrypt, storedModelKey, storeExport, storeGapPlan, storeGapRepair, storeImport, storeInfo, storeJobCancel, storeJobClear, storeJobDetails, storeJobRetry, storeMigration, storeReindex, storeRepair, storeReset, storeRestore, storeTable, tagChange, tagging, task, taskAnalysis, taskAnalysisMark, taskCard, taskCategories, taskClosed, taskCreated, taskLinks, taskMerge, taskPair, taskScan, taskSimilar, taskStats, taskUnmerge, template, topic, topicIcon, trackedChat, trackedChatHistory, waitingChats, watchedMessage, watchItem, };
|
|
104
104
|
export const ENTITIES = {
|
|
105
105
|
sync_progress: syncProgress,
|
|
106
106
|
deal,
|
|
@@ -327,6 +327,7 @@ export const ENTITIES = {
|
|
|
327
327
|
store_decrypt: storeDecrypt,
|
|
328
328
|
store_restore: storeRestore,
|
|
329
329
|
store_reset: storeReset,
|
|
330
|
+
store_import: storeImport,
|
|
330
331
|
store_repair: storeRepair,
|
|
331
332
|
store_copy_removal: storeCopyRemoval,
|
|
332
333
|
store_table: storeTable,
|
|
@@ -362,6 +362,22 @@ export declare const storeRestore: v.UnionSchema<[v.StrictObjectSchema<{
|
|
|
362
362
|
readonly rebuilt: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
363
363
|
readonly foreign_key_violations: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
364
364
|
}, undefined>], undefined>;
|
|
365
|
+
/** Made-up data for a test store: what the file holds and, once loaded, what it added to the account. */
|
|
366
|
+
export declare const storeImport: v.StrictObjectSchema<{
|
|
367
|
+
readonly store: v.StringSchema<undefined>;
|
|
368
|
+
readonly profile: v.StringSchema<undefined>;
|
|
369
|
+
readonly account: v.StringSchema<undefined>;
|
|
370
|
+
readonly imported: v.BooleanSchema<undefined>;
|
|
371
|
+
readonly file: v.StrictObjectSchema<{
|
|
372
|
+
readonly chats: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
373
|
+
readonly people: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
374
|
+
readonly messages: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
375
|
+
}, undefined>;
|
|
376
|
+
readonly added: v.OptionalSchema<v.StrictObjectSchema<{
|
|
377
|
+
readonly chats: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
378
|
+
readonly messages: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
379
|
+
}, undefined>, undefined>;
|
|
380
|
+
}, undefined>;
|
|
365
381
|
export declare const storeReset: v.UnionSchema<[v.StrictObjectSchema<{
|
|
366
382
|
readonly path: v.StringSchema<undefined>;
|
|
367
383
|
readonly exists: v.LiteralSchema<false, undefined>;
|
|
@@ -174,6 +174,16 @@ export const storeRestore = v.union([
|
|
|
174
174
|
foreign_key_violations: count,
|
|
175
175
|
}),
|
|
176
176
|
]);
|
|
177
|
+
const importCounts = v.strictObject({ chats: count, messages: count });
|
|
178
|
+
/** Made-up data for a test store: what the file holds and, once loaded, what it added to the account. */
|
|
179
|
+
export const storeImport = v.strictObject({
|
|
180
|
+
store: text,
|
|
181
|
+
profile: text,
|
|
182
|
+
account: text,
|
|
183
|
+
imported: v.boolean(),
|
|
184
|
+
file: v.strictObject({ chats: count, people: count, messages: count }),
|
|
185
|
+
added: v.optional(importCounts),
|
|
186
|
+
});
|
|
177
187
|
export const storeReset = v.union([
|
|
178
188
|
v.strictObject({ ...absent.entries, reset: v.literal(false) }),
|
|
179
189
|
v.strictObject({
|
package/dist/store/path.d.ts
CHANGED
|
@@ -6,5 +6,8 @@ export declare const wirecatDirectory: (env?: NodeJS.ProcessEnv, platform?: Node
|
|
|
6
6
|
* before this one: a build still installed would open that name and run its own migrations over these tables.
|
|
7
7
|
*/
|
|
8
8
|
export declare const storePath: (env?: NodeJS.ProcessEnv) => string;
|
|
9
|
+
export declare const accountHome: () => string | undefined;
|
|
10
|
+
/** Whether `file` is in the owner's real WireCat folder, whatever HOME or MESSAGING_STORE this process was given. */
|
|
11
|
+
export declare const inOwnerFolder: (file: string, home?: string | undefined) => boolean;
|
|
9
12
|
/** Throws when a test is about to open a file in the owner's real WireCat folder. */
|
|
10
13
|
export declare const refuseOwnerStoreInTests: (file: string, env?: NodeJS.ProcessEnv, home?: string | undefined) => void;
|
package/dist/store/path.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
1
2
|
import { userInfo } from "node:os";
|
|
2
|
-
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
3
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
3
4
|
import { resolvePaths } from "@wirecat/cli-base";
|
|
4
5
|
/** The folder the CLIs share: the store, its backups and the models. `WIRECAT_STATE_DIR` moves all of it. */
|
|
5
6
|
export const wirecatDirectory = (env = process.env, platform) => resolvePaths({ appName: "WireCat", prefix: "WIRECAT", env, ...(platform ? { platform } : {}) }).state;
|
|
@@ -11,7 +12,7 @@ export const wirecatDirectory = (env = process.env, platform) => resolvePaths({
|
|
|
11
12
|
export const storePath = (env = process.env) => env.MESSAGING_STORE ?? join(wirecatDirectory(env), "wirecat.db");
|
|
12
13
|
// The account's home from the user database, not HOME: the test sandbox moves HOME, and a worker thread's
|
|
13
14
|
// `os.homedir()` still answers the real one (the 2026-10-18 leak).
|
|
14
|
-
const accountHome = () => {
|
|
15
|
+
export const accountHome = () => {
|
|
15
16
|
try {
|
|
16
17
|
return userInfo().homedir;
|
|
17
18
|
}
|
|
@@ -19,12 +20,30 @@ const accountHome = () => {
|
|
|
19
20
|
return undefined;
|
|
20
21
|
}
|
|
21
22
|
};
|
|
23
|
+
/** Whether `file` is in the owner's real WireCat folder, whatever HOME or MESSAGING_STORE this process was given. */
|
|
24
|
+
export const inOwnerFolder = (file, home = accountHome()) => {
|
|
25
|
+
if (!home || file === ":memory:")
|
|
26
|
+
return false;
|
|
27
|
+
const owner = wirecatDirectory({ HOME: home, USERPROFILE: home });
|
|
28
|
+
const within = (path, folder) => {
|
|
29
|
+
const inside = relative(folder, path);
|
|
30
|
+
return !(inside.startsWith("..") || isAbsolute(inside));
|
|
31
|
+
};
|
|
32
|
+
return within(resolve(file), owner) || within(settled(resolve(file)), settled(owner));
|
|
33
|
+
};
|
|
34
|
+
/** The path with every link in its existing part followed, so a link into the owner's folder is seen as one. */
|
|
35
|
+
const settled = (path) => {
|
|
36
|
+
try {
|
|
37
|
+
return realpathSync(path);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
const parent = dirname(path);
|
|
41
|
+
return parent === path ? path : join(settled(parent), basename(path));
|
|
42
|
+
}
|
|
43
|
+
};
|
|
22
44
|
/** Throws when a test is about to open a file in the owner's real WireCat folder. */
|
|
23
45
|
export const refuseOwnerStoreInTests = (file, env = process.env, home = accountHome()) => {
|
|
24
|
-
if (!env.VITEST || !
|
|
25
|
-
return;
|
|
26
|
-
const inside = relative(wirecatDirectory({ HOME: home, USERPROFILE: home }), resolve(file));
|
|
27
|
-
if (inside.startsWith("..") || isAbsolute(inside))
|
|
46
|
+
if (!env.VITEST || !inOwnerFolder(file, home))
|
|
28
47
|
return;
|
|
29
48
|
throw new Error(`a test tried to open ${file}, in the owner's real WireCat folder; give it a MESSAGING_STORE or HOME of its own`);
|
|
30
49
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.633.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",
|