@wirecat/cli-core 0.613.0 → 0.615.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/background/report/render.d.ts +18 -4
  3. package/dist/background/report/render.js +59 -18
  4. package/dist/background/report/stored-templates.d.ts +64 -0
  5. package/dist/background/report/stored-templates.js +80 -0
  6. package/dist/background/report/templates/morning-digest.sample.json +150 -0
  7. package/dist/background/schedules.d.ts +4 -2
  8. package/dist/background/schedules.js +2 -1
  9. package/dist/calendar/mcp/index.d.ts +12 -12
  10. package/dist/cli/account-remove.d.ts +67 -0
  11. package/dist/cli/account-remove.js +285 -0
  12. package/dist/cli/index.d.ts +3 -1
  13. package/dist/cli/index.js +2 -1
  14. package/dist/cli/messenger/account-command.js +6 -0
  15. package/dist/cli/messenger/context.d.ts +2 -0
  16. package/dist/cli/messenger/serve-relay.d.ts +1 -0
  17. package/dist/cli/profile-files.d.ts +7 -0
  18. package/dist/cli/profile-files.js +43 -0
  19. package/dist/cli/schedule/schedule-command.d.ts +2 -0
  20. package/dist/cli/schedule/schedule-command.js +20 -2
  21. package/dist/cli/shared-command-exports.d.ts +1 -0
  22. package/dist/cli/shared-command-exports.js +2 -0
  23. package/dist/cli/templates-command.d.ts +16 -0
  24. package/dist/cli/templates-command.js +243 -0
  25. package/dist/entities/account-change.d.ts +20 -0
  26. package/dist/entities/account-change.js +12 -1
  27. package/dist/entities/index.d.ts +20 -0
  28. package/dist/entities/index.js +2 -1
  29. package/dist/errors/reasons.js +17 -0
  30. package/dist/services/metadata.d.ts +1 -1
  31. package/dist/store/accounts.d.ts +2 -0
  32. package/dist/store/accounts.js +2 -1
  33. package/dist/store/exports.d.ts +1 -0
  34. package/dist/store/exports.js +1 -0
  35. package/dist/store/index.d.ts +1 -0
  36. package/dist/store/sqlite/account-groups.d.ts +1 -0
  37. package/dist/store/sqlite/account-groups.js +14 -0
  38. package/dist/store/sqlite/manifest.js +1 -0
  39. package/dist/store/sqlite/migrations.generated.js +8 -0
  40. package/dist/store/sqlite/schema/templates.d.ts +242 -0
  41. package/dist/store/sqlite/schema/templates.js +23 -0
  42. package/dist/store/sqlite/schema.d.ts +1 -0
  43. package/dist/store/sqlite/schema.js +1 -0
  44. package/dist/store/sqlite/templates.d.ts +38 -0
  45. package/dist/store/sqlite/templates.js +69 -0
  46. package/dist/store/store.d.ts +3 -0
  47. package/dist/store/store.js +5 -0
  48. package/package.json +4 -4
@@ -0,0 +1,242 @@
1
+ /** A template the owner saved over the shipped one, per key, channel and language. */
2
+ export declare const templates: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
3
+ name: "templates";
4
+ schema: undefined;
5
+ columns: {
6
+ key: import("drizzle-orm/sqlite-core").SQLiteColumn<{
7
+ name: string;
8
+ tableName: "templates";
9
+ dataType: "string";
10
+ data: string;
11
+ driverParam: string;
12
+ notNull: true;
13
+ hasDefault: false;
14
+ isPrimaryKey: false;
15
+ isAutoincrement: false;
16
+ hasRuntimeDefault: false;
17
+ enumValues: [string, ...string[]];
18
+ baseColumn: never;
19
+ identity: undefined;
20
+ generated: undefined;
21
+ }, {}>;
22
+ channel: import("drizzle-orm/sqlite-core").SQLiteColumn<{
23
+ name: string;
24
+ tableName: "templates";
25
+ dataType: "string";
26
+ data: string;
27
+ driverParam: string;
28
+ notNull: true;
29
+ hasDefault: false;
30
+ isPrimaryKey: false;
31
+ isAutoincrement: false;
32
+ hasRuntimeDefault: false;
33
+ enumValues: [string, ...string[]];
34
+ baseColumn: never;
35
+ identity: undefined;
36
+ generated: undefined;
37
+ }, {}>;
38
+ language: import("drizzle-orm/sqlite-core").SQLiteColumn<{
39
+ name: string;
40
+ tableName: "templates";
41
+ dataType: "string";
42
+ data: string;
43
+ driverParam: string;
44
+ notNull: true;
45
+ hasDefault: false;
46
+ isPrimaryKey: false;
47
+ isAutoincrement: false;
48
+ hasRuntimeDefault: false;
49
+ enumValues: [string, ...string[]];
50
+ baseColumn: never;
51
+ identity: undefined;
52
+ generated: undefined;
53
+ }, {}>;
54
+ body: import("drizzle-orm/sqlite-core").SQLiteColumn<{
55
+ name: string;
56
+ tableName: "templates";
57
+ dataType: "string";
58
+ data: string;
59
+ driverParam: string;
60
+ notNull: true;
61
+ hasDefault: false;
62
+ isPrimaryKey: false;
63
+ isAutoincrement: false;
64
+ hasRuntimeDefault: false;
65
+ enumValues: [string, ...string[]];
66
+ baseColumn: never;
67
+ identity: undefined;
68
+ generated: undefined;
69
+ }, {}>;
70
+ updatedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
71
+ name: string;
72
+ tableName: "templates";
73
+ dataType: "number int53";
74
+ data: number;
75
+ driverParam: number;
76
+ notNull: true;
77
+ hasDefault: false;
78
+ isPrimaryKey: false;
79
+ isAutoincrement: false;
80
+ hasRuntimeDefault: false;
81
+ enumValues: undefined;
82
+ baseColumn: never;
83
+ identity: undefined;
84
+ generated: undefined;
85
+ }, {}>;
86
+ updatedBy: import("drizzle-orm/sqlite-core").SQLiteColumn<{
87
+ name: string;
88
+ tableName: "templates";
89
+ dataType: "string";
90
+ data: string;
91
+ driverParam: string;
92
+ notNull: true;
93
+ hasDefault: false;
94
+ isPrimaryKey: false;
95
+ isAutoincrement: false;
96
+ hasRuntimeDefault: false;
97
+ enumValues: [string, ...string[]];
98
+ baseColumn: never;
99
+ identity: undefined;
100
+ generated: undefined;
101
+ }, {}>;
102
+ };
103
+ dialect: 'sqlite';
104
+ isAlias: false;
105
+ }>;
106
+ /** Every body a save or a reset replaced. */
107
+ export declare const templatesHistory: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
108
+ name: "templates_history";
109
+ schema: undefined;
110
+ columns: {
111
+ id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
112
+ name: string;
113
+ tableName: "templates_history";
114
+ dataType: "number int53";
115
+ data: number;
116
+ driverParam: number;
117
+ notNull: true;
118
+ hasDefault: true;
119
+ isPrimaryKey: true;
120
+ isAutoincrement: false;
121
+ hasRuntimeDefault: false;
122
+ enumValues: undefined;
123
+ baseColumn: never;
124
+ identity: undefined;
125
+ generated: undefined;
126
+ }, {}>;
127
+ key: import("drizzle-orm/sqlite-core").SQLiteColumn<{
128
+ name: string;
129
+ tableName: "templates_history";
130
+ dataType: "string";
131
+ data: string;
132
+ driverParam: string;
133
+ notNull: true;
134
+ hasDefault: false;
135
+ isPrimaryKey: false;
136
+ isAutoincrement: false;
137
+ hasRuntimeDefault: false;
138
+ enumValues: [string, ...string[]];
139
+ baseColumn: never;
140
+ identity: undefined;
141
+ generated: undefined;
142
+ }, {}>;
143
+ channel: import("drizzle-orm/sqlite-core").SQLiteColumn<{
144
+ name: string;
145
+ tableName: "templates_history";
146
+ dataType: "string";
147
+ data: string;
148
+ driverParam: string;
149
+ notNull: true;
150
+ hasDefault: false;
151
+ isPrimaryKey: false;
152
+ isAutoincrement: false;
153
+ hasRuntimeDefault: false;
154
+ enumValues: [string, ...string[]];
155
+ baseColumn: never;
156
+ identity: undefined;
157
+ generated: undefined;
158
+ }, {}>;
159
+ language: import("drizzle-orm/sqlite-core").SQLiteColumn<{
160
+ name: string;
161
+ tableName: "templates_history";
162
+ dataType: "string";
163
+ data: string;
164
+ driverParam: string;
165
+ notNull: true;
166
+ hasDefault: false;
167
+ isPrimaryKey: false;
168
+ isAutoincrement: false;
169
+ hasRuntimeDefault: false;
170
+ enumValues: [string, ...string[]];
171
+ baseColumn: never;
172
+ identity: undefined;
173
+ generated: undefined;
174
+ }, {}>;
175
+ body: import("drizzle-orm/sqlite-core").SQLiteColumn<{
176
+ name: string;
177
+ tableName: "templates_history";
178
+ dataType: "string";
179
+ data: string;
180
+ driverParam: string;
181
+ notNull: true;
182
+ hasDefault: false;
183
+ isPrimaryKey: false;
184
+ isAutoincrement: false;
185
+ hasRuntimeDefault: false;
186
+ enumValues: [string, ...string[]];
187
+ baseColumn: never;
188
+ identity: undefined;
189
+ generated: undefined;
190
+ }, {}>;
191
+ savedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
192
+ name: string;
193
+ tableName: "templates_history";
194
+ dataType: "number int53";
195
+ data: number;
196
+ driverParam: number;
197
+ notNull: true;
198
+ hasDefault: false;
199
+ isPrimaryKey: false;
200
+ isAutoincrement: false;
201
+ hasRuntimeDefault: false;
202
+ enumValues: undefined;
203
+ baseColumn: never;
204
+ identity: undefined;
205
+ generated: undefined;
206
+ }, {}>;
207
+ savedBy: import("drizzle-orm/sqlite-core").SQLiteColumn<{
208
+ name: string;
209
+ tableName: "templates_history";
210
+ dataType: "string";
211
+ data: string;
212
+ driverParam: string;
213
+ notNull: true;
214
+ hasDefault: false;
215
+ isPrimaryKey: false;
216
+ isAutoincrement: false;
217
+ hasRuntimeDefault: false;
218
+ enumValues: [string, ...string[]];
219
+ baseColumn: never;
220
+ identity: undefined;
221
+ generated: undefined;
222
+ }, {}>;
223
+ replacedAt: import("drizzle-orm/sqlite-core").SQLiteColumn<{
224
+ name: string;
225
+ tableName: "templates_history";
226
+ dataType: "number int53";
227
+ data: number;
228
+ driverParam: number;
229
+ notNull: true;
230
+ hasDefault: false;
231
+ isPrimaryKey: false;
232
+ isAutoincrement: false;
233
+ hasRuntimeDefault: false;
234
+ enumValues: undefined;
235
+ baseColumn: never;
236
+ identity: undefined;
237
+ generated: undefined;
238
+ }, {}>;
239
+ };
240
+ dialect: 'sqlite';
241
+ isAlias: false;
242
+ }>;
@@ -0,0 +1,23 @@
1
+ import { index, integer, primaryKey, sqliteTable, text } from "../drizzle/core.js";
2
+ /** A template the owner saved over the shipped one, per key, channel and language. */
3
+ export const templates = sqliteTable("templates", {
4
+ key: text("key").notNull(),
5
+ channel: text("channel").notNull(),
6
+ language: text("language").notNull(),
7
+ body: text("body").notNull(),
8
+ updatedAt: integer("updated_at").notNull(),
9
+ updatedBy: text("updated_by").notNull(),
10
+ }, (table) => [primaryKey({ columns: [table.key, table.channel, table.language] })]);
11
+ /** Every body a save or a reset replaced. */
12
+ export const templatesHistory = sqliteTable("templates_history", {
13
+ id: integer("id").primaryKey(),
14
+ key: text("key").notNull(),
15
+ channel: text("channel").notNull(),
16
+ language: text("language").notNull(),
17
+ body: text("body").notNull(),
18
+ savedAt: integer("saved_at").notNull(),
19
+ savedBy: text("saved_by").notNull(),
20
+ replacedAt: integer("replaced_at").notNull(),
21
+ }, (table) => [
22
+ index("templates_history_by_key_channel_language_id").on(table.key, table.channel, table.language, table.id),
23
+ ]);
@@ -19487,6 +19487,7 @@ export declare const transactionSplits: import("drizzle-orm/sqlite-core").SQLite
19487
19487
  }>;
19488
19488
  export { decisionRequests } from "./schema/decision-requests.js";
19489
19489
  export { enrichments } from "./schema/enrichments.js";
19490
+ export { templates, templatesHistory } from "./schema/templates.js";
19490
19491
  /** What a source said about one of its records, as it said it: the layer under the entity an import makes. */
19491
19492
  export declare const records: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
19492
19493
  name: "records";
@@ -1934,6 +1934,7 @@ export const transactionSplits = sqliteTable("transaction_splits", {
1934
1934
  ]);
1935
1935
  export { decisionRequests } from "./schema/decision-requests.js";
1936
1936
  export { enrichments } from "./schema/enrichments.js";
1937
+ export { templates, templatesHistory } from "./schema/templates.js";
1937
1938
  /** What a source said about one of its records, as it said it: the layer under the entity an import makes. */
1938
1939
  export const records = sqliteTable("records", {
1939
1940
  id: integer("id").primaryKey(),
@@ -0,0 +1,38 @@
1
+ import type { CacheDatabase } from "../driver.js";
2
+ import type { StoreContext } from "./open.js";
3
+ /** Which template: `report/morning-digest`, `telegram`, `ru`. */
4
+ export interface TemplateAddress {
5
+ key: string;
6
+ channel: string;
7
+ language: string;
8
+ }
9
+ export interface StoredTemplate extends TemplateAddress {
10
+ body: string;
11
+ updatedAt: number;
12
+ updatedBy: string;
13
+ }
14
+ /** A body a save or a reset replaced. */
15
+ export interface TemplateHistoryEntry extends TemplateAddress {
16
+ id: number;
17
+ body: string;
18
+ savedAt: number;
19
+ savedBy: string;
20
+ replacedAt: number;
21
+ }
22
+ /** The owner's templates over the shipped ones. Nothing here checks a body: the caller does, before `save`. */
23
+ export interface TemplateStore {
24
+ list(): StoredTemplate[];
25
+ get(address: TemplateAddress): StoredTemplate | undefined;
26
+ /** Stores `body`, and keeps the body it replaces in the history. */
27
+ save(address: TemplateAddress, body: string, by: string): StoredTemplate;
28
+ /** Deletes the stored body, kept in the history, so the shipped one applies; false when there was none. */
29
+ reset(address: TemplateAddress): boolean;
30
+ /** Newest first. */
31
+ history(address: TemplateAddress, limit?: number): TemplateHistoryEntry[];
32
+ }
33
+ export declare const templateStoreOver: ({ database, now }: StoreContext) => TemplateStore;
34
+ /**
35
+ * The stored bodies of one key and language, by channel, read without migrating the file: a store older than the
36
+ * table has none.
37
+ */
38
+ export declare const storedTemplateBodies: (database: CacheDatabase, key: string, language: string) => Record<string, string>;
@@ -0,0 +1,69 @@
1
+ import { write } from "./transaction.js";
2
+ const templateOf = (row) => ({
3
+ key: row.key,
4
+ channel: row.channel,
5
+ language: row.language,
6
+ body: row.body,
7
+ updatedAt: row.updated_at,
8
+ updatedBy: row.updated_by,
9
+ });
10
+ const WHERE = "key = ? AND channel = ? AND language = ?";
11
+ const at = ({ key, channel, language }) => [key, channel, language];
12
+ export const templateStoreOver = ({ database, now }) => {
13
+ const get = (address) => {
14
+ const row = database.prepare(`SELECT * FROM templates WHERE ${WHERE}`).get(...at(address));
15
+ return row && templateOf(row);
16
+ };
17
+ const keep = (old, replacedAt) => database
18
+ .prepare("INSERT INTO templates_history (key, channel, language, body, saved_at, saved_by, replaced_at) " +
19
+ "VALUES (?, ?, ?, ?, ?, ?, ?)")
20
+ .run(...at(old), old.body, old.updatedAt, old.updatedBy, replacedAt);
21
+ return {
22
+ list: () => database.prepare("SELECT * FROM templates ORDER BY key, channel, language").all().map(templateOf),
23
+ get,
24
+ save: (address, body, by) => write(database, () => {
25
+ const time = now();
26
+ const old = get(address);
27
+ if (old)
28
+ keep(old, time);
29
+ database
30
+ .prepare("INSERT INTO templates (key, channel, language, body, updated_at, updated_by) VALUES (?, ?, ?, ?, ?, ?) " +
31
+ "ON CONFLICT (key, channel, language) DO UPDATE SET body = excluded.body, " +
32
+ "updated_at = excluded.updated_at, updated_by = excluded.updated_by")
33
+ .run(...at(address), body, time, by);
34
+ return { ...address, body, updatedAt: time, updatedBy: by };
35
+ }),
36
+ reset: (address) => write(database, () => {
37
+ const old = get(address);
38
+ if (!old)
39
+ return false;
40
+ keep(old, now());
41
+ database.prepare(`DELETE FROM templates WHERE ${WHERE}`).run(...at(address));
42
+ return true;
43
+ }),
44
+ history: (address, limit = 20) => database
45
+ .prepare(`SELECT * FROM templates_history WHERE ${WHERE} ORDER BY id DESC LIMIT ?`)
46
+ .all(...at(address), limit).map((row) => ({
47
+ id: row.id,
48
+ key: row.key,
49
+ channel: row.channel,
50
+ language: row.language,
51
+ body: row.body,
52
+ savedAt: row.saved_at,
53
+ savedBy: row.saved_by,
54
+ replacedAt: row.replaced_at,
55
+ })),
56
+ };
57
+ };
58
+ /**
59
+ * The stored bodies of one key and language, by channel, read without migrating the file: a store older than the
60
+ * table has none.
61
+ */
62
+ export const storedTemplateBodies = (database, key, language) => {
63
+ if (!database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'templates'").get())
64
+ return {};
65
+ const rows = database
66
+ .prepare("SELECT channel, body FROM templates WHERE key = ? AND language = ?")
67
+ .all(key, language);
68
+ return Object.fromEntries(rows.map((row) => [row.channel, row.body]));
69
+ };
@@ -49,6 +49,7 @@ import { type RecordStore } from "./sqlite/records.js";
49
49
  import { type RelationsStore } from "./sqlite/reported-relations.js";
50
50
  import { type SubscriptionsStore } from "./sqlite/subscriptions.js";
51
51
  import { type StoreTaskStore } from "./sqlite/tasks.js";
52
+ import { type TemplateStore } from "./sqlite/templates.js";
52
53
  import { type WalletsStore } from "./sqlite/wallets.js";
53
54
  import { type SyncStore } from "./sync.js";
54
55
  import { type TagsStore } from "./tags.js";
@@ -135,6 +136,8 @@ export interface MessageStore {
135
136
  readonly relations: RelationsStore;
136
137
  /** The one-time keys behind the buttons of a message that asks the owner to decide a batch. */
137
138
  readonly decisionRequests: DecisionRequestStore;
139
+ /** The message templates the owner saved over the shipped ones, with every body a change replaced. */
140
+ readonly templates: TemplateStore;
138
141
  /** What each import said, by the source's identity; `ingest` (services) is the way in. */
139
142
  readonly records: RecordStore;
140
143
  /** What agents concluded: summaries, digests, facts, preferences, each with evidence and a scope. */
@@ -55,6 +55,7 @@ import { relationsStoreOver } from "./sqlite/reported-relations.js";
55
55
  import * as stems from "./sqlite/stems.js";
56
56
  import { subscriptionsStoreOver } from "./sqlite/subscriptions.js";
57
57
  import { taskStoreOver } from "./sqlite/tasks.js";
58
+ import { templateStoreOver } from "./sqlite/templates.js";
58
59
  import { walletsStoreOver } from "./sqlite/wallets.js";
59
60
  import { storeErrors } from "./store-errors.js";
60
61
  import { syncStoreOver } from "./sync.js";
@@ -135,6 +136,7 @@ const storeOver = (context) => {
135
136
  const crm = once(() => crmCopiesOver(context, accountPeopleOver(context)));
136
137
  const relations = once(() => relationsStoreOver(context));
137
138
  const decisionRequests = once(() => decisionRequestStoreOver(context));
139
+ const templates = once(() => templateStoreOver(context));
138
140
  const records = once(() => recordStoreOver(context));
139
141
  const memories = once(() => memoriesStoreOver(context));
140
142
  const proposedActions = once(() => proposedActionsStoreOver(context));
@@ -277,6 +279,9 @@ const storeOver = (context) => {
277
279
  get decisionRequests() {
278
280
  return decisionRequests();
279
281
  },
282
+ get templates() {
283
+ return templates();
284
+ },
280
285
  get records() {
281
286
  return records();
282
287
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.613.0",
3
+ "version": "0.615.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",
@@ -15,7 +15,7 @@
15
15
  "type": "module",
16
16
  "wirecat": {
17
17
  "store": {
18
- "speaks": 58,
18
+ "speaks": 59,
19
19
  "minCompatible": 56
20
20
  }
21
21
  },
@@ -278,7 +278,7 @@
278
278
  "@types/node": "^22.20.5",
279
279
  "@types/pngjs": "6.0.5",
280
280
  "@vitest/coverage-v8": "^5.0.5",
281
- "@wirecat/cli-base": "0.85.0",
281
+ "@wirecat/cli-base": "0.87.0",
282
282
  "@wirecat/cli-core-legacy-tags": "npm:@wirecat/cli-core@0.414.0",
283
283
  "ajv": "8.17.1",
284
284
  "commander": "15.0.0",
@@ -299,7 +299,7 @@
299
299
  },
300
300
  "peerDependencies": {
301
301
  "@napi-rs/canvas": ">=0.1.69 <2",
302
- "@wirecat/cli-base": ">=0.80.7 <0.86.0",
302
+ "@wirecat/cli-base": ">=0.80.7 <1.0.0",
303
303
  "commander": ">=15"
304
304
  },
305
305
  "bin": {