@wirecat/files-cli 0.0.0-stage → 0.2.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 +52 -0
- package/LICENSE +204 -0
- package/README.md +68 -2
- package/contracts/wirecat.json +793 -0
- package/dist/answer.js +60 -0
- package/dist/app.js +6 -0
- package/dist/author.js +87 -0
- package/dist/bin/files.js +40 -0
- package/dist/bundle/chunk-3GCXH3WT.js +263 -0
- package/dist/bundle/files.js +21 -0
- package/dist/bundle/program-OBKXQ4VY.js +12479 -0
- package/dist/config.js +74 -0
- package/dist/doctor.js +33 -0
- package/dist/entities.js +104 -0
- package/dist/failure.js +21 -0
- package/dist/identity.js +27 -0
- package/dist/import/audio.js +96 -0
- package/dist/import/command.js +156 -0
- package/dist/import/external-id.js +44 -0
- package/dist/import/files.js +206 -0
- package/dist/import/readers.js +87 -0
- package/dist/index.js +3 -0
- package/dist/migrate.js +192 -0
- package/dist/notes/about.js +55 -0
- package/dist/notes/bound.js +41 -0
- package/dist/notes/command.js +241 -0
- package/dist/notes/dates.js +15 -0
- package/dist/notes/dialects/common.js +79 -0
- package/dist/notes/dialects/index.js +6 -0
- package/dist/notes/dialects/markdown.js +51 -0
- package/dist/notes/dialects/obsidian.js +33 -0
- package/dist/notes/dialects/types.js +2 -0
- package/dist/notes/embed.js +97 -0
- package/dist/notes/export.js +76 -0
- package/dist/notes/files.js +87 -0
- package/dist/notes/folders-command.js +172 -0
- package/dist/notes/folders.js +90 -0
- package/dist/notes/import.js +289 -0
- package/dist/notes/internal.js +51 -0
- package/dist/notes/links.js +46 -0
- package/dist/notes/list.js +23 -0
- package/dist/notes/renames.js +24 -0
- package/dist/notes/search.js +16 -0
- package/dist/notes/state.js +33 -0
- package/dist/options.js +9 -0
- package/dist/output.js +4 -0
- package/dist/paths.js +5 -0
- package/dist/people/command.js +92 -0
- package/dist/people/identity.js +19 -0
- package/dist/people/notes-map.js +58 -0
- package/dist/people/owner.js +14 -0
- package/dist/people/subject.js +19 -0
- package/dist/program.js +101 -0
- package/dist/progress.js +19 -0
- package/dist/reasons.js +187 -0
- package/dist/records/input.js +114 -0
- package/dist/records/receipt.js +25 -0
- package/dist/records/source.js +12 -0
- package/dist/refs.js +28 -0
- package/dist/run/lock.js +21 -0
- package/dist/save-help.js +3 -0
- package/dist/search.js +63 -0
- package/dist/sources/command.js +295 -0
- package/dist/sources/copy.js +32 -0
- package/dist/sources/mentions.js +78 -0
- package/dist/sources/read.js +262 -0
- package/dist/sources/readers/ai-model.js +74 -0
- package/dist/sources/readers/api.js +48 -0
- package/dist/sources/readers/claude-code.js +74 -0
- package/dist/sources/readers/codex.js +72 -0
- package/dist/sources/readers/index.js +10 -0
- package/dist/sources/readers/keys.js +31 -0
- package/dist/sources/readers/ollama.js +84 -0
- package/dist/sources/readers/process.js +49 -0
- package/dist/sources/readers/types.js +2 -0
- package/dist/sources/suggest-command.js +253 -0
- package/dist/sources/suggest.js +142 -0
- package/dist/sources/transcript.js +52 -0
- package/dist/store/group.js +8 -0
- package/dist/store/scope.js +25 -0
- package/dist/store/source-list.js +22 -0
- package/dist/sync.js +182 -0
- package/dist/terminal.js +16 -0
- package/dist/version.js +2 -0
- package/dist/wcat.js +4 -0
- package/package.json +89 -4
- package/skills/files-cli/SKILL.md +41 -0
package/dist/reasons.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { defineReasons } from "@wirecat/cli-base/standards";
|
|
2
|
+
/** The reasons files raises itself; cli-base's and cli-core's are merged in by `failureContext`. */
|
|
3
|
+
export const REASONS = defineReasons([
|
|
4
|
+
{
|
|
5
|
+
reason: "source.agent-fetch",
|
|
6
|
+
code: "permission_error",
|
|
7
|
+
message: "an agent over MCP cannot make files fetch an address",
|
|
8
|
+
details: [],
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
reason: "ref.bare-number",
|
|
12
|
+
code: "validation_error",
|
|
13
|
+
message: "{value} is a bare number, which names no one kind of record here; give a reference such as {suggestion}",
|
|
14
|
+
details: ["value", "suggestion"],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
reason: "decision.owner-unconfirmed",
|
|
18
|
+
code: "confirmation_required",
|
|
19
|
+
message: "--as-owner asks at a terminal, and nobody is at one to answer; the owner runs it there, without --json",
|
|
20
|
+
details: [],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
reason: "decision.decider-unknown",
|
|
24
|
+
code: "confirmation_required",
|
|
25
|
+
message: "nothing shows who decides; the owner decides at a terminal, an agent from its own session with --reason",
|
|
26
|
+
details: [],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
reason: "records.file-missing",
|
|
30
|
+
code: "not_found",
|
|
31
|
+
message: "no records file {path}: give a file that exists, or - for stdin",
|
|
32
|
+
details: ["path"],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
reason: "records.file-unreadable",
|
|
36
|
+
code: "validation_error",
|
|
37
|
+
message: "the records file {path} cannot be read: {why}",
|
|
38
|
+
details: ["path", "why"],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
reason: "sync.running",
|
|
42
|
+
code: "rate_limited",
|
|
43
|
+
message: "another files sync is running (process {pid}); try again when it ends",
|
|
44
|
+
details: ["pid"],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
reason: "folder.unbound",
|
|
48
|
+
code: "configuration_error",
|
|
49
|
+
message: "the notes folder {path} has no folder id; files folders add or files folders update gives it one",
|
|
50
|
+
details: ["path"],
|
|
51
|
+
},
|
|
52
|
+
{ reason: "folder.not-found", code: "not_found", message: "the store has no such folder of notes", details: [] },
|
|
53
|
+
{
|
|
54
|
+
reason: "folder.overlap",
|
|
55
|
+
code: "validation_error",
|
|
56
|
+
message: "{path} is inside or around {other}, which files already reads; remove one of them first",
|
|
57
|
+
details: ["path", "other"],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
reason: "folder.delete-notes",
|
|
61
|
+
code: "confirmation_required",
|
|
62
|
+
message: "removing the folder deletes {notes} of its notes from the store; nothing was changed — add --yes",
|
|
63
|
+
details: ["notes"],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
reason: "notes.folder-missing",
|
|
67
|
+
code: "not_found",
|
|
68
|
+
message: "the notes folder {path} is missing — connect its disk; if it moved, files folders update <id> <new path>",
|
|
69
|
+
details: ["path"],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
reason: "note.not-imported",
|
|
73
|
+
code: "not_found",
|
|
74
|
+
message: "the note is not imported; files sync",
|
|
75
|
+
details: [],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
reason: "import.too-many-files",
|
|
79
|
+
code: "validation_error",
|
|
80
|
+
message: "{path} holds more files than one import reads: import them by folder",
|
|
81
|
+
details: ["path"],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
reason: "mail.account-unknown",
|
|
85
|
+
code: "not_found",
|
|
86
|
+
message: "no stored mailbox by that address; the mail CLI syncs one",
|
|
87
|
+
details: ["account"],
|
|
88
|
+
},
|
|
89
|
+
{ reason: "person.not-found", code: "not_found", message: "the store has no person by that name", details: [] },
|
|
90
|
+
{
|
|
91
|
+
reason: "identity.not-found",
|
|
92
|
+
code: "not_found",
|
|
93
|
+
message: "no identity has that exact id; people show lists them",
|
|
94
|
+
details: [],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
reason: "identity.no-messenger",
|
|
98
|
+
code: "validation_error",
|
|
99
|
+
message: "the name has no messenger; write it as <messenger>:<name or id>",
|
|
100
|
+
details: [],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
reason: "deal.not-readable",
|
|
104
|
+
code: "not_found",
|
|
105
|
+
message: "the deal or lead is in a CRM copy whose sign-in may not read it (SEC-197)",
|
|
106
|
+
details: [],
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
reason: "reader.none-chosen",
|
|
110
|
+
code: "configuration_error",
|
|
111
|
+
message: "no reader is chosen for sources; the owner picks one with files sources readers set <reader>",
|
|
112
|
+
details: ["readers"],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
reason: "reader.owner-picks",
|
|
116
|
+
code: "permission_error",
|
|
117
|
+
message: "only the owner picks the reader that reads a source; an agent uses the one the owner chose",
|
|
118
|
+
details: [],
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
reason: "reader.unknown",
|
|
122
|
+
code: "validation_error",
|
|
123
|
+
message: "{reader} is not a reader files knows; it reads with one of {readers}",
|
|
124
|
+
details: ["reader", "readers"],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
reason: "reader.unavailable",
|
|
128
|
+
code: "configuration_error",
|
|
129
|
+
message: "the chosen reader cannot read now; files sources readers says why and what fixes it",
|
|
130
|
+
details: [],
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
reason: "reader.address-refused",
|
|
134
|
+
code: "validation_error",
|
|
135
|
+
message: "the reader's address must be on this computer (localhost, 127.x.x.x or [::1]); --base-url is Ollama's only",
|
|
136
|
+
details: [],
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
reason: "reader.model-missing",
|
|
140
|
+
code: "configuration_error",
|
|
141
|
+
message: "the reader needs a model the owner names; files sources readers set <reader> --model <model>",
|
|
142
|
+
details: [],
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
reason: "reader.ai-not-set",
|
|
146
|
+
code: "configuration_error",
|
|
147
|
+
message: "no AI model is chosen for every tool; wcat models ai set <provider> --model <model> chooses one",
|
|
148
|
+
details: [],
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
reason: "reader.no-key",
|
|
152
|
+
code: "authentication_error",
|
|
153
|
+
message: "no API key is kept for the reader's provider; wcat models ai set <provider> --secret-stdin keeps one",
|
|
154
|
+
details: [],
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
reason: "reader.not-running",
|
|
158
|
+
code: "provider_unavailable",
|
|
159
|
+
message: "the local model server is not running on this computer; start it, then try again",
|
|
160
|
+
details: [],
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
reason: "reader.timeout",
|
|
164
|
+
code: "timeout",
|
|
165
|
+
message: "the reader gave no answer in time; try again, or a smaller source",
|
|
166
|
+
details: [],
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
reason: "reader.limit",
|
|
170
|
+
code: "rate_limited",
|
|
171
|
+
message: "the reader's provider says the limit is reached; try again later",
|
|
172
|
+
details: [],
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
reason: "reader.failed",
|
|
176
|
+
code: "invalid_response",
|
|
177
|
+
message: "the reader failed; check its sign-in, key, model and credit, then try again",
|
|
178
|
+
details: [],
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
reason: "reader.unusable-answer",
|
|
182
|
+
code: "invalid_response",
|
|
183
|
+
message: "the reader's answer was not the JSON files asked for; nothing was staged, so try again",
|
|
184
|
+
details: [],
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
//# sourceMappingURL=reasons.js.map
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { open } from "node:fs/promises";
|
|
2
|
+
import { CliError } from "@wirecat/cli-base";
|
|
3
|
+
import { envelopeOfText, ingest, ingestLines, ingestVcard, isVcard, jsonlLines, } from "@wirecat/cli-core";
|
|
4
|
+
/** A vCard address book is a phone's contacts: they go under the seeded `phone` provider, one account per device. */
|
|
5
|
+
const PHONE = "phone";
|
|
6
|
+
const BOM = /^\uFEFF/;
|
|
7
|
+
const errnoOf = (error) => typeof error === "object" && error !== null && "code" in error ? String(error.code) : undefined;
|
|
8
|
+
/** A file opened now, so a missing one fails before anything is read; its errors come as answers, not as errno. */
|
|
9
|
+
const linesOf = async (file, stdin) => {
|
|
10
|
+
if (file === "-")
|
|
11
|
+
return jsonlLines(stdin);
|
|
12
|
+
try {
|
|
13
|
+
const handle = await open(file);
|
|
14
|
+
if (!(await handle.stat()).isFile()) {
|
|
15
|
+
await handle.close();
|
|
16
|
+
throw Object.assign(new Error(`${file} is a folder`), { code: "EISDIR" });
|
|
17
|
+
}
|
|
18
|
+
return jsonlLines(handle.createReadStream({ encoding: "utf8" }));
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (errnoOf(error) === "ENOENT")
|
|
22
|
+
throw new CliError("not_found", `no records file ${file}: give a file that exists, or - for stdin`, {
|
|
23
|
+
reason: "records.file-missing",
|
|
24
|
+
path: file,
|
|
25
|
+
});
|
|
26
|
+
const why = errnoOf(error) === "EISDIR" ? "it is a folder" : errnoOf(error) === "EACCES" ? "no permission" : "unreadable";
|
|
27
|
+
throw new CliError("validation_error", `the records file ${file} cannot be read: ${why}`, {
|
|
28
|
+
reason: "records.file-unreadable",
|
|
29
|
+
path: file,
|
|
30
|
+
why,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/** A JSONL file's first line: an object holding no `records`. */
|
|
35
|
+
const headerOf = (line) => {
|
|
36
|
+
try {
|
|
37
|
+
const value = JSON.parse(line);
|
|
38
|
+
return value && typeof value === "object" && !Array.isArray(value) && !("records" in value)
|
|
39
|
+
? value
|
|
40
|
+
: undefined;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/** `sheet:rentals` names the envelope's provider and account, as records list and link take it. */
|
|
47
|
+
const accountIn = (envelope, given) => {
|
|
48
|
+
const provider = envelope?.source?.provider;
|
|
49
|
+
return typeof provider === "string" && given.startsWith(`${provider}:`) ? given.slice(provider.length + 1) : given;
|
|
50
|
+
};
|
|
51
|
+
const deviceOf = (given) => {
|
|
52
|
+
const at = given.indexOf(":");
|
|
53
|
+
if (at < 0)
|
|
54
|
+
return given;
|
|
55
|
+
if (given.slice(0, at) !== PHONE)
|
|
56
|
+
throw new CliError("validation_error", "a vCard file holds a phone's contacts: --account phone:<device>", {
|
|
57
|
+
param: "--account",
|
|
58
|
+
});
|
|
59
|
+
return given.slice(at + 1);
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Imports a records file or stdin. JSONL streams, a record at a time, so a file of any length fits in memory; a JSON
|
|
63
|
+
* envelope and a vCard address book are read whole, as one envelope each. A CSV sheet is a document to `files import`. `onIssue` hears every refusal as it
|
|
64
|
+
* happens, also those past the receipt's capped lists.
|
|
65
|
+
*/
|
|
66
|
+
export const importRecords = async (store, { file, stdin, account, dryRun, onIssue, }) => {
|
|
67
|
+
const iterator = (await linesOf(file, stdin))[Symbol.asyncIterator]();
|
|
68
|
+
const before = [];
|
|
69
|
+
let next = await iterator.next();
|
|
70
|
+
while (!next.done && next.value.replace(BOM, "").trim() === "") {
|
|
71
|
+
before.push(next.value);
|
|
72
|
+
next = await iterator.next();
|
|
73
|
+
}
|
|
74
|
+
async function* rest() {
|
|
75
|
+
for (let line = await iterator.next(); !line.done; line = await iterator.next())
|
|
76
|
+
yield line.value;
|
|
77
|
+
}
|
|
78
|
+
const whole = async (first) => {
|
|
79
|
+
const lines = [...before, ...first];
|
|
80
|
+
for await (const line of rest())
|
|
81
|
+
lines.push(line);
|
|
82
|
+
return lines.join("\n");
|
|
83
|
+
};
|
|
84
|
+
if (next.done)
|
|
85
|
+
return ingest(store, envelopeOfText(before.join("\n")), { account, dryRun, onIssue });
|
|
86
|
+
const first = next.value.replace(BOM, "");
|
|
87
|
+
if (isVcard(first)) {
|
|
88
|
+
const { vcard, ...receipt } = await ingestVcard(store, await whole([first]), {
|
|
89
|
+
account: deviceOf(account),
|
|
90
|
+
provider: PHONE,
|
|
91
|
+
batchId: `vcard-${new Date().toISOString()}`,
|
|
92
|
+
dryRun,
|
|
93
|
+
onIssue,
|
|
94
|
+
});
|
|
95
|
+
return { ...receipt, vcard: vcard.map((one) => ({ ...one, card: one.card + 1 })) };
|
|
96
|
+
}
|
|
97
|
+
const header = headerOf(first);
|
|
98
|
+
if (header !== undefined) {
|
|
99
|
+
async function* all() {
|
|
100
|
+
// A refused header stops the stream at its first line; the file is closed here, not when it is collected.
|
|
101
|
+
try {
|
|
102
|
+
yield first;
|
|
103
|
+
yield* rest();
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
await iterator.return?.();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return ingestLines(store, all(), { account: accountIn(header, account), dryRun, onIssue });
|
|
110
|
+
}
|
|
111
|
+
const envelope = envelopeOfText(await whole([first]));
|
|
112
|
+
return ingest(store, envelope, { account: accountIn(envelope, account), dryRun, onIssue });
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=input.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The review kinds of what the import proposed, as `wcat review kind:` takes them: each ref's prefix. */
|
|
2
|
+
const kindsOf = (proposed) => [...new Set(proposed.map((ref) => ref.slice(0, ref.indexOf(":"))))];
|
|
3
|
+
/** The envelope's root is `/`: an empty JSON pointer would break the answer's issue shape. */
|
|
4
|
+
const pointerOf = (pointer) => pointer || "/";
|
|
5
|
+
const refusedLine = (one) => `refused ${pointerOf(one.pointer)} · ${one.message} (${one.code})`;
|
|
6
|
+
export const receiptText = (receipt) => [
|
|
7
|
+
`${receipt.dryRun ? "would import" : "imported"} ${receipt.source?.batchId ?? "nothing"}: ` +
|
|
8
|
+
`${receipt.created} created, ${receipt.updated} updated, ${receipt.unchanged} unchanged, ` +
|
|
9
|
+
`${receipt.deleted} deleted, ${receipt.refused} refused`,
|
|
10
|
+
...(receipt.proposed.length
|
|
11
|
+
? [
|
|
12
|
+
`proposed for your review (wcat review list kind:${kindsOf(receipt.proposed).join(",")}): ` +
|
|
13
|
+
receipt.proposed.join(" "),
|
|
14
|
+
]
|
|
15
|
+
: []),
|
|
16
|
+
...receipt.waiting.map((one) => `waiting ${one.key}: no entity yet for ${one.missing.join(", ")}`),
|
|
17
|
+
...receipt.unmatched.map((one) => `unmatched ${one.key}: ${one.candidates.length ? `could be ${one.candidates.join(" or ")}` : one.reason}; ` +
|
|
18
|
+
"you say which with wcat records link"),
|
|
19
|
+
...receipt.flagged.map((one) => `changed at the source ${one.key}: ${one.entity} kept as it was`),
|
|
20
|
+
...receipt.ignored.map((one) => `kept as data only ${one.key} ${one.pointer} (${one.reason})`),
|
|
21
|
+
...(receipt.vcard ?? []).map((one) => `notice card ${one.card}: ${one.message}`),
|
|
22
|
+
...receipt.errors.map(refusedLine),
|
|
23
|
+
...(receipt.truncated ? ["the lists stop at 1000 entries each; the counts are exact"] : []),
|
|
24
|
+
].join("\n");
|
|
25
|
+
//# sourceMappingURL=receipt.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
/** `sheet:rentals`: records are kept per source, so a read or a mapping names its provider and account. */
|
|
3
|
+
export const sourceOf = (account) => {
|
|
4
|
+
const [provider = "", ...rest] = (account ?? "").trim().split(":");
|
|
5
|
+
const name = rest.join(":");
|
|
6
|
+
if (!provider || !name)
|
|
7
|
+
throw new CliError("validation_error", "name the source as --account <provider>:<account>, such as sheet:rentals", {
|
|
8
|
+
param: "--account",
|
|
9
|
+
});
|
|
10
|
+
return { provider, account: name };
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=source.js.map
|
package/dist/refs.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
const BARE = /^\d+$/;
|
|
3
|
+
const either = (words) => words.length < 2 ? (words[0] ?? "") : `${words.slice(0, -1).join(", ")} or ${words.at(-1)}`;
|
|
4
|
+
/**
|
|
5
|
+
* An argument that takes several kinds refuses a bare number (NEED-2140 A): the same words would change meaning as
|
|
6
|
+
* the store grows. The refusal names only the references that exist, from one read of the store.
|
|
7
|
+
*/
|
|
8
|
+
export const refuseBareNumber = async (store, text, kinds, options = {}) => {
|
|
9
|
+
const value = text.trim();
|
|
10
|
+
if (!BARE.test(value))
|
|
11
|
+
return;
|
|
12
|
+
const candidates = kinds.map((kind) => `${kind}:${value}`);
|
|
13
|
+
const found = await store.refs.summaries(candidates);
|
|
14
|
+
const existing = candidates.filter((ref) => {
|
|
15
|
+
const state = found.get(ref)?.state;
|
|
16
|
+
return state !== undefined && state !== "unavailable";
|
|
17
|
+
});
|
|
18
|
+
const guess = existing.length
|
|
19
|
+
? `did you mean ${either(existing)}?`
|
|
20
|
+
: `no ${either(kinds.map((kind) => (kind === "msg" ? "message" : kind)))} has id ${value}`;
|
|
21
|
+
const path = options.path ? `; to read a file named ${value}, give its path: ./${value}` : "";
|
|
22
|
+
throw new CliError("validation_error", `"${value}" is a bare number; ${guess}${path}`, {
|
|
23
|
+
reason: "ref.bare-number",
|
|
24
|
+
value,
|
|
25
|
+
suggestion: existing[0] ?? candidates[0],
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=refs.js.map
|
package/dist/run/lock.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { CliError } from "@wirecat/cli-base";
|
|
3
|
+
import { releaseLock, takeLock } from "@wirecat/cli-core";
|
|
4
|
+
import { filesPaths } from "../paths.js";
|
|
5
|
+
/** Runs one sync at a time: `files sync` by hand and from the timer share this lock. */
|
|
6
|
+
export const withImportLock = async (env, work) => {
|
|
7
|
+
const lock = join(filesPaths(env).state, "import.lock");
|
|
8
|
+
const holder = takeLock(lock, { pid: process.pid, startedAt: new Date().toISOString() });
|
|
9
|
+
if (holder !== undefined)
|
|
10
|
+
throw new CliError("rate_limited", `another files sync is running (process ${holder.pid}); try again when it ends`, {
|
|
11
|
+
reason: "sync.running",
|
|
12
|
+
pid: holder.pid,
|
|
13
|
+
});
|
|
14
|
+
try {
|
|
15
|
+
return await work();
|
|
16
|
+
}
|
|
17
|
+
finally {
|
|
18
|
+
releaseLock(lock, process.pid);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=lock.js.map
|
package/dist/search.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { annotate } from "@wirecat/cli-base/commands";
|
|
2
|
+
import { LOCAL_READ, noteHitItem, searchNotesOf } from "@wirecat/cli-core";
|
|
3
|
+
import { InvalidArgumentError } from "commander";
|
|
4
|
+
import { answers, listAnswer, withStore } from "./answer.js";
|
|
5
|
+
import { APP } from "./app.js";
|
|
6
|
+
import { searchText } from "./notes/search.js";
|
|
7
|
+
import { positive } from "./options.js";
|
|
8
|
+
import { OWN_NOTES } from "./store/group.js";
|
|
9
|
+
const meaningMissed = (why, exact = false) => why === undefined || exact ? [] : [{ field: "found_by", why }];
|
|
10
|
+
const notesAnswer = (found, limit, page, args = {}) => listAnswer("search notes", {
|
|
11
|
+
items: found.items.map(noteHitItem),
|
|
12
|
+
limit,
|
|
13
|
+
has_more: found.hasMore && found.nextOffset !== undefined,
|
|
14
|
+
page,
|
|
15
|
+
...(found.total ? { total: found.total } : {}),
|
|
16
|
+
args,
|
|
17
|
+
missing: meaningMissed(found.meaning_skipped, args.exact === true),
|
|
18
|
+
});
|
|
19
|
+
/** `files search notes`: the notes in the store, by words and, with the local model, by meaning. */
|
|
20
|
+
export const searchCommand = (program, streams, env) => {
|
|
21
|
+
const { print } = answers(program, streams, env);
|
|
22
|
+
const group = program.command("search").description("search the notes in the local store");
|
|
23
|
+
annotate(group.command("notes"), { effects: LOCAL_READ, output: { entity: "note", view: "hit" } })
|
|
24
|
+
.description("native notes by words and, with the local model, meaning")
|
|
25
|
+
.argument("<query...>", "words, phrases, Boolean operators and field queries")
|
|
26
|
+
.addHelpText("after", "\nsource:internal keeps the notes you wrote with notes add, source:file the notes from a folder — 'budget source:internal'." +
|
|
27
|
+
"\n--source notes:<folder id> is different: it chooses which notes accounts are read." +
|
|
28
|
+
"\nFields in the query or in --filter (tag:, date:) hold for every hit, found by words or by meaning; a query of" +
|
|
29
|
+
"\nfields alone lists the matching notes, newest first — 'budget tag:work', 'date:today'." +
|
|
30
|
+
"\n--json: each note's reference is ref (note: or document:).")
|
|
31
|
+
.option("--limit <n>", "most results, at most 100", (value) => {
|
|
32
|
+
const limit = positive(value);
|
|
33
|
+
if (limit > 100)
|
|
34
|
+
throw new InvalidArgumentError("at most 100");
|
|
35
|
+
return limit;
|
|
36
|
+
}, 20)
|
|
37
|
+
.option("--page <n>", "which page, from 1", positive, 1)
|
|
38
|
+
.option("--exact", "words as written; skip meaning search")
|
|
39
|
+
.option("--timezone <zone>", "IANA timezone for calendar date boundaries")
|
|
40
|
+
.option("--filter <query>", "another query every note must match")
|
|
41
|
+
.option("--source <accounts>", "only these notes accounts, separated by commas: notes:internal for the notes you wrote, notes:<folder id> " +
|
|
42
|
+
"as a hit shows it, or notes")
|
|
43
|
+
.action(async (words, options) => {
|
|
44
|
+
const text = words.join(" ");
|
|
45
|
+
const answer = await withStore(env, (store) => searchNotesOf(store, OWN_NOTES, text, {
|
|
46
|
+
limit: options.limit,
|
|
47
|
+
offset: (options.page - 1) * options.limit,
|
|
48
|
+
env,
|
|
49
|
+
app: APP,
|
|
50
|
+
...(options.filter === undefined ? {} : { filter: options.filter }),
|
|
51
|
+
...(options.source === undefined ? {} : { accounts: options.source }),
|
|
52
|
+
...(options.exact ? { exact: true } : {}),
|
|
53
|
+
...(options.timezone === undefined ? {} : { timezone: options.timezone }),
|
|
54
|
+
}));
|
|
55
|
+
if (answer.meaning_skipped && options.exact !== true)
|
|
56
|
+
streams.diagnostic(`Searched by words only: ${answer.meaning_skipped}\n`);
|
|
57
|
+
for (const { source, reason } of answer.skipped)
|
|
58
|
+
streams.diagnostic(`${source} not searched: ${reason}\n`);
|
|
59
|
+
const { limit, page, ...rest } = options;
|
|
60
|
+
print(true, notesAnswer(answer, limit, page, { query: text, ...rest }), searchText(answer, (page - 1) * limit));
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=search.js.map
|