@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,167 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { resolvePaths } from "@wirecat/cli-base";
|
|
5
|
+
import { SKILL_TARGETS, skillPath, skillVersion } from "@wirecat/cli-base/skill";
|
|
6
|
+
import { appDoctorCommand, chosenTextModel, DEFAULT_TEXT_MODEL, DOCTOR_DEEP_OPTION, overrideSharedContract, privateFiles, rootOf, runsDirFor, sharedModelsDirectory, storePath, storeSummary, textModelsFile, withSqliteSidecars, } from "@wirecat/cli-core";
|
|
7
|
+
import { APP } from "../app.js";
|
|
8
|
+
import { inspectConfig } from "../config.js";
|
|
9
|
+
import { autoState, lastAutoRun, UNIT } from "../run/auto.js";
|
|
10
|
+
import { installer, PACKAGE } from "../update.js";
|
|
11
|
+
import { VERSION } from "../version.js";
|
|
12
|
+
/** The addresses an old config's `mail.accounts` names, to say which mailboxes the `mail` CLI should sync. */
|
|
13
|
+
const retiredMailAddresses = (mail) => {
|
|
14
|
+
const accounts = mail?.accounts;
|
|
15
|
+
if (!Array.isArray(accounts))
|
|
16
|
+
return [];
|
|
17
|
+
return accounts
|
|
18
|
+
.map((account) => account?.address)
|
|
19
|
+
.filter((address) => typeof address === "string");
|
|
20
|
+
};
|
|
21
|
+
const unitPaths = (unit) => [...(/^ExecStart=(.*)$/m.exec(unit)?.[1] ?? "").matchAll(/"((?:[^"\\]|\\.)*)"/g)]
|
|
22
|
+
.map(([, path]) => path?.replace(/\\(["\\])/g, "$1") ?? "")
|
|
23
|
+
.filter((path) => path.startsWith("/"));
|
|
24
|
+
/** Everything wcat needs, read from this computer only: no mail server, no messenger, no npm. */
|
|
25
|
+
export const diagnose = async (env, program, { deep = false } = {}) => {
|
|
26
|
+
const problems = [];
|
|
27
|
+
const paths = resolvePaths({ appName: APP.appName, prefix: APP.envPrefix, env });
|
|
28
|
+
// Config problems go to `config.issues`, the shape every WireCat doctor shares, not to `problems`.
|
|
29
|
+
const { config, ...configReport } = inspectConfig(env, program);
|
|
30
|
+
// The same files and folders the shared doctor checks; mail lives in the store.
|
|
31
|
+
const files = privateFiles({
|
|
32
|
+
files: [configReport.path, ...withSqliteSidecars(storePath(env))],
|
|
33
|
+
// A folder the owner chose with MESSAGING_STORE may rightly be shared, like the home folder itself.
|
|
34
|
+
dirs: [dirname(configReport.path), ...(env.MESSAGING_STORE ? [] : [dirname(storePath(env))]), runsDirFor(APP, env)],
|
|
35
|
+
});
|
|
36
|
+
const store = await storeSummary(env, { deep, command: "wcat", version: APP.version });
|
|
37
|
+
if ("damage" in store && store.damage)
|
|
38
|
+
problems.push({ what: store.damage.what, fix: "wcat store recover" });
|
|
39
|
+
else if ("error" in store && store.error)
|
|
40
|
+
problems.push({ what: `the store cannot be read: ${store.error}`, fix: "" });
|
|
41
|
+
if ("writable" in store && store.writable === false)
|
|
42
|
+
problems.push({ what: "the store is from a newer version than this wcat", fix: "wcat upgrade" });
|
|
43
|
+
if (config.mail !== undefined) {
|
|
44
|
+
const addresses = retiredMailAddresses(config.mail);
|
|
45
|
+
problems.push({
|
|
46
|
+
what: "wcat no longer imports mail, so the config's mail settings do nothing; the mail CLI syncs " +
|
|
47
|
+
`${addresses.length ? addresses.join(", ") : "each mailbox"} into the same store (mail <profile> session ` +
|
|
48
|
+
"start --address <address>, then mail <profile> sync), and the mail already stored stays",
|
|
49
|
+
fix: "wcat config unset mail",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
let textModel = DEFAULT_TEXT_MODEL;
|
|
53
|
+
try {
|
|
54
|
+
textModel = chosenTextModel(env).id;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
problems.push({
|
|
58
|
+
what: `the embedding model choice cannot be read: ${error instanceof Error ? error.message : String(error)}`,
|
|
59
|
+
fix: `fix text_models in ${textModelsFile(env)}, or remove it to go back to ${DEFAULT_TEXT_MODEL}`,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const modelDir = join(sharedModelsDirectory("text", env), textModel);
|
|
63
|
+
const model = existsSync(modelDir) && readdirSync(modelDir).length > 0;
|
|
64
|
+
const state = autoState(config);
|
|
65
|
+
const unitFile = join(env.XDG_CONFIG_HOME ?? join(env.HOME ?? homedir(), ".config"), "systemd", "user", `${UNIT}.service`);
|
|
66
|
+
const unit = existsSync(unitFile) ? readFileSync(unitFile, "utf8") : undefined;
|
|
67
|
+
const runs = unit ? unitPaths(unit) : [];
|
|
68
|
+
const missing = runs.filter((path) => !existsSync(path));
|
|
69
|
+
const last = lastAutoRun(env);
|
|
70
|
+
const failing = last && last.exitCode !== 0
|
|
71
|
+
? { since: last.failingSince ?? last.at, runs: last.failures ?? 1, reason: last.reason ?? null }
|
|
72
|
+
: null;
|
|
73
|
+
if (state.enabled && !unit)
|
|
74
|
+
problems.push({ what: "the timer is on in the config but not installed", fix: "wcat jobs start" });
|
|
75
|
+
if (missing.length > 0)
|
|
76
|
+
problems.push({ what: `the timer runs a program that is gone: ${missing.join(", ")}`, fix: "wcat jobs start" });
|
|
77
|
+
if (failing)
|
|
78
|
+
problems.push({ what: `the timer has failed ${failing.runs} runs since ${failing.since}`, fix: "wcat jobs status" });
|
|
79
|
+
const skills = SKILL_TARGETS.map((target) => {
|
|
80
|
+
const path = skillPath(target, APP.appName, env);
|
|
81
|
+
const version = existsSync(path) ? (skillVersion(readFileSync(path, "utf8")) ?? "unknown") : null;
|
|
82
|
+
return { target, path, version };
|
|
83
|
+
});
|
|
84
|
+
if (skills.some(({ version }) => version !== null && version !== VERSION))
|
|
85
|
+
problems.push({ what: "an installed skill is from another wcat version", fix: "wcat skill install --for all" });
|
|
86
|
+
return {
|
|
87
|
+
wcat: { version: VERSION, node: process.version, installed_by: installer() },
|
|
88
|
+
state: paths.state,
|
|
89
|
+
cache: paths.cache,
|
|
90
|
+
store,
|
|
91
|
+
search_model: { name: textModel, path: modelDir, present: model },
|
|
92
|
+
timer: { enabled: state.enabled, every: state.every, unit: unit ? unitFile : null, runs, failing },
|
|
93
|
+
skills,
|
|
94
|
+
files: files.checked
|
|
95
|
+
? { ...files, problems: files.problems.map(({ path, mode, want }) => ({ path, mode, want })) }
|
|
96
|
+
: files,
|
|
97
|
+
problems,
|
|
98
|
+
fixes: files.checked ? files.problems.map(({ fix }) => fix) : [],
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
const _yes = (value) => (value ? "yes" : "no");
|
|
102
|
+
const fileLines = (d) => d.files.checked
|
|
103
|
+
? d.files.problems.map(({ path, mode, want }) => `! ${path} is ${mode}, so others can read it; it should be ${want}`)
|
|
104
|
+
: [];
|
|
105
|
+
const onlineLine = ({ version }) => version.latest === null
|
|
106
|
+
? "online npm could not be reached"
|
|
107
|
+
: version.newer
|
|
108
|
+
? `online wcat ${version.latest} is published (this is ${version.current}) — wcat upgrade`
|
|
109
|
+
: `online wcat ${version.current} is the newest published`;
|
|
110
|
+
export const doctorText = (d) => [
|
|
111
|
+
`wcat ${d.wcat.version} on Node ${d.wcat.node}, installed by ${d.wcat.installed_by}`,
|
|
112
|
+
`config ${d.config.path}${d.config.found ? "" : " (none yet)"}`,
|
|
113
|
+
`state ${d.state}`,
|
|
114
|
+
`cache ${d.cache}`,
|
|
115
|
+
`store ${d.store.path}${!d.store.exists
|
|
116
|
+
? " (none yet; the first wcat sync makes it)"
|
|
117
|
+
: "schema" in d.store
|
|
118
|
+
? ` (schema ${d.store.schema}, wcat speaks ${d.store.speaks})`
|
|
119
|
+
: ""}`,
|
|
120
|
+
...("health" in d.store && d.store.health
|
|
121
|
+
? [
|
|
122
|
+
`health ${d.store.health.ok ? "ok" : "DAMAGED"}, checked ${d.store.health.covers}${d.store.health.checked === "quick" ? " (wcat doctor --deep reads every page)" : ""}`,
|
|
123
|
+
]
|
|
124
|
+
: []),
|
|
125
|
+
`search ${d.search_model.name} ${d.search_model.present ? "present" : "not downloaded — search is by words"}`,
|
|
126
|
+
`timer ${d.timer.enabled ? `on, every ${d.timer.every}` : "off"}`,
|
|
127
|
+
...d.skills.map((s) => `skill ${s.path} ${s.version === null ? "(not installed)" : `(${s.version})`}`),
|
|
128
|
+
...(d.online ? [onlineLine(d.online)] : []),
|
|
129
|
+
"",
|
|
130
|
+
...(d.problems.length + d.config.issues.length + fileLines(d).length === 0
|
|
131
|
+
? ["nothing needs attention"]
|
|
132
|
+
: [
|
|
133
|
+
...d.config.issues.map(({ what, fix }) => `! ${what}${fix ? ` — ${fix}` : ""}`),
|
|
134
|
+
...fileLines(d),
|
|
135
|
+
...d.problems.map(({ what, fix }) => `! ${what}${fix ? ` — ${fix}` : ""}`),
|
|
136
|
+
]),
|
|
137
|
+
].join("\n");
|
|
138
|
+
const configOf = (env, command) => {
|
|
139
|
+
const { config: _config, ...report } = inspectConfig(env, rootOf(command));
|
|
140
|
+
return report;
|
|
141
|
+
};
|
|
142
|
+
export const doctorCommand = () => overrideSharedContract(appDoctorCommand(APP, null, {
|
|
143
|
+
packageName: PACKAGE,
|
|
144
|
+
config: configOf,
|
|
145
|
+
local: async (env, command) => {
|
|
146
|
+
const { fixes, ...diagnosis } = await diagnose(env, rootOf(command), {
|
|
147
|
+
deep: command.opts().deep === true,
|
|
148
|
+
});
|
|
149
|
+
return {
|
|
150
|
+
fields: diagnosis,
|
|
151
|
+
notes: fixes.map((fix) => `to make it private: ${fix}`),
|
|
152
|
+
failing: diagnosis.problems.length > 0,
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
view: (item) => doctorText(item),
|
|
156
|
+
}), "wcat has no global --json, so doctor takes its own, and --deep reads every page of wcat's store.", (command) => {
|
|
157
|
+
command
|
|
158
|
+
.option("--deep", DOCTOR_DEEP_OPTION)
|
|
159
|
+
.option("--json", "print JSON; --json=id,title keeps only those fields")
|
|
160
|
+
.addHelpText("after", "\nReads this computer only, unless --online: the config, the store, the search " +
|
|
161
|
+
"model, the timer and the agent skill, each problem with the command that fixes it. --online also asks " +
|
|
162
|
+
"npm whether a newer wcat is published, and nothing else leaves this computer. Exits 1 when something " +
|
|
163
|
+
"other than the config file or a file mode needs attention; problems in the config file are listed in " +
|
|
164
|
+
"config.issues, and files or folders other users can read in files.problems, and neither changes the exit " +
|
|
165
|
+
"code.");
|
|
166
|
+
});
|
|
167
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join, relative } from "node:path";
|
|
3
|
+
import { resolvePaths } from "@wirecat/cli-base";
|
|
4
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
5
|
+
import { DOCUMENTS_LIST_QUERY, documentListRequest, isFolderProvider, LOCAL_READ, listDocumentSources, listDocuments, showDocument, withQuery, } from "@wirecat/cli-core";
|
|
6
|
+
import { answers, itemAnswer, listAnswer, plainText, withStore } from "../answer.js";
|
|
7
|
+
import { configPath } from "../config.js";
|
|
8
|
+
import { between, collect, positive } from "../options.js";
|
|
9
|
+
const NOTE = "\nEvery account holding documents is read: Drive accounts, notes folders, sources added by hand and imports. " +
|
|
10
|
+
"Newest change first; a text term keeps that order among what the notes search found. meta.accounts names what " +
|
|
11
|
+
"was read.";
|
|
12
|
+
/** The folders with an id in a config file's `notes.folders`, by id; nothing when the file does not read. */
|
|
13
|
+
const folderRoots = (file) => {
|
|
14
|
+
try {
|
|
15
|
+
const folders = JSON.parse(readFileSync(file, "utf8")).notes?.folders;
|
|
16
|
+
return Array.isArray(folders)
|
|
17
|
+
? folders.flatMap((folder) => folder && typeof folder.id === "string" && typeof folder.path === "string" ? [[folder.id, folder.path]] : [])
|
|
18
|
+
: [];
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* A notes folder's file opens from where the folder is on this computer, which only the files CLI's config knows, or
|
|
26
|
+
* wcat's own from before files took it over. The config names a folder by its stored account id; a row names its
|
|
27
|
+
* account as provider:account.
|
|
28
|
+
*/
|
|
29
|
+
const withLocalPaths = async (env, store) => {
|
|
30
|
+
const files = join(resolvePaths({ appName: "files-cli", prefix: "FILES", env }).config, "config.json");
|
|
31
|
+
const roots = new Map([...folderRoots(configPath(env)), ...folderRoots(files)]);
|
|
32
|
+
const folders = new Map((await store.listings.documentAccounts()).flatMap(({ id, provider, account }) => {
|
|
33
|
+
const root = roots.get(String(id));
|
|
34
|
+
return root === undefined ? [] : [[`${provider}:${account}`, root]];
|
|
35
|
+
}));
|
|
36
|
+
return (item) => {
|
|
37
|
+
if (item.local_path !== null || item.path === null || !isFolderProvider(item.source.provider))
|
|
38
|
+
return item;
|
|
39
|
+
const root = folders.get(item.source.source);
|
|
40
|
+
if (root === undefined)
|
|
41
|
+
return item;
|
|
42
|
+
const path = join(root, item.path);
|
|
43
|
+
// The path comes from the store: one that climbs out of the folder is not opened.
|
|
44
|
+
return relative(root, path).startsWith("..") ? item : { ...item, local_path: path };
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export const documentsCommand = (program, streams, env) => {
|
|
48
|
+
const { print } = answers(program, streams, env);
|
|
49
|
+
const documents = program
|
|
50
|
+
.command("documents")
|
|
51
|
+
.description("every document the store holds, of every account: Drive, notes folders, added sources, imports")
|
|
52
|
+
.summary("documents of every account");
|
|
53
|
+
withQuery(annotate(documents.command("list"), { effects: LOCAL_READ, output: { entity: "document_entry" } })
|
|
54
|
+
.description("documents of every account, newest change first, with their source, folder and kind")
|
|
55
|
+
.summary("documents of every account, newest first"), DOCUMENTS_LIST_QUERY)
|
|
56
|
+
.addHelpText("after", NOTE)
|
|
57
|
+
.option("--limit <n>", "documents per page, 1–500", between(1, 500), 50)
|
|
58
|
+
.option("--page <n>", "which page, from 1", positive, 1)
|
|
59
|
+
.option("--json", "print JSON; --json=ref,title keeps only those fields")
|
|
60
|
+
.action(async (words, { json, limit, page }, command) => {
|
|
61
|
+
const request = documentListRequest(words, { limit, page });
|
|
62
|
+
const { found, local } = await withStore(env, async (store) => ({
|
|
63
|
+
found: await listDocuments(store, request),
|
|
64
|
+
local: await withLocalPaths(env, store),
|
|
65
|
+
}));
|
|
66
|
+
const body = listAnswer("documents list", {
|
|
67
|
+
items: found.items.map(local),
|
|
68
|
+
limit,
|
|
69
|
+
page,
|
|
70
|
+
total: found.total,
|
|
71
|
+
// A capped total says only "at least": a full page then may have more after it.
|
|
72
|
+
has_more: request.offset + found.items.length < found.total.value ||
|
|
73
|
+
(found.total.relation === "gte" && found.items.length === limit),
|
|
74
|
+
args: { query: words.join(" ") || undefined, limit },
|
|
75
|
+
meta: { accounts: found.accounts },
|
|
76
|
+
});
|
|
77
|
+
print(json, body, plainText(body, command));
|
|
78
|
+
});
|
|
79
|
+
annotate(documents.command("tree"), { effects: LOCAL_READ, output: { entity: "document_source" } })
|
|
80
|
+
.description("the accounts holding documents, each with its folders and how many documents each holds")
|
|
81
|
+
.summary("accounts and folders holding documents, with counts")
|
|
82
|
+
.option("--source <accounts>", "only this provider:account, or every account of a provider; repeat for more", collect)
|
|
83
|
+
.option("--depth <n>", "folder levels to list, 0–20", between(0, 20), 3)
|
|
84
|
+
.option("--json", "print JSON; --json=source,count keeps only those fields")
|
|
85
|
+
.action(async ({ json, source, depth }, command) => {
|
|
86
|
+
const items = await withStore(env, (store) => listDocumentSources(store, { ...(source ? { sources: source } : {}), depth }));
|
|
87
|
+
const body = listAnswer("documents tree", {
|
|
88
|
+
items,
|
|
89
|
+
limit: Math.max(1, items.length),
|
|
90
|
+
has_more: false,
|
|
91
|
+
meta: { accounts: items.map(({ source }) => source) },
|
|
92
|
+
});
|
|
93
|
+
print(json, body, plainText(body, command));
|
|
94
|
+
});
|
|
95
|
+
annotate(documents.command("show"), { effects: LOCAL_READ, output: { entity: "document_entry_details" } })
|
|
96
|
+
.description("one document: a part of its text, its tags, the people it names and its meetings")
|
|
97
|
+
.summary("one document with its text")
|
|
98
|
+
.argument("<document>", "document:<id>, from documents list")
|
|
99
|
+
.option("--cursor <cursor>", "the character its text starts at: where the last read ended", between(0, Number.MAX_SAFE_INTEGER), 0)
|
|
100
|
+
.option("--max-chars <n>", "characters of text at most, 1–200000", between(1, 200_000), 20_000)
|
|
101
|
+
.option("--json", "print JSON; --json=ref,text keeps only those fields")
|
|
102
|
+
.action(async (ref, { json, cursor, maxChars }) => {
|
|
103
|
+
const item = await withStore(env, async (store) => (await withLocalPaths(env, store))(await showDocument(store, ref, { offset: cursor, limit: maxChars })));
|
|
104
|
+
print(json, itemAnswer(item));
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { domainListsCommand } from "@wirecat/cli-core";
|
|
2
|
+
import { answers } from "../answer.js";
|
|
3
|
+
import { APP } from "../app.js";
|
|
4
|
+
export const domainListsCommands = (program, streams, env) => {
|
|
5
|
+
const { print } = answers(program, streams, env);
|
|
6
|
+
program.addCommand(domainListsCommand(APP, {
|
|
7
|
+
env: () => env,
|
|
8
|
+
output: (body, command) => print(command.optsWithGlobals().json, body),
|
|
9
|
+
diagnostic: (line) => streams.diagnostic(line),
|
|
10
|
+
offline: () => program.opts().offline === true,
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { LOCAL_READ, withQuery } from "@wirecat/cli-core";
|
|
3
|
+
import { InvalidArgumentError } from "commander";
|
|
4
|
+
import { answers, itemAnswer, plainText, withStore } from "../answer.js";
|
|
5
|
+
import { accountsLine, EVENTS_NOTE, EVENTS_QUERY, listEvents, showEvent } from "./events.js";
|
|
6
|
+
const upTo1000 = (value) => {
|
|
7
|
+
const number = Number(value);
|
|
8
|
+
if (!Number.isInteger(number) || number < 1 || number > 1000)
|
|
9
|
+
throw new InvalidArgumentError("a whole number, 1 to 1000");
|
|
10
|
+
return number;
|
|
11
|
+
};
|
|
12
|
+
export const eventsCommand = (program, streams, env) => {
|
|
13
|
+
const { print } = answers(program, streams, env);
|
|
14
|
+
const events = program
|
|
15
|
+
.command("events")
|
|
16
|
+
.description("calendar events of every account in the store, phone calls included")
|
|
17
|
+
.summary("calendar events and phone calls of every account");
|
|
18
|
+
withQuery(annotate(events.command("list"), { effects: LOCAL_READ, partial: true })
|
|
19
|
+
.description("events of every calendar account in the store, latest start first: calendars and imported phone calls")
|
|
20
|
+
.summary("events and phone calls of every account, latest first"), EVENTS_QUERY)
|
|
21
|
+
.addHelpText("after", EVENTS_NOTE)
|
|
22
|
+
.option("--limit <n>", "events at most, 1–1000", upTo1000, 100)
|
|
23
|
+
.option("--json", "print JSON; --json=ref,title keeps only those fields")
|
|
24
|
+
.action(async (words, { json, limit }, command) => {
|
|
25
|
+
const body = await withStore(env, (store) => listEvents(store, words, limit));
|
|
26
|
+
const accounts = body.meta?.accounts ?? [];
|
|
27
|
+
print(json, body, `${accountsLine(accounts)}\n${plainText(body, command)}`);
|
|
28
|
+
});
|
|
29
|
+
annotate(events.command("show"), { effects: LOCAL_READ, output: { entity: "event" } })
|
|
30
|
+
.description("one event: its time, the accounts and calendars that hold it, and its attendees")
|
|
31
|
+
.argument("<ref>", "event:<id>")
|
|
32
|
+
.option("--json", "print JSON; --json=ref,title keeps only those fields")
|
|
33
|
+
.action(async (ref, { json }) => print(json, itemAnswer(await withStore(env, (store) => showEvent(store, ref)))));
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { dateRange, dayBoundary, timezoneOf } from "@wirecat/cli-base/query";
|
|
3
|
+
import { accountsMeta, calendarAccounts, eventItem, listQuery, nativeField, nativeTerms, termField, typedQuery, } from "@wirecat/cli-core";
|
|
4
|
+
import { listAnswer } from "../answer.js";
|
|
5
|
+
import { accountName } from "../store/source-list.js";
|
|
6
|
+
const LIST = "events list";
|
|
7
|
+
// cli-core 0.613 keeps its own list of these, EVENTS_QUERY and eventsFilter unexported.
|
|
8
|
+
const EVENT_TYPES = [
|
|
9
|
+
"default",
|
|
10
|
+
"out-of-office",
|
|
11
|
+
"focus",
|
|
12
|
+
"working-location",
|
|
13
|
+
"birthday",
|
|
14
|
+
"from-mail",
|
|
15
|
+
"call",
|
|
16
|
+
];
|
|
17
|
+
export const EVENTS_QUERY = {
|
|
18
|
+
entity: "event",
|
|
19
|
+
backend: "native",
|
|
20
|
+
fields: [
|
|
21
|
+
nativeField({
|
|
22
|
+
name: "starts_at",
|
|
23
|
+
type: "time",
|
|
24
|
+
operators: ["term", "range"],
|
|
25
|
+
example: "starts_at:[2026-11-02 TO 2026-11-07}",
|
|
26
|
+
}),
|
|
27
|
+
termField("account", "kw", 'account:"phone:pixel"', {
|
|
28
|
+
relation: "one calendar account, provider:account, or every account of a provider",
|
|
29
|
+
}),
|
|
30
|
+
termField("calendar", "kw", "calendar:Calls", { relation: "one calendar, by its id or its title" }),
|
|
31
|
+
termField("event_type", "enum", "event_type:call", {
|
|
32
|
+
values: EVENT_TYPES,
|
|
33
|
+
relation: "events with a copy of this kind; a phone's imported calls are call",
|
|
34
|
+
}),
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
/** Recent history matters as much as what comes next: imported calls are all in the past. */
|
|
38
|
+
const RECENT_DAYS = 30;
|
|
39
|
+
const AHEAD_DAYS = 7;
|
|
40
|
+
export const EVENTS_NOTE = `\nEvery calendar account in the store is read, phone imports included. Without starts_at: the last ${RECENT_DAYS} ` +
|
|
41
|
+
`days and the next ${AHEAD_DAYS}. Latest start first.`;
|
|
42
|
+
/** Whoever sent the invitation or shared the calendar wrote these; a call's title is the name the phone shows. */
|
|
43
|
+
const UNTRUSTED = ["title", "description", "location", "in"];
|
|
44
|
+
const readAccounts = async (store) => {
|
|
45
|
+
const held = await calendarAccounts(store);
|
|
46
|
+
const stored = await store.accounts.storedAccounts();
|
|
47
|
+
const read = [];
|
|
48
|
+
for (const key of held) {
|
|
49
|
+
const one = stored.find(({ provider, account }) => provider === key.provider && account === key.account);
|
|
50
|
+
if (one)
|
|
51
|
+
read.push({ id: one.id, key, calendars: await store.calendar.calendars(one.id) });
|
|
52
|
+
}
|
|
53
|
+
return read;
|
|
54
|
+
};
|
|
55
|
+
const narrowed = (accounts, value) => {
|
|
56
|
+
const chosen = accounts.filter(({ key }) => accountName(key) === value || key.provider === value);
|
|
57
|
+
if (chosen.length === 0)
|
|
58
|
+
throw new CliError("not_found", `account:${value} names no calendar account — the store holds ${accounts.map(({ key }) => accountName(key)).join(", ") || "none"}`, { reason: "events.account-unknown" });
|
|
59
|
+
return chosen;
|
|
60
|
+
};
|
|
61
|
+
/** One calendar among the accounts read: a title two accounts share is refused with each one's id, never picked. */
|
|
62
|
+
const calendarOf = (accounts, value) => {
|
|
63
|
+
const all = accounts.flatMap((account) => account.calendars.map((calendar) => ({ account, calendar })));
|
|
64
|
+
const byId = all.filter(({ calendar }) => String(calendar.id) === value);
|
|
65
|
+
const found = byId.length ? byId : all.filter(({ calendar }) => calendar.title === value);
|
|
66
|
+
if (found.length === 1)
|
|
67
|
+
return found[0];
|
|
68
|
+
if (found.length === 0)
|
|
69
|
+
throw new CliError("not_found", `calendar:${value} names no calendar in the accounts read`);
|
|
70
|
+
throw new CliError("validation_error", `calendar:${value} names ${found.length} calendars; give one by its id: ` +
|
|
71
|
+
found.map(({ account, calendar }) => `calendar:${calendar.id} (${accountName(account.key)})`).join(", "));
|
|
72
|
+
};
|
|
73
|
+
const localDate = (at, zone) => new Intl.DateTimeFormat("en-CA", { timeZone: zone, year: "numeric", month: "2-digit", day: "2-digit" }).format(at);
|
|
74
|
+
const plusDays = (date, days) => {
|
|
75
|
+
const [year, month, day] = date.split("-").map(Number);
|
|
76
|
+
return new Date(Date.UTC(year, month - 1, day + days)).toISOString().slice(0, 10);
|
|
77
|
+
};
|
|
78
|
+
const midnight = (date, zone) => dayBoundary(date, zone, false, { start: 0, end: date.length });
|
|
79
|
+
/** As cli-core's own events list reads a `starts_at` term: from `lower` on, and before `upper`. */
|
|
80
|
+
const startsWindow = (node, zone, now) => {
|
|
81
|
+
const range = node.operator === "range"
|
|
82
|
+
? dateRange(node.value, node.upper ?? "*", node.lower_inclusive !== false, node.upper_inclusive !== false, zone, node.span, now)
|
|
83
|
+
: dateRange(node.value, node.value, true, true, zone, node.span, now);
|
|
84
|
+
return {
|
|
85
|
+
...(range.lower === undefined ? {} : { lower: range.lower_inclusive ? range.lower : range.lower + 1 }),
|
|
86
|
+
...(range.upper === undefined ? {} : { upper: range.upper_inclusive ? range.upper + 1 : range.upper }),
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/** All-day events have days, not instants: the store compares them by these local days. */
|
|
90
|
+
const dated = (filter, zone) => {
|
|
91
|
+
if (filter.from !== undefined)
|
|
92
|
+
filter.fromDate = localDate(filter.from, zone);
|
|
93
|
+
if (filter.to !== undefined)
|
|
94
|
+
filter.toDate = plusDays(localDate(filter.to - 1, zone), 1);
|
|
95
|
+
if (filter.startsFrom !== undefined) {
|
|
96
|
+
const date = localDate(filter.startsFrom, zone);
|
|
97
|
+
filter.startsFromDate = midnight(date, zone) < filter.startsFrom ? plusDays(date, 1) : date;
|
|
98
|
+
}
|
|
99
|
+
return filter;
|
|
100
|
+
};
|
|
101
|
+
const windowMeta = (filter, zone) => {
|
|
102
|
+
const since = filter.startsFrom ?? filter.from;
|
|
103
|
+
return {
|
|
104
|
+
timezone: zone,
|
|
105
|
+
window: {
|
|
106
|
+
...(since === undefined ? {} : { since: new Date(since).toISOString() }),
|
|
107
|
+
...(filter.to === undefined ? {} : { until: new Date(filter.to - 1).toISOString() }),
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
const rowOf = (details, accounts) => {
|
|
112
|
+
const live = details.entries.filter(({ deletedAt }) => deletedAt === null);
|
|
113
|
+
const copies = live.length ? live : details.entries;
|
|
114
|
+
const held = accounts.flatMap((account) => account.calendars
|
|
115
|
+
.filter(({ id }) => copies.some(({ calendarId }) => calendarId === id))
|
|
116
|
+
.map((calendar) => ({ account: accountName(account.key), calendar: calendar.title ?? String(calendar.id) })));
|
|
117
|
+
return {
|
|
118
|
+
...eventItem(details.event),
|
|
119
|
+
ref: `event:${details.event.id}`,
|
|
120
|
+
event_type: copies.find(({ eventType }) => eventType !== null)?.eventType ?? "default",
|
|
121
|
+
accounts: [...new Set(held.map(({ account }) => account))],
|
|
122
|
+
in: held.map(({ account, calendar }) => `${account}/${calendar}`).join(", "),
|
|
123
|
+
untrusted: UNTRUSTED,
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
/** `wcat events list`: one list over every calendar account the store holds, latest start first. */
|
|
127
|
+
export const listEvents = async (store, words, limit, { now = Date.now(), zone = timezoneOf() } = {}) => {
|
|
128
|
+
const terms = nativeTerms(listQuery(typedQuery(words), EVENTS_QUERY, LIST), LIST);
|
|
129
|
+
const every = await readAccounts(store);
|
|
130
|
+
const account = terms.get("account");
|
|
131
|
+
let accounts = account ? narrowed(every, account.value) : every;
|
|
132
|
+
const filter = { newest: true };
|
|
133
|
+
const calendar = terms.get("calendar");
|
|
134
|
+
if (calendar) {
|
|
135
|
+
const found = calendarOf(accounts, calendar.value);
|
|
136
|
+
accounts = [found.account];
|
|
137
|
+
filter.calendarId = found.calendar.id;
|
|
138
|
+
}
|
|
139
|
+
const kind = terms.get("event_type");
|
|
140
|
+
if (kind)
|
|
141
|
+
filter.eventType = kind.value.toLowerCase();
|
|
142
|
+
const starts = terms.get("starts_at");
|
|
143
|
+
if (starts) {
|
|
144
|
+
const { lower, upper } = startsWindow(starts, zone, now);
|
|
145
|
+
if (lower !== undefined)
|
|
146
|
+
filter.startsFrom = lower;
|
|
147
|
+
if (upper !== undefined)
|
|
148
|
+
filter.to = upper;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const today = localDate(now, zone);
|
|
152
|
+
filter.from = midnight(plusDays(today, -RECENT_DAYS), zone);
|
|
153
|
+
filter.to = midnight(plusDays(today, AHEAD_DAYS + 1), zone);
|
|
154
|
+
}
|
|
155
|
+
dated(filter, zone);
|
|
156
|
+
const read = accounts.map(({ id, key }) => ({ id, key }));
|
|
157
|
+
const events = read.length
|
|
158
|
+
? await store.calendar.events({ ...filter, accountIds: read.map(({ id }) => id), limit: limit + 1 })
|
|
159
|
+
: [];
|
|
160
|
+
const rows = [];
|
|
161
|
+
for (const event of events.slice(0, limit)) {
|
|
162
|
+
const details = await store.calendar.event(event.id);
|
|
163
|
+
if (details)
|
|
164
|
+
rows.push(rowOf(details, accounts));
|
|
165
|
+
}
|
|
166
|
+
const body = listAnswer(LIST, { items: rows, limit, has_more: events.length > limit });
|
|
167
|
+
body.meta = {
|
|
168
|
+
...body.meta,
|
|
169
|
+
...(await accountsMeta(store.calendar, read, [], now)),
|
|
170
|
+
...windowMeta(filter, zone),
|
|
171
|
+
};
|
|
172
|
+
return body;
|
|
173
|
+
};
|
|
174
|
+
/** `wcat events show`: one event with its copies in every calendar account the store holds. */
|
|
175
|
+
export const showEvent = async (store, reference) => {
|
|
176
|
+
const text = reference.replace(/^event:/u, "");
|
|
177
|
+
if (!/^[1-9]\d*$/u.test(text))
|
|
178
|
+
throw new CliError("validation_error", "an event is event:<id>");
|
|
179
|
+
const details = await store.calendar.event(Number(text));
|
|
180
|
+
const accounts = await readAccounts(store);
|
|
181
|
+
const row = details && rowOf(details, accounts);
|
|
182
|
+
if (!details || !row?.accounts.length)
|
|
183
|
+
throw new CliError("not_found", `no event ${text} in any calendar account`);
|
|
184
|
+
return {
|
|
185
|
+
...row,
|
|
186
|
+
attendees: details.participants.map(({ email, name, response, organizer }) => ({
|
|
187
|
+
email,
|
|
188
|
+
name,
|
|
189
|
+
response,
|
|
190
|
+
organizer,
|
|
191
|
+
})),
|
|
192
|
+
untrusted: [...UNTRUSTED, "attendees.name"],
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
export const accountsLine = (accounts) => accounts.length ? `calendar accounts read: ${accounts.join(", ")}` : "no calendar account in the store";
|
|
196
|
+
//# sourceMappingURL=events.js.map
|