@wirecat/wirecat 0.0.0-stage → 1.1.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/LICENSE +204 -0
- package/README.md +399 -2
- package/THIRD_PARTY_NOTICES +2 -0
- package/contracts/wirecat.json +4612 -0
- package/dist/actions/actions.js +269 -0
- package/dist/actions/command.js +102 -0
- package/dist/agents/command.js +17 -0
- package/dist/agents/log.js +23 -0
- package/dist/answer.js +100 -0
- package/dist/answers/command.js +128 -0
- package/dist/app.js +15 -0
- package/dist/author.js +109 -0
- package/dist/bin/wcat-wirecat.js +40 -0
- package/dist/bots/command.js +175 -0
- package/dist/bundle/auto-O24ISPOI.js +43 -0
- package/dist/bundle/chunk-2A3YPENI.js +31 -0
- package/dist/bundle/chunk-6BDIFKF5.js +222 -0
- package/dist/bundle/chunk-7O7XM37N.js +2 -0
- package/dist/bundle/chunk-AYHZY24E.js +120 -0
- package/dist/bundle/chunk-CKBTMZUX.js +72 -0
- package/dist/bundle/chunk-FGXUH3XL.js +416 -0
- package/dist/bundle/chunk-I5JQBRRC.js +807 -0
- package/dist/bundle/chunk-RKVAWMZT.js +38 -0
- package/dist/bundle/chunk-SCDNOUUR.js +395 -0
- package/dist/bundle/chunk-T7TG4JKR.js +312 -0
- package/dist/bundle/chunk-XBUCXQKT.js +51 -0
- package/dist/bundle/entry-EW5A7FYV.js +64 -0
- package/dist/bundle/failure-HMELJ3K5.js +19 -0
- package/dist/bundle/from-memo-F7NTUXAR.js +314 -0
- package/dist/bundle/program-7XWGFN4H.js +14994 -0
- package/dist/bundle/server-T7RVBNRW.js +303 -0
- package/dist/bundle/update-JZDS7B6L.js +22 -0
- package/dist/bundle/wcat-wirecat.js +83 -0
- package/dist/config-command.js +39 -0
- package/dist/config-issues.js +15 -0
- package/dist/config.js +187 -0
- package/dist/context/command.js +162 -0
- package/dist/context/context.js +197 -0
- package/dist/contract-overrides/commands.js +81 -0
- package/dist/contract-overrides/mcp.js +241 -0
- package/dist/contract-overrides/meetings.js +344 -0
- package/dist/contract-overrides/search.js +508 -0
- package/dist/contract-overrides/skill.js +85 -0
- package/dist/contract-overrides.js +7 -0
- package/dist/digest/backfill.js +175 -0
- package/dist/digest/brief.js +189 -0
- package/dist/digest/catch-up-record.js +30 -0
- package/dist/digest/catch-up.js +86 -0
- package/dist/digest/command.js +110 -0
- package/dist/digest/digest-commands.js +327 -0
- package/dist/digest/digest.js +560 -0
- package/dist/digest/digests.js +213 -0
- package/dist/digest/history.js +202 -0
- package/dist/digest/input.js +30 -0
- package/dist/digest/known.js +28 -0
- package/dist/digest/sources.js +155 -0
- package/dist/digest/sync-health.js +158 -0
- package/dist/digest/task-proposals.js +67 -0
- package/dist/digest/tasks.js +145 -0
- package/dist/digest/text.js +49 -0
- package/dist/discovery/command.js +107 -0
- package/dist/doctor/command.js +167 -0
- package/dist/documents/command.js +107 -0
- package/dist/domain-lists/command.js +13 -0
- package/dist/events/command.js +35 -0
- package/dist/events/events.js +196 -0
- package/dist/examples.js +609 -0
- package/dist/facts/command.js +100 -0
- package/dist/facts/fact.js +54 -0
- package/dist/facts/facts.js +15 -0
- package/dist/failure.js +58 -0
- package/dist/finance/command.js +121 -0
- package/dist/finance/contracts-command.js +109 -0
- package/dist/finance/deal-text.js +34 -0
- package/dist/finance/deals-command.js +346 -0
- package/dist/finance/finance.js +129 -0
- package/dist/finance/lines-command.js +70 -0
- package/dist/finance/orders-command.js +94 -0
- package/dist/finance/products-command.js +98 -0
- package/dist/finance/subscriptions-command.js +152 -0
- package/dist/finance/transactions-command.js +136 -0
- package/dist/finance/wallets-command.js +105 -0
- package/dist/finance/written.js +36 -0
- package/dist/findings/command.js +102 -0
- package/dist/findings-input.js +23 -0
- package/dist/identity.js +20 -0
- package/dist/install/postinstall.js +47 -0
- package/dist/json-fields.js +48 -0
- package/dist/knowledge/business-text.js +19 -0
- package/dist/knowledge/command.js +435 -0
- package/dist/knowledge/document-context.js +33 -0
- package/dist/knowledge/key-documents.js +120 -0
- package/dist/knowledge/list-queries.js +20 -0
- package/dist/knowledge/meeting-projects-command.js +61 -0
- package/dist/knowledge/messenger-sync.js +253 -0
- package/dist/knowledge/money-text.js +16 -0
- package/dist/knowledge/notes-about.js +81 -0
- package/dist/knowledge/organization-delete-command.js +44 -0
- package/dist/knowledge/organization-text.js +27 -0
- package/dist/knowledge/project-actions-command.js +130 -0
- package/dist/knowledge/project-actions.js +104 -0
- package/dist/knowledge/project-activity-command.js +70 -0
- package/dist/knowledge/project-context.js +101 -0
- package/dist/knowledge/project-findings.js +41 -0
- package/dist/knowledge/project-gather-command.js +100 -0
- package/dist/knowledge/project-status-command.js +129 -0
- package/dist/knowledge/project-transfer-command.js +58 -0
- package/dist/knowledge/project-transfer.js +107 -0
- package/dist/knowledge/relationships-scan.js +116 -0
- package/dist/knowledge/relationships.js +115 -0
- package/dist/knowledge/roles-command.js +67 -0
- package/dist/mail/command.js +20 -0
- package/dist/mail/findings-command.js +143 -0
- package/dist/mail/findings-duplicates.js +159 -0
- package/dist/mail/messages-command.js +77 -0
- package/dist/mail/review-command.js +59 -0
- package/dist/mail/subscriptions-command.js +84 -0
- package/dist/mcp/catalogue.js +159 -0
- package/dist/mcp/command.js +125 -0
- package/dist/mcp/granted.js +18 -0
- package/dist/mcp/permissions.js +61 -0
- package/dist/mcp/server.js +128 -0
- package/dist/meetings/command.js +31 -0
- package/dist/meetings/list-command.js +59 -0
- package/dist/meetings/preparation-command.js +42 -0
- package/dist/meetings/preparation-text.js +44 -0
- package/dist/meetings/preparation.js +50 -0
- package/dist/meetings/read.js +32 -0
- package/dist/memories/command.js +105 -0
- package/dist/memories/memories.js +17 -0
- package/dist/memories/memory.js +89 -0
- package/dist/memories/sources.js +111 -0
- package/dist/mentions/command.js +91 -0
- package/dist/migrate/check.js +48 -0
- package/dist/migrate/from-memo.js +345 -0
- package/dist/migrate/skill.js +35 -0
- package/dist/models/command.js +19 -0
- package/dist/options.js +35 -0
- package/dist/output.js +17 -0
- package/dist/page.js +14 -0
- package/dist/people/command.js +144 -0
- package/dist/people/delete-command.js +53 -0
- package/dist/people/doubts-command.js +81 -0
- package/dist/people/identities-command.js +188 -0
- package/dist/people/identity.js +42 -0
- package/dist/people/owner.js +14 -0
- package/dist/people/proposal-rows.js +70 -0
- package/dist/people/proposals-command.js +248 -0
- package/dist/people/review-context.js +108 -0
- package/dist/people/subject.js +19 -0
- package/dist/program.js +875 -0
- package/dist/read-only.js +51 -0
- package/dist/reasons.js +368 -0
- package/dist/records/import.js +135 -0
- package/dist/records/input.js +210 -0
- package/dist/records/mapping.js +80 -0
- package/dist/records/record-commands.js +125 -0
- package/dist/records/sources.js +73 -0
- package/dist/refs.js +28 -0
- package/dist/review/command.js +171 -0
- package/dist/review/kinds.js +44 -0
- package/dist/review/review.js +299 -0
- package/dist/review/status.js +93 -0
- package/dist/rows.js +219 -0
- package/dist/run/auto.js +237 -0
- package/dist/run/entry.js +62 -0
- package/dist/run/files.js +51 -0
- package/dist/run/import.js +253 -0
- package/dist/run/lock.js +20 -0
- package/dist/save-help.js +3 -0
- package/dist/schedule/command.js +58 -0
- package/dist/schedule/mail-triage-input.js +152 -0
- package/dist/schedule/task-triage-input.js +152 -0
- package/dist/search/answers.js +176 -0
- package/dist/search/command.js +257 -0
- package/dist/search/denied.js +9 -0
- package/dist/search/embed.js +126 -0
- package/dist/search/hits.js +4 -0
- package/dist/search/lane-gates.js +76 -0
- package/dist/search/notes-text.js +18 -0
- package/dist/search/people.js +88 -0
- package/dist/search/search.js +306 -0
- package/dist/show/command.js +179 -0
- package/dist/store/crm-viewer.js +102 -0
- package/dist/store/group.js +112 -0
- package/dist/store/groups-command.js +136 -0
- package/dist/store/guard.js +94 -0
- package/dist/store/held.js +21 -0
- package/dist/store/info-command.js +37 -0
- package/dist/store/scope.js +53 -0
- package/dist/store/source-list.js +222 -0
- package/dist/store/source-target.js +28 -0
- package/dist/tags/command.js +176 -0
- package/dist/tasks/command.js +174 -0
- package/dist/tasks/context.js +74 -0
- package/dist/tasks/list.js +199 -0
- package/dist/tasks/proposal-duplicates.js +70 -0
- package/dist/tasks/relations-command.js +28 -0
- package/dist/tasks/shared.js +105 -0
- package/dist/tasks/tasks.js +197 -0
- package/dist/templates/command.js +18 -0
- package/dist/terminal.js +23 -0
- package/dist/update.js +35 -0
- package/dist/version.js +2 -0
- package/dist/vocabulary/command.js +103 -0
- package/dist/vocabulary/inspect.js +23 -0
- package/dist/vocabulary/inspection.js +18 -0
- package/dist/vocabulary/list.js +18 -0
- package/dist/vocabulary/project.js +19 -0
- package/dist/wcat.js +3 -0
- package/install/postinstall.mjs +9 -0
- package/package.json +89 -4
- package/scenarios/decision-trail.md +21 -0
- package/scenarios/person-brief.md +35 -0
- package/scenarios/prepare-meeting.md +17 -0
- package/scenarios/project-state.md +26 -0
- package/scenarios/set-up.md +18 -0
- package/scenarios/start-the-day.md +19 -0
- package/skills/mail-triage/SKILL.md +208 -0
- package/skills/morning-digest/SKILL.md +147 -0
- package/skills/task-triage/SKILL.md +79 -0
- package/skills/wcat/SKILL.md +65 -0
- package/skills/wcat/topics/mail.md +32 -0
- package/skills/wcat/topics/mcp.md +22 -0
- package/skills/wcat/topics/meetings.md +37 -0
- package/skills/wcat/topics/money.md +52 -0
- package/skills/wcat/topics/projects.md +54 -0
- package/skills/wcat/topics/proposals.md +113 -0
- package/skills/wcat/topics/search.md +85 -0
- package/skills/wcat/topics/vocabulary.md +8 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { closeSync, cpSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmdirSync, rmSync, statSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { isMovedRun, resolvePaths, systemKeyring } from "@wirecat/cli-base";
|
|
4
|
+
import { pauseSchedule, readSchedule, thisMachine, writeSchedule, } from "@wirecat/cli-core";
|
|
5
|
+
import { APP } from "../app.js";
|
|
6
|
+
import { applyAuto, autoState, unitDir } from "../run/auto.js";
|
|
7
|
+
import { replaceMemoSkill } from "./skill.js";
|
|
8
|
+
/** memo's names before the rename: its folders, its variables, its keyring service and its units. */
|
|
9
|
+
export const OLD_APP = { ...APP, command: "memo", appName: "cli-memo", envPrefix: "MEMO" };
|
|
10
|
+
const OLD_JOBS_UNIT = "memo-import";
|
|
11
|
+
const NEW_PREFIX = `${APP.envPrefix}_`;
|
|
12
|
+
const OLD_PREFIX = `${OLD_APP.envPrefix}_`;
|
|
13
|
+
export const MARKER = "migrated-from-memo.json";
|
|
14
|
+
const PENDING_SCHEDULES = "migrating-schedules.json";
|
|
15
|
+
const LOCK_STALE_MS = 5 * 60_000;
|
|
16
|
+
/** The keyring accounts memo and the cli-core code it calls write under its own service, besides one per AI address. */
|
|
17
|
+
const FIXED_ACCOUNTS = [
|
|
18
|
+
"embeddings:openai",
|
|
19
|
+
"embeddings:anthropic",
|
|
20
|
+
"embeddings:endpoint:openai",
|
|
21
|
+
"embeddings:endpoint:anthropic",
|
|
22
|
+
// A key the owner stored by hand under the provider's own name, which cli-core still reads.
|
|
23
|
+
"openai",
|
|
24
|
+
"anthropic",
|
|
25
|
+
"registries:cas",
|
|
26
|
+
];
|
|
27
|
+
const isEmptyDir = (path) => {
|
|
28
|
+
try {
|
|
29
|
+
return statSync(path).isDirectory() && readdirSync(path).length === 0;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const readJson = (path) => {
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Moves one folder. Across file systems the copy goes to a sibling first and is renamed into place, so a copy cut
|
|
45
|
+
* short never sits at the new name and passes for the moved folder on the next start.
|
|
46
|
+
*/
|
|
47
|
+
const moveFolder = (from, to) => {
|
|
48
|
+
mkdirSync(dirname(to), { recursive: true });
|
|
49
|
+
try {
|
|
50
|
+
renameSync(from, to);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error.code !== "EXDEV")
|
|
54
|
+
throw error;
|
|
55
|
+
const partial = `${to}.moving`;
|
|
56
|
+
rmSync(partial, { recursive: true, force: true });
|
|
57
|
+
cpSync(from, partial, { recursive: true, preserveTimestamps: true, verbatimSymlinks: true });
|
|
58
|
+
renameSync(partial, to);
|
|
59
|
+
rmSync(from, { recursive: true, force: true });
|
|
60
|
+
}
|
|
61
|
+
// On Windows state and cache share one cli-memo folder; it goes once both are out.
|
|
62
|
+
try {
|
|
63
|
+
if (isEmptyDir(dirname(from)) && dirname(from).endsWith(OLD_APP.appName))
|
|
64
|
+
rmdirSync(dirname(from));
|
|
65
|
+
}
|
|
66
|
+
catch { }
|
|
67
|
+
};
|
|
68
|
+
const KINDS = ["config", "state", "cache"];
|
|
69
|
+
/** Moves each folder that only memo has. Answers the kinds whose old and new folders both hold files. */
|
|
70
|
+
export const moveFolders = (old, now) => {
|
|
71
|
+
const kept = [];
|
|
72
|
+
for (const kind of KINDS) {
|
|
73
|
+
if (!existsSync(old[kind]))
|
|
74
|
+
continue;
|
|
75
|
+
if (existsSync(now[kind]) && !isEmptyDir(now[kind])) {
|
|
76
|
+
kept.push(kind);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (isEmptyDir(now[kind]))
|
|
80
|
+
rmdirSync(now[kind]);
|
|
81
|
+
moveFolder(old[kind], now[kind]);
|
|
82
|
+
}
|
|
83
|
+
return kept;
|
|
84
|
+
};
|
|
85
|
+
/** The remote MCP login memo kept under its own name in its state folder, renamed where wcat's server looks. */
|
|
86
|
+
const moveHttpTokens = (state) => {
|
|
87
|
+
for (const ending of [".json", ".lock"]) {
|
|
88
|
+
const from = join(state, "mcp-http", `memo${ending}`);
|
|
89
|
+
const to = join(state, "mcp-http", `wcat${ending}`);
|
|
90
|
+
if (existsSync(from) && !existsSync(to))
|
|
91
|
+
renameSync(from, to);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
/** `endpointKeyName` of cli-core: the name of a key kept per AI address that is not one of the two providers. */
|
|
95
|
+
const endpointKey = (url) => {
|
|
96
|
+
try {
|
|
97
|
+
const host = new URL(url).host;
|
|
98
|
+
return ["openai", "anthropic"].includes(host) ? `endpoint:${host}` : host;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/** Every http(s) address in a settings file: a key for a custom AI address is named after its host. */
|
|
105
|
+
const addressesIn = (value) => {
|
|
106
|
+
if (typeof value === "string")
|
|
107
|
+
return /^https?:\/\//.test(value) ? [value] : [];
|
|
108
|
+
if (Array.isArray(value))
|
|
109
|
+
return value.flatMap(addressesIn);
|
|
110
|
+
if (value && typeof value === "object")
|
|
111
|
+
return Object.values(value).flatMap(addressesIn);
|
|
112
|
+
return [];
|
|
113
|
+
};
|
|
114
|
+
export const keyringAccounts = (settingsFiles) => [
|
|
115
|
+
...new Set([
|
|
116
|
+
...FIXED_ACCOUNTS,
|
|
117
|
+
...settingsFiles
|
|
118
|
+
.flatMap((file) => addressesIn(readJson(file)))
|
|
119
|
+
.flatMap((url) => {
|
|
120
|
+
const key = endpointKey(url);
|
|
121
|
+
return key ? [`embeddings:${key}`] : [];
|
|
122
|
+
}),
|
|
123
|
+
]),
|
|
124
|
+
];
|
|
125
|
+
/**
|
|
126
|
+
* Moves each entry from memo's keyring service to wcat's: read, write, read back and compare, and only then delete
|
|
127
|
+
* the old one. No keyring at all (no D-Bus, a locked one that refuses) counts as done: a key kept in a file instead
|
|
128
|
+
* lives in the config folder, which moved. Any other failure keeps the old entry for the next start.
|
|
129
|
+
*/
|
|
130
|
+
export const moveKeyring = (keyring, accounts) => {
|
|
131
|
+
let failed = false;
|
|
132
|
+
for (const account of accounts) {
|
|
133
|
+
let secret;
|
|
134
|
+
try {
|
|
135
|
+
secret = keyring.get(OLD_APP.appName, account);
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return failed ? "retry" : "done";
|
|
139
|
+
}
|
|
140
|
+
if (secret === null)
|
|
141
|
+
continue;
|
|
142
|
+
try {
|
|
143
|
+
const present = keyring.get(APP.appName, account);
|
|
144
|
+
// A key set under wcat already is the newer one; the old entry stays rather than lose a secret.
|
|
145
|
+
if (present !== null && present !== secret)
|
|
146
|
+
continue;
|
|
147
|
+
if (present === null)
|
|
148
|
+
keyring.set(APP.appName, account, secret);
|
|
149
|
+
if (keyring.get(APP.appName, account) !== secret) {
|
|
150
|
+
failed = true;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
keyring.delete(OLD_APP.appName, account);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
failed = true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return failed ? "retry" : "done";
|
|
160
|
+
};
|
|
161
|
+
const renamedVariables = (variables) => Object.fromEntries(Object.entries(variables).map(([name, value]) => [
|
|
162
|
+
name.startsWith(OLD_PREFIX) ? `${NEW_PREFIX}${name.slice(OLD_PREFIX.length)}` : name,
|
|
163
|
+
value,
|
|
164
|
+
]));
|
|
165
|
+
// Only before a command word, so "a memo to Kai" in a prompt stays as written.
|
|
166
|
+
const PROMPT_COMMAND = /\bmemo (?=(?:actions|answers|commands|context|digest|facts|guide|mail|meetings|memories|messages|organizations|people|projects|reminders|review|schedule|search|show|skill|sync|tags|tasks|templates)\b)/g;
|
|
167
|
+
/** What an agent was asked in memo's words, in wcat's: the program name, and the two moved `mail` commands. */
|
|
168
|
+
export const renamedPrompt = (prompt) => prompt
|
|
169
|
+
.replace(/\bmemo mail findings\b/g, "wcat review findings")
|
|
170
|
+
.replace(/\bmemo mail review\b/g, "wcat review mail")
|
|
171
|
+
.replace(PROMPT_COMMAND, "wcat ");
|
|
172
|
+
const renamedArgv = ({ kind, argv }) => {
|
|
173
|
+
// An agent schedule made before its spec was saved runs its argv, prompt included.
|
|
174
|
+
// `Bash(memo:*)` is the agent's allowed tool: with wcat's words in the prompt it has to allow wcat.
|
|
175
|
+
if (kind === "agent")
|
|
176
|
+
return argv.map((word) => renamedPrompt(word).replace(/^Bash\(memo([: ])/, "Bash(wcat$1"));
|
|
177
|
+
if (argv[0] !== "mail")
|
|
178
|
+
return argv;
|
|
179
|
+
if (argv[1] === "findings")
|
|
180
|
+
return ["review", "findings", ...argv.slice(2)];
|
|
181
|
+
if (argv[1] === "review")
|
|
182
|
+
return ["review", "mail", ...argv.slice(2)];
|
|
183
|
+
return argv;
|
|
184
|
+
};
|
|
185
|
+
export const renamedSchedule = (schedule) => {
|
|
186
|
+
const argv = renamedArgv(schedule);
|
|
187
|
+
return {
|
|
188
|
+
...schedule,
|
|
189
|
+
argv,
|
|
190
|
+
environment: renamedVariables(schedule.environment),
|
|
191
|
+
...(schedule.agent ? { agent: { ...schedule.agent, prompt: renamedPrompt(schedule.agent.prompt) } } : {}),
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
const listSchedules = (state) => {
|
|
195
|
+
const dir = join(state, "schedules");
|
|
196
|
+
if (!existsSync(dir))
|
|
197
|
+
return [];
|
|
198
|
+
return readdirSync(dir)
|
|
199
|
+
.map((name) => join(dir, name, "schedule.json"))
|
|
200
|
+
.filter((file) => existsSync(file))
|
|
201
|
+
.map((file) => readSchedule(file));
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Takes memo's schedules off their timers while their files are still in memo's folder, and keeps each as it was in a
|
|
205
|
+
* file that moves with the folder, so `restoreSchedules` puts them back on wcat's timers even after a cut-short start.
|
|
206
|
+
*/
|
|
207
|
+
const holdSchedules = async (site, state) => {
|
|
208
|
+
// Held by a start that was cut short: those files are paused now, and the pending file has them as they were.
|
|
209
|
+
if (existsSync(join(state, PENDING_SCHEDULES)))
|
|
210
|
+
return;
|
|
211
|
+
const schedules = listSchedules(state);
|
|
212
|
+
if (schedules.length === 0)
|
|
213
|
+
return;
|
|
214
|
+
writeFileSync(join(state, PENDING_SCHEDULES), `${JSON.stringify(schedules, null, 2)}\n`, { mode: 0o600 });
|
|
215
|
+
for (const schedule of schedules) {
|
|
216
|
+
const profile = schedule.environment[`${OLD_PREFIX}PROFILE`] ?? "";
|
|
217
|
+
await pauseSchedule({ app: OLD_APP, system: site.system, env: site.env, profile }, schedule.name, true);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
const restoreSchedules = async (site, state, warn) => {
|
|
221
|
+
const pending = join(state, PENDING_SCHEDULES);
|
|
222
|
+
const schedules = readJson(pending);
|
|
223
|
+
if (schedules === undefined)
|
|
224
|
+
return;
|
|
225
|
+
for (const schedule of schedules.map(renamedSchedule)) {
|
|
226
|
+
const profile = schedule.environment[`${NEW_PREFIX}PROFILE`] ?? "";
|
|
227
|
+
try {
|
|
228
|
+
await writeSchedule({ app: APP, system: site.system, env: site.env, profile }, schedule);
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
warn(`wcat: schedule ${schedule.name} is not on a timer: ${error.message}; ` +
|
|
232
|
+
`run wcat schedule resume ${schedule.name}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
rmSync(pending, { force: true });
|
|
236
|
+
};
|
|
237
|
+
/** `Environment="PATH=…" "WCAT_CONFIG_DIR=…"` of a unit memo wrote: the timer keeps the PATH it was set up with. */
|
|
238
|
+
const unitEnvironment = (text) => {
|
|
239
|
+
const line = /^Environment=(.*)$/m.exec(text)?.[1] ?? "";
|
|
240
|
+
return Object.fromEntries([...line.matchAll(/"((?:[^"\\]|\\.)*)"/g)].map((match) => {
|
|
241
|
+
const pair = (match[1] ?? "").replace(/\\(["\\])/g, "$1");
|
|
242
|
+
return [pair.slice(0, pair.indexOf("=")), pair.slice(pair.indexOf("=") + 1)];
|
|
243
|
+
}));
|
|
244
|
+
};
|
|
245
|
+
/**
|
|
246
|
+
* Replaces `memo jobs`' systemd timer with wcat's, through the same writer `wcat jobs start` uses. The config, already
|
|
247
|
+
* in wcat's folder, says whether the timer is on; its saved variables get wcat's prefix.
|
|
248
|
+
*/
|
|
249
|
+
const moveJobsTimer = async (env, configFile) => {
|
|
250
|
+
const raw = readJson(configFile);
|
|
251
|
+
if (raw?.auto?.places && Object.keys(raw.auto.places).some((name) => name.startsWith(OLD_PREFIX))) {
|
|
252
|
+
raw.auto.places = renamedVariables(raw.auto.places);
|
|
253
|
+
writeFileSync(configFile, `${JSON.stringify(raw, null, 2)}\n`);
|
|
254
|
+
}
|
|
255
|
+
const oldService = join(unitDir(env), `${OLD_JOBS_UNIT}.service`);
|
|
256
|
+
if (!existsSync(oldService) && !existsSync(join(unitDir(env), `${OLD_JOBS_UNIT}.timer`)))
|
|
257
|
+
return;
|
|
258
|
+
const saved = existsSync(oldService) ? unitEnvironment(readFileSync(oldService, "utf8")) : {};
|
|
259
|
+
const state = autoState(raw ?? {});
|
|
260
|
+
await applyAuto(env, { ...state, enabled: false }, OLD_JOBS_UNIT);
|
|
261
|
+
// The unit keeps the PATH memo's timer had; systemctl itself runs on this start's PATH.
|
|
262
|
+
if (state.enabled)
|
|
263
|
+
await applyAuto(env, state, undefined, saved.PATH ?? env.PATH);
|
|
264
|
+
};
|
|
265
|
+
/** Takes the lock beside wcat's state folder, or answers false while another start holds it. */
|
|
266
|
+
const lock = (path) => {
|
|
267
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
268
|
+
try {
|
|
269
|
+
closeSync(openSync(path, "wx"));
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
try {
|
|
273
|
+
if (Date.now() - statSync(path).mtimeMs < LOCK_STALE_MS)
|
|
274
|
+
return undefined;
|
|
275
|
+
rmSync(path, { force: true });
|
|
276
|
+
closeSync(openSync(path, "wx"));
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
return undefined;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return () => rmSync(path, { force: true });
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* wcat's first start after memo: memo's config, state and cache folders, its keyring entries, its timers and its agent
|
|
286
|
+
* skill move to wcat's names. A marker in wcat's state folder makes it once; a keyring step that failed is tried again
|
|
287
|
+
* on the next start. A run with moved folders is a test or a sandbox and moves nothing. Nothing goes to stdout.
|
|
288
|
+
*/
|
|
289
|
+
export const migrateFromMemo = async ({ env, platform = process.platform, home, keyring = systemKeyring, system, warn = () => undefined, }) => {
|
|
290
|
+
const moved = isMovedRun({ appName: APP.appName, prefix: APP.envPrefix, env, platform, home }) ||
|
|
291
|
+
isMovedRun({ appName: OLD_APP.appName, prefix: OLD_APP.envPrefix, env, platform, home });
|
|
292
|
+
if (moved)
|
|
293
|
+
return "moved-run";
|
|
294
|
+
const now = resolvePaths({ appName: APP.appName, prefix: APP.envPrefix, env, platform });
|
|
295
|
+
const old = resolvePaths({ appName: OLD_APP.appName, prefix: OLD_APP.envPrefix, env, platform });
|
|
296
|
+
const markerPath = join(now.state, MARKER);
|
|
297
|
+
const before = existsSync(markerPath) ? readJson(markerPath) : undefined;
|
|
298
|
+
if (before && before.keyring === "done")
|
|
299
|
+
return "done-before";
|
|
300
|
+
const unlock = lock(`${now.state}.migrating`);
|
|
301
|
+
if (!unlock)
|
|
302
|
+
return "busy";
|
|
303
|
+
try {
|
|
304
|
+
const accounts = () => keyringAccounts([
|
|
305
|
+
join(now.config, "config.json"),
|
|
306
|
+
join(resolvePaths({ appName: "WireCat", prefix: "WIRECAT", env, platform }).config, "config.json"),
|
|
307
|
+
]);
|
|
308
|
+
if (before) {
|
|
309
|
+
const keys = moveKeyring(keyring, accounts());
|
|
310
|
+
writeFileSync(markerPath, `${JSON.stringify({ ...before, keyring: keys })}\n`);
|
|
311
|
+
return "keyring-retried";
|
|
312
|
+
}
|
|
313
|
+
const site = { env, system: system ?? thisMachine() };
|
|
314
|
+
const stateMoves = existsSync(old.state) && (!existsSync(now.state) || isEmptyDir(now.state));
|
|
315
|
+
if (stateMoves)
|
|
316
|
+
await holdSchedules(site, old.state);
|
|
317
|
+
const tasksOf = (appName, prefix) => resolvePaths({ appName, prefix, env, platform });
|
|
318
|
+
// The task commands keep their settings in a folder of their own.
|
|
319
|
+
const tasks = [tasksOf("cli-memo-tasks", "MEMO_TASKS"), tasksOf("wcat-tasks", "WCAT_TASKS")];
|
|
320
|
+
for (const [from, to] of [[old, now], tasks]) {
|
|
321
|
+
const kept = moveFolders(from, to);
|
|
322
|
+
if (kept.length > 0)
|
|
323
|
+
warn(`wcat: memo's ${kept.join(", ")} folder stayed where it was, because wcat's already holds files; ` +
|
|
324
|
+
`wcat uses its own (${kept.map((kind) => to[kind]).join(", ")})`);
|
|
325
|
+
}
|
|
326
|
+
moveHttpTokens(now.state);
|
|
327
|
+
await restoreSchedules(site, now.state, warn);
|
|
328
|
+
if (platform === "linux")
|
|
329
|
+
await moveJobsTimer(env, join(now.config, "config.json")).catch((error) => warn(`wcat: memo's sync timer was not replaced: ${error.message}; run wcat jobs start`));
|
|
330
|
+
try {
|
|
331
|
+
replaceMemoSkill(env);
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
warn(`wcat: memo's agent skill was not replaced: ${error.message}; run wcat skill install`);
|
|
335
|
+
}
|
|
336
|
+
const keys = moveKeyring(keyring, accounts());
|
|
337
|
+
mkdirSync(now.state, { recursive: true });
|
|
338
|
+
writeFileSync(markerPath, `${JSON.stringify({ at: new Date().toISOString(), keyring: keys })}\n`);
|
|
339
|
+
return "migrated";
|
|
340
|
+
}
|
|
341
|
+
finally {
|
|
342
|
+
unlock();
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
//# sourceMappingURL=from-memo.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { readFileSync, rmSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { installSkill, skillPath, skillVersion } from "@wirecat/cli-base/skill";
|
|
4
|
+
import { APP } from "../app.js";
|
|
5
|
+
const OLD_SKILL_NAME = /^name:\s*["']?cli-memo["']?\s*$/m;
|
|
6
|
+
/**
|
|
7
|
+
* memo's skill folders. Only a SKILL.md that memo's install stamped (its name and a version) counts, so a folder the
|
|
8
|
+
* owner wrote by hand stays.
|
|
9
|
+
*/
|
|
10
|
+
export const memoSkills = (env) => ["claude", "agents"]
|
|
11
|
+
.map((target) => ({ target, folder: dirname(skillPath(target, "cli-memo", env)) }))
|
|
12
|
+
.filter(({ folder }) => {
|
|
13
|
+
try {
|
|
14
|
+
const text = readFileSync(join(folder, "SKILL.md"), "utf8");
|
|
15
|
+
return OLD_SKILL_NAME.test(text) && skillVersion(text) !== undefined;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
export const removeMemoSkills = (env) => {
|
|
22
|
+
const found = memoSkills(env);
|
|
23
|
+
for (const { folder } of found)
|
|
24
|
+
rmSync(folder, { recursive: true, force: true });
|
|
25
|
+
return found.map(({ target }) => target);
|
|
26
|
+
};
|
|
27
|
+
export const SKILL = new URL("../../skills/wcat/SKILL.md", import.meta.url);
|
|
28
|
+
/** Where memo's skill was installed, wcat's takes its place, and memo's folder goes. */
|
|
29
|
+
export const replaceMemoSkill = (env, skill = SKILL) => {
|
|
30
|
+
const found = memoSkills(env);
|
|
31
|
+
if (found.length > 0)
|
|
32
|
+
installSkill(APP, skill, { env, targets: found.map(({ target }) => target) });
|
|
33
|
+
return removeMemoSkills(env);
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=skill.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { modelCatalogueCommand } from "@wirecat/cli-core";
|
|
2
|
+
import { answers } from "../answer.js";
|
|
3
|
+
import { APP } from "../app.js";
|
|
4
|
+
export const modelsCommand = (program, streams, env, keyring, stdin) => {
|
|
5
|
+
const { print } = answers(program, streams, env);
|
|
6
|
+
program.addCommand(modelCatalogueCommand(APP, {
|
|
7
|
+
kinds: ["text"],
|
|
8
|
+
// wcat's sync is the one that enriches, so wcat offers the switch.
|
|
9
|
+
enrichment: true,
|
|
10
|
+
jsonOption: true,
|
|
11
|
+
env: () => env,
|
|
12
|
+
...(keyring ? { keyring } : {}),
|
|
13
|
+
...(stdin ? { stdin: () => stdin } : {}),
|
|
14
|
+
output: (body, command) => print(command.optsWithGlobals().json, body),
|
|
15
|
+
diagnostic: (line) => streams.diagnostic(line),
|
|
16
|
+
offline: () => program.opts().offline === true,
|
|
17
|
+
}));
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=command.js.map
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { InvalidArgumentError } from "commander";
|
|
2
|
+
import { ONE_ACCOUNT_HELP, sourceOptions, writeOptions } from "./store/source-list.js";
|
|
3
|
+
export const positive = (value) => {
|
|
4
|
+
const number = Number(value);
|
|
5
|
+
if (!Number.isInteger(number) || number < 1)
|
|
6
|
+
throw new InvalidArgumentError("a whole number above zero");
|
|
7
|
+
return number;
|
|
8
|
+
};
|
|
9
|
+
/** A whole number from `low` to `high`, both included. */
|
|
10
|
+
export const between = (low, high) => (value) => {
|
|
11
|
+
const number = Number(value);
|
|
12
|
+
if (!Number.isInteger(number) || number < low || number > high)
|
|
13
|
+
throw new InvalidArgumentError(`a whole number, ${low} to ${high}`);
|
|
14
|
+
return number;
|
|
15
|
+
};
|
|
16
|
+
export const whole = (value) => {
|
|
17
|
+
const number = Number(value);
|
|
18
|
+
if (!Number.isInteger(number) || number < 0 || number > 100)
|
|
19
|
+
throw new InvalidArgumentError("a whole number, 0 to 100");
|
|
20
|
+
return number;
|
|
21
|
+
};
|
|
22
|
+
export const oneOf = (values) => (value) => {
|
|
23
|
+
if (!values.includes(value))
|
|
24
|
+
throw new InvalidArgumentError(`choose ${values.join(", ")}`);
|
|
25
|
+
return value;
|
|
26
|
+
};
|
|
27
|
+
/** A repeatable option: `--subject a --subject b`. */
|
|
28
|
+
export const collect = (value, previous = []) => [...previous, value];
|
|
29
|
+
/** A read's `--source`, naming one account, or several where `help` says so. */
|
|
30
|
+
export const readScope = (command, help = ONE_ACCOUNT_HELP) => sourceOptions(command, help).option("--json", "print JSON; --json=id,title keeps only those fields");
|
|
31
|
+
/** A write's `--account provider:account`. */
|
|
32
|
+
export const writeScope = (command, help) => writeOptions(command, help).option("--json", "print JSON; --json=id,title keeps only those fields");
|
|
33
|
+
/** `--json`, and the fields `--json=a,b` may keep, named in its help. */
|
|
34
|
+
export const jsonOption = (command, fields = "ref,title") => command.option("--json", `print JSON; --json=${fields} keeps only those fields`);
|
|
35
|
+
//# sourceMappingURL=options.js.map
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { resolveOutput, snakeKeysKeeping } from "@wirecat/cli-core";
|
|
2
|
+
/** Every key snake_case, except under a note's front matter or an email's headers: the owner's or a provider's words. */
|
|
3
|
+
export const snakeKeys = snakeKeysKeeping(["front_matter", "metadata", "headers"]);
|
|
4
|
+
/**
|
|
5
|
+
* Found messages cut to cli-core's detail level, which picks a hit's fields by their camelCase names — so before
|
|
6
|
+
* `snakeKeys`. cli-core exports the cut only inside its JSON renderer.
|
|
7
|
+
*/
|
|
8
|
+
export const atDetail = (value, level) => {
|
|
9
|
+
let picked = "";
|
|
10
|
+
resolveOutput({
|
|
11
|
+
json: true,
|
|
12
|
+
streams: { data: (chunk) => (picked += chunk), diagnostic: () => undefined, progress: () => undefined },
|
|
13
|
+
...(level === undefined ? {} : { hitDetail: level }),
|
|
14
|
+
}).renderer.result(value);
|
|
15
|
+
return JSON.parse(picked);
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=output.js.map
|
package/dist/page.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { listAnswer } from "./answer.js";
|
|
2
|
+
/** One page of a store list, which says itself whether more rows remain. */
|
|
3
|
+
export const pageOf = async (command, limit, read, { fallback = 100, cap = 500, page, args, shape = (rows) => rows } = {}) => {
|
|
4
|
+
const wanted = Math.min(limit ?? fallback, cap);
|
|
5
|
+
const { items, hasMore } = await read(wanted, ((page ?? 1) - 1) * wanted);
|
|
6
|
+
return listAnswer(command, {
|
|
7
|
+
items: await shape(items),
|
|
8
|
+
limit: wanted,
|
|
9
|
+
has_more: hasMore,
|
|
10
|
+
...(page === undefined ? {} : { page }),
|
|
11
|
+
...(args === undefined ? {} : { args }),
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=page.js.map
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { LOCAL_READ, LOCAL_WRITE, PEOPLE_SORTS, PERSON_KINDS, queryTerms, termField, withQuery, } from "@wirecat/cli-core";
|
|
3
|
+
import { answers, itemAnswer, listAnswer, wholeList, withStore } from "../answer.js";
|
|
4
|
+
import { oneOf, positive } from "../options.js";
|
|
5
|
+
import { groupOf, keepInGroup } from "../store/group.js";
|
|
6
|
+
import { identitiesCommands } from "./identities-command.js";
|
|
7
|
+
const personRow = (person) => ({
|
|
8
|
+
ref: person.person,
|
|
9
|
+
name: person.name,
|
|
10
|
+
display_name: person.displayName,
|
|
11
|
+
kind: person.kind,
|
|
12
|
+
kind_signals: person.kindSignals,
|
|
13
|
+
owner: person.owner,
|
|
14
|
+
tasks: person.tasks,
|
|
15
|
+
contact: person.contact,
|
|
16
|
+
phone: person.phone,
|
|
17
|
+
email: person.email,
|
|
18
|
+
username: person.username,
|
|
19
|
+
username_source: person.usernameSource,
|
|
20
|
+
messages_from: person.messagesFrom,
|
|
21
|
+
last_contact: person.lastContact,
|
|
22
|
+
ties: person.ties,
|
|
23
|
+
});
|
|
24
|
+
// Keyed by name rather than PersonKind: a cli-core that adds a kind must not break wcat's build.
|
|
25
|
+
const KIND_WORDS = {
|
|
26
|
+
person: ["person", "people"],
|
|
27
|
+
organization: ["organization", "organizations"],
|
|
28
|
+
automated: ["automated sender", "automated senders"],
|
|
29
|
+
stranger: ["stranger", "strangers"],
|
|
30
|
+
unsorted: ["unsorted one", "unsorted ones"],
|
|
31
|
+
test: ["test account", "test accounts"],
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* One step to every kind, with how many each other kind holds: an answer keeps two next steps at most, and the next page
|
|
35
|
+
* takes one of them.
|
|
36
|
+
*/
|
|
37
|
+
const otherKinds = (shown, counts, name) => {
|
|
38
|
+
// Test data is hidden from every list: `kind:all` leaves it out, so the step never names it.
|
|
39
|
+
const others = PERSON_KINDS.filter((kind) => kind !== shown && kind !== "test" && counts[kind] > 0);
|
|
40
|
+
if (shown === "all" || others.length === 0)
|
|
41
|
+
return [];
|
|
42
|
+
const query = ["kind:all", ...(name === undefined ? [] : [`name:${JSON.stringify(name)}`])].join(" ");
|
|
43
|
+
return [
|
|
44
|
+
{
|
|
45
|
+
kind: "command",
|
|
46
|
+
step: "people.kinds",
|
|
47
|
+
command: "people list",
|
|
48
|
+
args: { query },
|
|
49
|
+
line: `wcat people list '${query}'`,
|
|
50
|
+
why: others
|
|
51
|
+
.map((kind) => {
|
|
52
|
+
const [one, many] = KIND_WORDS[kind] ?? [kind, kind];
|
|
53
|
+
return `${counts[kind]} ${counts[kind] === 1 ? one : many}`;
|
|
54
|
+
})
|
|
55
|
+
.join(", "),
|
|
56
|
+
safe_to_auto_execute: true,
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
};
|
|
60
|
+
export const peopleCommand = (program, streams, env) => {
|
|
61
|
+
const { print } = answers(program, streams, env);
|
|
62
|
+
const people = program
|
|
63
|
+
.command("people")
|
|
64
|
+
.description("the people wcat knows: who is who across sources, and whom to assign tasks to");
|
|
65
|
+
annotate(people.command("add"), { effects: LOCAL_WRITE, literal_after_dashes: true })
|
|
66
|
+
.description("add a person by name, before any message names them")
|
|
67
|
+
.argument("<name...>", "what to call them")
|
|
68
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
69
|
+
.action(async (words, options) => {
|
|
70
|
+
await withStore(env, async (store) => {
|
|
71
|
+
const person = await store.people.add({ name: words.join(" ") });
|
|
72
|
+
print(options.json, itemAnswer({ ref: `person:${person.uid}`, name: person.name }), `person:${person.uid}`);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
const query = {
|
|
76
|
+
entity: "task_person",
|
|
77
|
+
backend: "native",
|
|
78
|
+
fields: [
|
|
79
|
+
termField("name", "txt", "name:ivan"),
|
|
80
|
+
termField("kind", "enum", "kind:organization", { values: [...PERSON_KINDS, "all"] }),
|
|
81
|
+
],
|
|
82
|
+
};
|
|
83
|
+
withQuery(annotate(people.command("list"), { effects: LOCAL_READ })
|
|
84
|
+
.summary("people of one kind, most messages first: person by default")
|
|
85
|
+
.description("people of one kind: person (the default: the owner, people added by hand or assigned a task, and named " +
|
|
86
|
+
"people with a tie to you, such as a one-to-one chat, a group of at most 10, mail you wrote, a meeting, a " +
|
|
87
|
+
"CRM deal of yours or your address book), organization, automated (a name or a bulk mailbox marks them; " +
|
|
88
|
+
"bots are not people: bots list), " +
|
|
89
|
+
"stranger (no tie), unsorted (no name), test (what a test run left, hidden from every other list) or all, " +
|
|
90
|
+
"which leaves test out. The owner first, then by the messages and mail they sent"), query)
|
|
91
|
+
.option("--sort <field>", `${PEOPLE_SORTS.join(", ")} (default interactions)`, oneOf(PEOPLE_SORTS), "interactions")
|
|
92
|
+
.option("--limit <n>", "most people on a page, up to 5000", positive, 500)
|
|
93
|
+
.option("--page <n>", "which page, from 1", positive, 1)
|
|
94
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
95
|
+
.action(async (words, { json, ...options }) => {
|
|
96
|
+
const terms = queryTerms(words, query, "people list");
|
|
97
|
+
const name = terms.get("name");
|
|
98
|
+
const kind = (terms.get("kind") ?? "person");
|
|
99
|
+
const limit = Math.min(options.limit, 5000);
|
|
100
|
+
await withStore(env, async (store) => {
|
|
101
|
+
const found = await store.people.list({
|
|
102
|
+
limit,
|
|
103
|
+
offset: (options.page - 1) * limit,
|
|
104
|
+
sort: options.sort,
|
|
105
|
+
kind,
|
|
106
|
+
...(name === undefined ? {} : { query: name }),
|
|
107
|
+
});
|
|
108
|
+
const counted = groupOf(env) === undefined;
|
|
109
|
+
// In a group the store's counts and ties cover accounts outside it (WC-ACCT-13), so the answer claims none.
|
|
110
|
+
const rows = found.items
|
|
111
|
+
.map(personRow)
|
|
112
|
+
.map((row) => counted ? row : { ...row, messages_from: null, last_contact: null, ties: [], kind_signals: [] });
|
|
113
|
+
const items = await keepInGroup(store, env, rows, ({ ref }) => ref);
|
|
114
|
+
const steps = counted ? otherKinds(kind, found.counts, name) : [];
|
|
115
|
+
print(json, listAnswer("people list", {
|
|
116
|
+
items,
|
|
117
|
+
limit,
|
|
118
|
+
has_more: found.hasMore,
|
|
119
|
+
page: options.page,
|
|
120
|
+
...(counted ? { total: { value: found.total, relation: "eq" } } : {}),
|
|
121
|
+
args: {
|
|
122
|
+
...(words.length ? { query: words.join(" ") } : {}),
|
|
123
|
+
...(options.sort === "interactions" ? {} : { sort: options.sort }),
|
|
124
|
+
},
|
|
125
|
+
...(steps.length ? { next: steps } : {}),
|
|
126
|
+
}));
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
annotate(people.command("check"), { effects: LOCAL_READ })
|
|
130
|
+
.summary("people with a name like this one, to check before adding a person")
|
|
131
|
+
.description("people whose names start like these words, the same name first: check before adding a person")
|
|
132
|
+
.argument("<name...>", "the name being typed")
|
|
133
|
+
.option("--limit <n>", "most people, up to 50", positive, 8)
|
|
134
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
135
|
+
.action(async (words, options) => {
|
|
136
|
+
await withStore(env, async (store) => {
|
|
137
|
+
const found = await store.people.similar(words.join(" "), { limit: Math.min(options.limit, 50) });
|
|
138
|
+
const items = await keepInGroup(store, env, found.map(({ sameName, ...person }) => ({ ...personRow(person), same_name: sameName })), ({ ref }) => ref);
|
|
139
|
+
print(options.json, wholeList("people check", items));
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
identitiesCommands(people, program, streams, env);
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
3
|
+
import { LOCAL_WRITE } from "@wirecat/cli-core";
|
|
4
|
+
import { answers, itemAnswer, withStore } from "../answer.js";
|
|
5
|
+
import { byOption } from "../author.js";
|
|
6
|
+
import { personOf } from "./identity.js";
|
|
7
|
+
import { asOwner } from "./proposal-rows.js";
|
|
8
|
+
const counts = (rows) => Object.entries(rows)
|
|
9
|
+
.map(([where, n]) => `${n} ${where}`)
|
|
10
|
+
.join(", ");
|
|
11
|
+
const planText = (plan) => [
|
|
12
|
+
`${plan.erased ? "deleted" : "this deletes"} ${plan.person}${plan.name ? ` (${plan.name})` : ""}`,
|
|
13
|
+
...(plan.merged.length ? [` merged into them earlier, deleted too: ${plan.merged.join(", ")}`] : []),
|
|
14
|
+
` identities: ${plan.identities.join(", ") || "none"}`,
|
|
15
|
+
...(Object.keys(plan.deleted).length ? [` deleted with them: ${counts(plan.deleted)}`] : []),
|
|
16
|
+
...(Object.keys(plan.detached).length ? [` stay, without the person: ${counts(plan.detached)}`] : []),
|
|
17
|
+
...(plan.kept.length
|
|
18
|
+
? [
|
|
19
|
+
` stay with no person, as messages, mail or meetings name them; the next sync or people scan makes a ` +
|
|
20
|
+
`person again: ${plan.kept.map(({ identity, references }) => `${identity} (${references})`).join(", ")}`,
|
|
21
|
+
]
|
|
22
|
+
: []),
|
|
23
|
+
].join("\n");
|
|
24
|
+
export const deleteCommand = (people, program, streams, env) => {
|
|
25
|
+
const { print } = answers(program, streams, env);
|
|
26
|
+
byOption(annotate(people.command("delete"), {
|
|
27
|
+
effects: LOCAL_WRITE,
|
|
28
|
+
output: { entity: "person_erasure" },
|
|
29
|
+
examples: ["wcat people delete person:17", "wcat people delete person:17 --yes"],
|
|
30
|
+
})
|
|
31
|
+
.summary("delete a person and what wcat knows of them alone; only you")
|
|
32
|
+
.description("delete a person, the people merged into them earlier, their identities, your notes about them, and the " +
|
|
33
|
+
"tags, links, aliases and mentions that name them. A fact, task or imported entry that names them stays " +
|
|
34
|
+
"and loses the name; a note that only links to them stays. Messages, mail and meetings are their " +
|
|
35
|
+
"source's: they stay, and the next sync makes their sender a person again. An invoice, order or " +
|
|
36
|
+
"subscription that names the person must be changed first. Without --yes it shows what would go and " +
|
|
37
|
+
"changes nothing")
|
|
38
|
+
.argument("<who>", "person:<uid> as people list prints it, or an identity of the person")
|
|
39
|
+
.option("--yes", "delete; nothing of the person can be brought back"))
|
|
40
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
41
|
+
.action(async (who, options, command) => {
|
|
42
|
+
const person = await withStore(env, async (store) => `person:${(await personOf(store, who)).uid}`);
|
|
43
|
+
const by = await asOwner(command, env, `delete ${person}?`);
|
|
44
|
+
const plan = await withStore(env, (store) => store.people.erase(person, by, { apply: options.yes === true }));
|
|
45
|
+
if (!plan.erased)
|
|
46
|
+
throw new CliError("confirmation_required", `${planText(plan)}\nnothing was changed — add --yes`, {
|
|
47
|
+
reason: "person.delete-confirm",
|
|
48
|
+
plan,
|
|
49
|
+
});
|
|
50
|
+
print(options.json, itemAnswer(plan), planText(plan));
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=delete-command.js.map
|