@wirecat/cli-core 0.614.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.
- package/CHANGELOG.md +21 -0
- package/dist/background/report/render.d.ts +18 -4
- package/dist/background/report/render.js +59 -18
- package/dist/background/report/stored-templates.d.ts +64 -0
- package/dist/background/report/stored-templates.js +80 -0
- package/dist/background/report/templates/morning-digest.sample.json +150 -0
- package/dist/background/schedules.d.ts +4 -2
- package/dist/background/schedules.js +2 -1
- package/dist/cli/index.d.ts +2 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/schedule/schedule-command.d.ts +2 -0
- package/dist/cli/schedule/schedule-command.js +20 -2
- package/dist/cli/shared-command-exports.d.ts +1 -0
- package/dist/cli/shared-command-exports.js +2 -0
- package/dist/cli/templates-command.d.ts +16 -0
- package/dist/cli/templates-command.js +243 -0
- package/dist/errors/reasons.js +7 -0
- package/dist/services/metadata.d.ts +1 -1
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/sqlite/manifest.js +1 -0
- package/dist/store/sqlite/migrations.generated.js +8 -0
- package/dist/store/sqlite/schema/templates.d.ts +242 -0
- package/dist/store/sqlite/schema/templates.js +23 -0
- package/dist/store/sqlite/schema.d.ts +1 -0
- package/dist/store/sqlite/schema.js +1 -0
- package/dist/store/sqlite/templates.d.ts +38 -0
- package/dist/store/sqlite/templates.js +69 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/package.json +4 -4
|
@@ -4,6 +4,8 @@ import { CliError, resolvePaths, writeSecurely } from "@wirecat/cli-base";
|
|
|
4
4
|
import { annotate } from "@wirecat/cli-base/commands";
|
|
5
5
|
import { Argument, Command, Option } from "commander";
|
|
6
6
|
import { parseRoute, ROUTE_HELP, routeText } from "../../background/deliver.js";
|
|
7
|
+
import { REPORT_CHANNELS } from "../../background/report/render.js";
|
|
8
|
+
import { reportKeyOf } from "../../background/report/stored-templates.js";
|
|
7
9
|
import { describeWhen, findProgram, lastRun, listSchedules, NOTIFY_WHEN, notifyOf, readSchedule, recordSkip, runSchedule, SCHEDULE_DEFAULTS, SKIP_REASONS, scheduleFile, scheduleName, spentToday, timerFor, } from "../../background/schedules.js";
|
|
8
10
|
import { thisMachine } from "../../background/system.js";
|
|
9
11
|
import { locationVariables } from "../../background/units.js";
|
|
@@ -13,7 +15,7 @@ import { readOnlyLockOf } from "../../ports/app.js";
|
|
|
13
15
|
import { aheadOf } from "../../services/moment.js";
|
|
14
16
|
import { openCache } from "../../store/open.js";
|
|
15
17
|
import { storePath } from "../../store/path.js";
|
|
16
|
-
import { ownerLanguages } from "../../store/store.js";
|
|
18
|
+
import { ownerLanguages, storedTemplateBodies } from "../../store/store.js";
|
|
17
19
|
import { environmentOf, setExitCode } from "../context.js";
|
|
18
20
|
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE, REMOTE_WRITE } from "../effects.js";
|
|
19
21
|
import { itemOf, listOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
@@ -157,7 +159,7 @@ const runCapOf = (argv) => {
|
|
|
157
159
|
return Number.isFinite(cap) ? cap : null;
|
|
158
160
|
};
|
|
159
161
|
/** The language a report is rendered in: the store's `owner_languages`, first one; Russian when it cannot be read. */
|
|
160
|
-
const ownerLanguageOf = async (env) => {
|
|
162
|
+
export const ownerLanguageOf = async (env) => {
|
|
161
163
|
const path = storePath(env);
|
|
162
164
|
if (!existsSync(path))
|
|
163
165
|
return "ru";
|
|
@@ -170,6 +172,20 @@ const ownerLanguageOf = async (env) => {
|
|
|
170
172
|
database.close();
|
|
171
173
|
}
|
|
172
174
|
};
|
|
175
|
+
/** The templates the owner saved for a report, read without migrating the store; none when there is no store. */
|
|
176
|
+
const reportTemplatesOf = (env) => async (kind, language) => {
|
|
177
|
+
const path = storePath(env);
|
|
178
|
+
if (!existsSync(path))
|
|
179
|
+
return {};
|
|
180
|
+
const database = await openCache(path);
|
|
181
|
+
try {
|
|
182
|
+
const bodies = storedTemplateBodies(database, reportKeyOf(kind), language);
|
|
183
|
+
return Object.fromEntries(REPORT_CHANNELS.flatMap((channel) => (channel in bodies ? [[channel, bodies[channel]]] : [])));
|
|
184
|
+
}
|
|
185
|
+
finally {
|
|
186
|
+
database.close();
|
|
187
|
+
}
|
|
188
|
+
};
|
|
173
189
|
/**
|
|
174
190
|
* Runs the CLI's own commands, or an agent, later or on a timer — through systemd (Linux), launchd
|
|
175
191
|
* (macOS) or Task Scheduler (Windows). Every timer runs `schedule exec <file>`; the schedule file holds
|
|
@@ -446,6 +462,7 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
|
|
|
446
462
|
timer: timer(),
|
|
447
463
|
agentRuns,
|
|
448
464
|
ownerLanguage: ownerLanguageOf,
|
|
465
|
+
reportTemplates: reportTemplatesOf,
|
|
449
466
|
...(agentInput ? { agentInput } : {}),
|
|
450
467
|
...(signal ? { signal } : {}),
|
|
451
468
|
}));
|
|
@@ -483,6 +500,7 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
|
|
|
483
500
|
timer: timer(),
|
|
484
501
|
agentRuns,
|
|
485
502
|
ownerLanguage: ownerLanguageOf,
|
|
503
|
+
reportTemplates: reportTemplatesOf,
|
|
486
504
|
...(agentInput ? { agentInput } : {}),
|
|
487
505
|
untilUnlocked: true,
|
|
488
506
|
...(signal ? { signal } : {}),
|
|
@@ -815,3 +815,4 @@ export declare const runsCommand: (app: import("./entry.js").AppIdentity) => imp
|
|
|
815
815
|
export declare const skillCommand: (app: import("./entry.js").AppIdentity, skill: URL) => import("commander").Command;
|
|
816
816
|
export declare const upgradeCommand: (app: import("./entry.js").AppIdentity, packageName: string, contextFor: (command: import("commander").Command) => import("./upgrade-command.js").UpgradeContext) => import("commander").Command;
|
|
817
817
|
export declare const modelCatalogueCommand: (app: import("./entry.js").AppIdentity, options: import("./model-catalogue-command.js").ModelCatalogueOptions) => import("commander").Command;
|
|
818
|
+
export declare const templatesCommand: (app: import("./entry.js").AppIdentity, options: import("./templates-command.js").TemplatesOptions) => import("commander").Command;
|
|
@@ -121,4 +121,6 @@ export const runsCommand = sharedCommand(runsCommandDefinition);
|
|
|
121
121
|
export const skillCommand = sharedCommand(skillCommandDefinition);
|
|
122
122
|
export const upgradeCommand = sharedCommand(upgradeCommandDefinition);
|
|
123
123
|
import { modelCatalogueCommand as modelCatalogueDefinition } from "./model-catalogue-command.js";
|
|
124
|
+
import { templatesCommand as templatesDefinition } from "./templates-command.js";
|
|
124
125
|
export const modelCatalogueCommand = sharedCommand(modelCatalogueDefinition);
|
|
126
|
+
export const templatesCommand = sharedCommand(templatesDefinition);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import type { AppIdentity } from "../ports/app.js";
|
|
3
|
+
import { type Body } from "./envelope.js";
|
|
4
|
+
export interface TemplatesOptions {
|
|
5
|
+
env: () => NodeJS.ProcessEnv;
|
|
6
|
+
output: (answer: Body, command: Command) => void;
|
|
7
|
+
diagnostic: (line: string) => void;
|
|
8
|
+
/** Opens `path` in the owner's editor and returns when it closes; `$VISUAL` or `$EDITOR` when absent. */
|
|
9
|
+
editor?: (path: string, env: NodeJS.ProcessEnv) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* `templates`: the owner's own templates for the messages WireCat sends him, kept in the shared store over the ones
|
|
13
|
+
* cli-core ships. The platform rules (escaping, the tags each channel keeps, links only to the report's own, the
|
|
14
|
+
* Telegram size) stay in code and run after every render, so a template cannot break them.
|
|
15
|
+
*/
|
|
16
|
+
export declare const templatesCommand: (app: AppIdentity, options: TemplatesOptions) => Command;
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { CliError, resolvePaths } from "@wirecat/cli-base";
|
|
6
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
7
|
+
import { Command, Option } from "commander";
|
|
8
|
+
import { checkTemplate, defaultTemplate, REPORT_CHANNELS, renderReport, } from "../background/report/render.js";
|
|
9
|
+
import { checkTemplateSave, previewView, shippedLanguages, TEMPLATE_KEYS, templateKeyOf, } from "../background/report/stored-templates.js";
|
|
10
|
+
import { agentOf } from "../runs/run-context.js";
|
|
11
|
+
import { openStore } from "../store/store.js";
|
|
12
|
+
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "./effects.js";
|
|
13
|
+
import { itemOf, listOf } from "./envelope.js";
|
|
14
|
+
import { ownerLanguageOf } from "./schedule/schedule-command.js";
|
|
15
|
+
const withStore = async (env, work) => {
|
|
16
|
+
const store = await openStore({ env });
|
|
17
|
+
try {
|
|
18
|
+
return await work(store);
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
await store.close();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const systemEditor = (path, env) => {
|
|
25
|
+
const editor = env.VISUAL?.trim() || env.EDITOR?.trim();
|
|
26
|
+
if (!editor)
|
|
27
|
+
throw new CliError("validation_error", "set VISUAL or EDITOR, or pass the template with --file", {
|
|
28
|
+
reason: "template.no-editor",
|
|
29
|
+
});
|
|
30
|
+
const [program = editor, ...args] = editor.split(/\s+/);
|
|
31
|
+
const ran = spawnSync(program, [...args, path], { stdio: "inherit", env });
|
|
32
|
+
if (ran.status !== 0)
|
|
33
|
+
throw new CliError("validation_error", `the editor exited with ${ran.status ?? ran.signal}; nothing was saved`);
|
|
34
|
+
};
|
|
35
|
+
const channelOption = () => new Option("--channel <channel>", "telegram (Bot API HTML), email (HTML with inline styles) or text")
|
|
36
|
+
.choices(REPORT_CHANNELS)
|
|
37
|
+
.makeOptionMandatory();
|
|
38
|
+
const languageOption = () => new Option("--language <code>", "the template's language, ISO 639-1; the owner's first language if not given");
|
|
39
|
+
/** The key, its report kind and the language, refused when nothing renders the key or cli-core ships no such language. */
|
|
40
|
+
const addressOf = async (key, given, env) => {
|
|
41
|
+
const known = templateKeyOf(key);
|
|
42
|
+
if (!known)
|
|
43
|
+
throw new CliError("validation_error", `no template ${key}; the keys are ${TEMPLATE_KEYS.map((one) => one.key).join(", ")}`, {
|
|
44
|
+
reason: "template.unknown-key",
|
|
45
|
+
});
|
|
46
|
+
if (known.kind === null)
|
|
47
|
+
throw new CliError("validation_error", `nothing renders ${key} yet (${known.about}), so a template for it cannot be checked or saved`, { reason: "template.no-renderer" });
|
|
48
|
+
const language = (given.language ?? (await ownerLanguageOf(env))).trim().toLowerCase();
|
|
49
|
+
const languages = shippedLanguages(known.kind);
|
|
50
|
+
if (!languages.includes(language))
|
|
51
|
+
throw new CliError("validation_error", `${key} has templates in ${languages.join(", ")}; a ${language} one would never be used`, { reason: "template.unknown-language" });
|
|
52
|
+
return { address: { key, channel: given.channel, language }, kind: known.kind, channel: given.channel };
|
|
53
|
+
};
|
|
54
|
+
const refuseAgent = (env) => {
|
|
55
|
+
// A template decides what every later digest says to the owner; an agent could make it hide or invent things.
|
|
56
|
+
if (agentOf(env))
|
|
57
|
+
throw new CliError("permission_error", "only the owner changes a message template, not an agent", {
|
|
58
|
+
reason: "template.owner-only",
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const stateOf = (app, env) => resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state;
|
|
62
|
+
const historyOf = (store, address) => store.templates.history(address).map((entry) => ({
|
|
63
|
+
id: entry.id,
|
|
64
|
+
saved_at: new Date(entry.savedAt).toISOString(),
|
|
65
|
+
saved_by: entry.savedBy,
|
|
66
|
+
replaced_at: new Date(entry.replacedAt).toISOString(),
|
|
67
|
+
chars: entry.body.length,
|
|
68
|
+
}));
|
|
69
|
+
/**
|
|
70
|
+
* `templates`: the owner's own templates for the messages WireCat sends him, kept in the shared store over the ones
|
|
71
|
+
* cli-core ships. The platform rules (escaping, the tags each channel keeps, links only to the report's own, the
|
|
72
|
+
* Telegram size) stay in code and run after every render, so a template cannot break them.
|
|
73
|
+
*/
|
|
74
|
+
export const templatesCommand = (app, options) => {
|
|
75
|
+
const editor = options.editor ?? systemEditor;
|
|
76
|
+
const templates = annotate(new Command("templates"), { effects: LOCAL_READ }).description("the templates of the digest and the other messages sent to you, per channel and language; edit, preview, reset");
|
|
77
|
+
annotate(templates.command("list"), {
|
|
78
|
+
effects: LOCAL_READ,
|
|
79
|
+
examples: [`${app.command} templates list`],
|
|
80
|
+
})
|
|
81
|
+
.description("every template key, channel and language, and whether yours or the shipped one applies")
|
|
82
|
+
.action(async function () {
|
|
83
|
+
const env = options.env();
|
|
84
|
+
const stored = await withStore(env, (store) => store.templates.list());
|
|
85
|
+
const items = TEMPLATE_KEYS.flatMap((known) => REPORT_CHANNELS.flatMap((channel) => (known.kind === null ? [null] : shippedLanguages(known.kind)).map((language) => {
|
|
86
|
+
const row = stored.find((one) => one.key === known.key && one.channel === channel && one.language === language);
|
|
87
|
+
return {
|
|
88
|
+
key: known.key,
|
|
89
|
+
channel,
|
|
90
|
+
language,
|
|
91
|
+
about: known.about,
|
|
92
|
+
renders: known.kind !== null,
|
|
93
|
+
source: row ? "stored" : known.kind === null ? "none" : "default",
|
|
94
|
+
updated_at: row ? new Date(row.updatedAt).toISOString() : null,
|
|
95
|
+
updated_by: row?.updatedBy ?? null,
|
|
96
|
+
};
|
|
97
|
+
})));
|
|
98
|
+
options.output(listOf("templates list", { items, limit: items.length, has_more: false }), this);
|
|
99
|
+
});
|
|
100
|
+
annotate(templates.command("show"), {
|
|
101
|
+
effects: LOCAL_READ,
|
|
102
|
+
examples: [`${app.command} templates show report/morning-digest --channel telegram`],
|
|
103
|
+
})
|
|
104
|
+
.description("the template that applies, yours or the shipped one, and the bodies your changes replaced")
|
|
105
|
+
.argument("<key>", "the template, such as report/morning-digest")
|
|
106
|
+
.addOption(channelOption())
|
|
107
|
+
.addOption(languageOption())
|
|
108
|
+
.action(async function (key, given) {
|
|
109
|
+
const env = options.env();
|
|
110
|
+
const { address, kind, channel } = await addressOf(key, given, env);
|
|
111
|
+
const item = await withStore(env, (store) => {
|
|
112
|
+
const row = store.templates.get(address);
|
|
113
|
+
return {
|
|
114
|
+
...address,
|
|
115
|
+
source: row ? "stored" : "default",
|
|
116
|
+
body: row?.body ?? defaultTemplate(kind, channel, address.language),
|
|
117
|
+
updated_at: row ? new Date(row.updatedAt).toISOString() : null,
|
|
118
|
+
updated_by: row?.updatedBy ?? null,
|
|
119
|
+
history: historyOf(store, address),
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
options.output(itemOf(item), this);
|
|
123
|
+
});
|
|
124
|
+
grantsAuthority(annotate(templates.command("edit"), {
|
|
125
|
+
effects: LOCAL_WRITE,
|
|
126
|
+
examples: [
|
|
127
|
+
`${app.command} templates edit report/morning-digest --channel telegram`,
|
|
128
|
+
`${app.command} templates edit report/morning-digest --channel text --file digest.text.liquid`,
|
|
129
|
+
`${app.command} templates edit report/morning-digest --channel telegram --undo`,
|
|
130
|
+
],
|
|
131
|
+
}))
|
|
132
|
+
.description("change a template in $EDITOR or from --file; it is checked first, and a failed check saves nothing and says why")
|
|
133
|
+
.argument("<key>", "the template, such as report/morning-digest")
|
|
134
|
+
.addOption(channelOption())
|
|
135
|
+
.addOption(languageOption())
|
|
136
|
+
.option("--file <path>", "take the new template from this file instead of opening an editor")
|
|
137
|
+
.addOption(new Option("--undo", "put back the body your last change replaced; twice is back where you were").conflicts("file"))
|
|
138
|
+
.action(async function (key, given) {
|
|
139
|
+
const env = options.env();
|
|
140
|
+
refuseAgent(env);
|
|
141
|
+
const { address, kind, channel } = await addressOf(key, given, env);
|
|
142
|
+
const { current, previous } = await withStore(env, (store) => ({
|
|
143
|
+
current: store.templates.get(address)?.body,
|
|
144
|
+
previous: store.templates.history(address, 1)[0]?.body,
|
|
145
|
+
}));
|
|
146
|
+
const effective = current ?? defaultTemplate(kind, channel, address.language);
|
|
147
|
+
let draft;
|
|
148
|
+
let body;
|
|
149
|
+
if (given.undo) {
|
|
150
|
+
if (previous === undefined)
|
|
151
|
+
throw new CliError("validation_error", `${key} ${channel} ${address.language} has no earlier body to put back`, {
|
|
152
|
+
reason: "template.no-history",
|
|
153
|
+
});
|
|
154
|
+
body = previous;
|
|
155
|
+
}
|
|
156
|
+
else if (given.file !== undefined) {
|
|
157
|
+
body = readFileSync(given.file, "utf8");
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
draft = join(mkdtempSync(join(tmpdir(), "wirecat-template-")), `${key.replace("/", "-")}.${channel}.${address.language}.liquid`);
|
|
161
|
+
writeFileSync(draft, effective, { mode: 0o600 });
|
|
162
|
+
editor(draft, env);
|
|
163
|
+
body = readFileSync(draft, "utf8");
|
|
164
|
+
}
|
|
165
|
+
if (body === effective) {
|
|
166
|
+
if (draft)
|
|
167
|
+
rmSync(join(draft, ".."), { recursive: true, force: true });
|
|
168
|
+
options.diagnostic(`${key} ${channel} ${address.language} is unchanged; nothing saved`);
|
|
169
|
+
options.output(itemOf({ ...address, changed: false }), this);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const checks = await checkTemplateSave({
|
|
173
|
+
kind,
|
|
174
|
+
channel,
|
|
175
|
+
language: address.language,
|
|
176
|
+
body,
|
|
177
|
+
state: stateOf(app, env),
|
|
178
|
+
now: Date.now(),
|
|
179
|
+
});
|
|
180
|
+
const problems = checks.flatMap((check) => check.problems.map((problem) => `${check.against}: ${problem}`));
|
|
181
|
+
if (problems.length > 0)
|
|
182
|
+
throw new CliError("validation_error", `the template was not saved — ${problems.join("; ")}${draft ? `. Your text is in ${draft}; fix it and run again with --file ${draft}` : ""}`, { reason: "template.check-failed" });
|
|
183
|
+
const saved = await withStore(env, (store) => store.templates.save(address, body, app.command));
|
|
184
|
+
if (draft)
|
|
185
|
+
rmSync(join(draft, ".."), { recursive: true, force: true });
|
|
186
|
+
options.diagnostic(`saved ${key} ${channel} ${address.language}; checked against ${checks.map((check) => check.against).join(" and ")}`);
|
|
187
|
+
options.output(itemOf({
|
|
188
|
+
...address,
|
|
189
|
+
changed: true,
|
|
190
|
+
updated_at: new Date(saved.updatedAt).toISOString(),
|
|
191
|
+
updated_by: saved.updatedBy,
|
|
192
|
+
checked_against: checks.map((check) => check.against),
|
|
193
|
+
}), this);
|
|
194
|
+
});
|
|
195
|
+
annotate(templates.command("preview"), {
|
|
196
|
+
effects: LOCAL_READ,
|
|
197
|
+
examples: [
|
|
198
|
+
`${app.command} templates preview report/morning-digest --channel telegram`,
|
|
199
|
+
`${app.command} templates preview report/morning-digest --channel email --file draft.liquid`,
|
|
200
|
+
],
|
|
201
|
+
})
|
|
202
|
+
.description("what would be sent on that channel, from the last real report or a synthetic one when there is none; saves nothing")
|
|
203
|
+
.argument("<key>", "the template, such as report/morning-digest")
|
|
204
|
+
.addOption(channelOption())
|
|
205
|
+
.addOption(languageOption())
|
|
206
|
+
.option("--file <path>", "preview this draft instead of the template that applies")
|
|
207
|
+
.action(async function (key, given) {
|
|
208
|
+
const env = options.env();
|
|
209
|
+
const { address, kind, channel } = await addressOf(key, given, env);
|
|
210
|
+
const stored = given.file === undefined ? await withStore(env, (store) => store.templates.get(address)?.body) : undefined;
|
|
211
|
+
const body = given.file === undefined ? stored : readFileSync(given.file, "utf8");
|
|
212
|
+
const { against, view } = previewView(stateOf(app, env), kind, address.language, Date.now());
|
|
213
|
+
const rendering = await renderReport(view, channel, body === undefined ? {} : { template: body });
|
|
214
|
+
const problems = body === undefined ? [] : (await checkTemplate(view, channel, body)).problems;
|
|
215
|
+
options.output(itemOf({
|
|
216
|
+
...address,
|
|
217
|
+
template: given.file === undefined ? (stored === undefined ? "default" : "stored") : given.file,
|
|
218
|
+
against,
|
|
219
|
+
template_failed: rendering.templateFailed,
|
|
220
|
+
problems,
|
|
221
|
+
text: rendering.text,
|
|
222
|
+
}), this);
|
|
223
|
+
});
|
|
224
|
+
grantsAuthority(annotate(templates.command("reset"), {
|
|
225
|
+
effects: LOCAL_WRITE,
|
|
226
|
+
examples: [`${app.command} templates reset report/morning-digest --channel telegram`],
|
|
227
|
+
}))
|
|
228
|
+
.description("go back to the shipped template; yours is kept in the history, and edit --undo brings it back")
|
|
229
|
+
.argument("<key>", "the template, such as report/morning-digest")
|
|
230
|
+
.addOption(channelOption())
|
|
231
|
+
.addOption(languageOption())
|
|
232
|
+
.action(async function (key, given) {
|
|
233
|
+
const env = options.env();
|
|
234
|
+
refuseAgent(env);
|
|
235
|
+
const { address } = await addressOf(key, given, env);
|
|
236
|
+
const changed = await withStore(env, (store) => store.templates.reset(address));
|
|
237
|
+
options.diagnostic(changed
|
|
238
|
+
? `${key} ${address.channel} ${address.language} uses the shipped template again`
|
|
239
|
+
: `${key} ${address.channel} ${address.language} already uses the shipped template`);
|
|
240
|
+
options.output(itemOf({ ...address, changed }), this);
|
|
241
|
+
});
|
|
242
|
+
return templates;
|
|
243
|
+
};
|
package/dist/errors/reasons.js
CHANGED
|
@@ -396,6 +396,13 @@ const OTHERS = [
|
|
|
396
396
|
validation("tag-review.required", "the tag needs the owner's review first"),
|
|
397
397
|
["tag-review.stale", "configuration_error", "the tag review changed meanwhile"],
|
|
398
398
|
validation("tag.invalid", "the tag is not valid"),
|
|
399
|
+
validation("template.unknown-key", "there is no message template by that key"),
|
|
400
|
+
validation("template.no-renderer", "nothing renders that template key yet, so a template for it cannot be checked"),
|
|
401
|
+
validation("template.unknown-language", "cli-core ships no template in that language, so one would never be used"),
|
|
402
|
+
validation("template.check-failed", "the template failed its check and was not saved; the message says why"),
|
|
403
|
+
validation("template.no-history", "the template has no earlier body to put back"),
|
|
404
|
+
validation("template.no-editor", "no editor is set: set VISUAL or EDITOR, or pass the template with --file"),
|
|
405
|
+
["template.owner-only", "permission_error", "only the owner changes a message template, not an agent"],
|
|
399
406
|
["reactions.list-hidden", "permission_error", "the chat does not let its members see who reacted"],
|
|
400
407
|
["reactions.broadcast", "permission_error", "a channel does not show who reacted to its posts"],
|
|
401
408
|
validation("task.external-id", "an external id is <service>:<id>, such as avito:4512345678"),
|
|
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
|
|
|
14
14
|
dryRun?: boolean;
|
|
15
15
|
}) => Promise<{
|
|
16
16
|
items: ({
|
|
17
|
-
error?: undefined;
|
|
18
17
|
chatId: string;
|
|
19
18
|
tags: import("../domain/channel-tags.js").ChannelTagMatch[];
|
|
20
19
|
algorithm: string;
|
|
21
20
|
fetchedAt: string | null;
|
|
22
21
|
source: string;
|
|
22
|
+
error?: undefined;
|
|
23
23
|
} | {
|
|
24
24
|
tags?: undefined;
|
|
25
25
|
algorithm?: undefined;
|
package/dist/store/exports.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export { savedTaskCategories } from "./sqlite/task-category-settings.js";
|
|
|
60
60
|
export { DEFAULT_AGENT_CLOSE, savedAgentClose } from "./sqlite/task-close.js";
|
|
61
61
|
export { DEFAULT_FIRST_PASS_PER_CHAT, firstPassPerChatOf, savedFirstPassPerChat } from "./sqlite/task-first-pass.js";
|
|
62
62
|
export { inboxKey } from "./sqlite/tasks.js";
|
|
63
|
+
export { storedTemplateBodies, type TemplateAddress } from "./sqlite/templates.js";
|
|
63
64
|
export { THREAD_COLUMNS } from "./sqlite/thread-columns.js";
|
|
64
65
|
export { dropAllUnusedVectors, vectorIndexCounts } from "./sqlite/vector-index.js";
|
|
65
66
|
export type { MatchPlace, ScoredHit } from "./sqlite/words.js";
|
package/dist/store/exports.js
CHANGED
|
@@ -30,5 +30,6 @@ export { savedTaskCategories } from "./sqlite/task-category-settings.js";
|
|
|
30
30
|
export { DEFAULT_AGENT_CLOSE, savedAgentClose } from "./sqlite/task-close.js";
|
|
31
31
|
export { DEFAULT_FIRST_PASS_PER_CHAT, firstPassPerChatOf, savedFirstPassPerChat } from "./sqlite/task-first-pass.js";
|
|
32
32
|
export { inboxKey } from "./sqlite/tasks.js";
|
|
33
|
+
export { storedTemplateBodies } from "./sqlite/templates.js";
|
|
33
34
|
export { THREAD_COLUMNS } from "./sqlite/thread-columns.js";
|
|
34
35
|
export { dropAllUnusedVectors, vectorIndexCounts } from "./sqlite/vector-index.js";
|
package/dist/store/index.d.ts
CHANGED
|
@@ -99,6 +99,7 @@ export type { TaskRelation, TaskRelationKind, TaskRelationsStore } from "./sqlit
|
|
|
99
99
|
export { TASK_RELATION_KINDS } from "./sqlite/task-relations.js";
|
|
100
100
|
export type { TaskStatRow, TaskStatScope } from "./sqlite/task-stats.js";
|
|
101
101
|
export type { StoreTaskStore } from "./sqlite/tasks.js";
|
|
102
|
+
export type { StoredTemplate, TemplateAddress, TemplateHistoryEntry, TemplateStore } from "./sqlite/templates.js";
|
|
102
103
|
export type { TagPreflight, VocabularyAlias, VocabularyAliasReceipt, VocabularyAudit, VocabularyAuditOptions, VocabularyCatalog, VocabularyEntry, VocabularyKind, VocabularyOptions, VocabularyResolution, VocabularyStore, VocabularyTarget, } from "./sqlite/vocabulary.js";
|
|
103
104
|
export type { Wallet, WalletFilter, WalletInput, WalletsStore, WalletUpdate } from "./sqlite/wallets.js";
|
|
104
105
|
export type { BoardCounts, BoardOptions, EditedTask, MovedSubtask, NewWorkTask, RevisionCheck, TaskAssignment, TaskDetails, TaskEvent, TaskFields, TaskMove, TaskMoved, TaskRole, TaskType, WorkTaskType, } from "./sqlite/work-tasks.js";
|
|
@@ -122,6 +122,7 @@ export const MANIFEST = [
|
|
|
122
122
|
{ name: "20261108010754_version-57-business-rules", version: 57, minCompatible: 56 },
|
|
123
123
|
{ name: "20261108104659_version-58-enrichments", version: 58, minCompatible: 56 },
|
|
124
124
|
{ name: "20261108104701_version-58-enrichments-deletes", version: 58, minCompatible: 56 },
|
|
125
|
+
{ name: "20261108165309_version-59-templates", version: 59, minCompatible: 56 },
|
|
125
126
|
];
|
|
126
127
|
export const generatedMigrations = (manifest = MANIFEST, generated = GENERATED) => {
|
|
127
128
|
const migrations = [];
|
|
@@ -1208,5 +1208,13 @@ export const GENERATED = [
|
|
|
1208
1208
|
"CREATE TRIGGER enrichments_note_gone AFTER DELETE ON notes BEGIN\n DELETE FROM enrichments WHERE subject_type = 'note' AND subject_id = OLD.id;\nEND;",
|
|
1209
1209
|
"CREATE TRIGGER enrichments_email_gone AFTER DELETE ON emails BEGIN\n DELETE FROM enrichments WHERE subject_type = 'email' AND subject_id = OLD.id;\n DELETE FROM chunks WHERE chunkable_type = 'email_enrichment' AND chunkable_id = OLD.id;\nEND;"
|
|
1210
1210
|
]
|
|
1211
|
+
},
|
|
1212
|
+
{
|
|
1213
|
+
"name": "20261108165309_version-59-templates",
|
|
1214
|
+
"statements": [
|
|
1215
|
+
"CREATE TABLE `templates` (\n\t`key` text NOT NULL,\n\t`channel` text NOT NULL,\n\t`language` text NOT NULL,\n\t`body` text NOT NULL,\n\t`updated_at` integer NOT NULL,\n\t`updated_by` text NOT NULL,\n\tCONSTRAINT `templates_pk` PRIMARY KEY(`key`, `channel`, `language`)\n);",
|
|
1216
|
+
"CREATE TABLE `templates_history` (\n\t`id` integer PRIMARY KEY,\n\t`key` text NOT NULL,\n\t`channel` text NOT NULL,\n\t`language` text NOT NULL,\n\t`body` text NOT NULL,\n\t`saved_at` integer NOT NULL,\n\t`saved_by` text NOT NULL,\n\t`replaced_at` integer NOT NULL\n);",
|
|
1217
|
+
"CREATE INDEX `templates_history_by_key_channel_language_id` ON `templates_history` (`key`,`channel`,`language`,`id`);"
|
|
1218
|
+
]
|
|
1211
1219
|
}
|
|
1212
1220
|
];
|
|
@@ -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
|
+
}>;
|