@wirecat/files-cli 0.0.0-stage → 0.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/CHANGELOG.md +23 -0
- package/LICENSE +204 -0
- package/README.md +68 -2
- package/contracts/wirecat.json +751 -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-GNDPV4HK.js +263 -0
- package/dist/bundle/files.js +21 -0
- package/dist/bundle/program-EN7Z757N.js +12291 -0
- package/dist/config.js +65 -0
- package/dist/entities.js +103 -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 +80 -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 +39 -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 +81 -0
- package/dist/notes/folders-command.js +172 -0
- package/dist/notes/folders.js +88 -0
- package/dist/notes/import.js +234 -0
- package/dist/notes/internal.js +51 -0
- package/dist/notes/links.js +44 -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/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 +98 -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 +261 -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 +156 -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
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { posix } from "node:path";
|
|
2
|
+
import { isReference } from "./dialects/common.js";
|
|
3
|
+
const fold = (value) => value.normalize("NFC").toLocaleLowerCase("en");
|
|
4
|
+
const stem = (path) => path.replace(/\.(md|markdown|txt|csv|tsv|pdf|docx|xlsx)$/i, "");
|
|
5
|
+
const aliasesOf = (frontMatter) => {
|
|
6
|
+
const value = frontMatter?.aliases ??
|
|
7
|
+
frontMatter?.alias;
|
|
8
|
+
if (typeof value === "string")
|
|
9
|
+
return [value];
|
|
10
|
+
return Array.isArray(value) ? value.filter((alias) => typeof alias === "string") : [];
|
|
11
|
+
};
|
|
12
|
+
export const documentOf = (note) => ({
|
|
13
|
+
id: note.id,
|
|
14
|
+
path: note.path,
|
|
15
|
+
aliases: aliasesOf(note.frontMatter),
|
|
16
|
+
});
|
|
17
|
+
/** The notes a written target names: by path (relative when it starts with `./` or `../`), else by file name or alias. */
|
|
18
|
+
export const notesNamed = (source, target, documents) => {
|
|
19
|
+
const normalized = stem(posix.normalize(target.replace(/\\/g, "/").replace(/^\//, "")));
|
|
20
|
+
const relative = stem(posix.normalize(posix.join(posix.dirname(source), normalized)));
|
|
21
|
+
const explicit = target.startsWith("./") || target.startsWith("../") || target.startsWith("/") || normalized.includes("/");
|
|
22
|
+
const preferred = target.startsWith("./") || target.startsWith("../") ? relative : normalized;
|
|
23
|
+
if (target === "")
|
|
24
|
+
return documents.filter((doc) => doc.path === source);
|
|
25
|
+
if (explicit)
|
|
26
|
+
return documents.filter((doc) => fold(stem(doc.path)) === fold(preferred));
|
|
27
|
+
const name = fold(stem(target));
|
|
28
|
+
return documents.filter((doc) => [stem(posix.basename(doc.path)), ...doc.aliases].some((known) => fold(known) === name));
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* What a file's links become in the store. A record (`person:…`, `msg:…`) is linked as written; a note
|
|
32
|
+
* named once is linked by id. A name no note has — or several have — stays as written, so the store can
|
|
33
|
+
* resolve it to a person the moment one by that name, alias or username appears.
|
|
34
|
+
*/
|
|
35
|
+
export const fileLinks = (source, links, documents) => links.map(({ target, anchor }) => {
|
|
36
|
+
const at = anchor === null ? {} : { anchor };
|
|
37
|
+
if (isReference(target))
|
|
38
|
+
return { to: target, kind: "links-to", ...at };
|
|
39
|
+
const named = notesNamed(source, target, documents);
|
|
40
|
+
return named.length === 1
|
|
41
|
+
? { to: `document:${named[0].id}`, kind: "links-to", ...at }
|
|
42
|
+
: { targetText: posix.basename(target.replace(/\\/g, "/")) || target, kind: "links-to", ...at };
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { notesReaching } from "./about.js";
|
|
2
|
+
const PRIORITY = ["about", "link", "through", "name"];
|
|
3
|
+
export const listNotes = async (store, filter) => {
|
|
4
|
+
const { offset, limit } = filter;
|
|
5
|
+
if (filter.about === undefined) {
|
|
6
|
+
const { about: _, ...rest } = filter;
|
|
7
|
+
return store.notes.notes(rest);
|
|
8
|
+
}
|
|
9
|
+
const { about } = filter;
|
|
10
|
+
const byRef = new Map();
|
|
11
|
+
for (const { note, via, anchor, text } of await notesReaching(store, about)) {
|
|
12
|
+
const known = byRef.get(note.ref);
|
|
13
|
+
const row = !known || PRIORITY.indexOf(via) < PRIORITY.indexOf(known.via) ? { ...known, ...note, via } : known;
|
|
14
|
+
if (anchor !== null && !row.anchors?.includes(anchor))
|
|
15
|
+
row.anchors = [...(row.anchors ?? []), anchor];
|
|
16
|
+
if (via === "name" && text !== null)
|
|
17
|
+
row.linkText = text;
|
|
18
|
+
byRef.set(note.ref, row);
|
|
19
|
+
}
|
|
20
|
+
const all = [...byRef.values()].sort((a, b) => b.createdAt.localeCompare(a.createdAt) || b.ref.localeCompare(a.ref));
|
|
21
|
+
return { items: all.slice(offset, offset + limit), hasMore: all.length > offset + limit };
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Files that moved between two listings: a path gone from `before` whose content hash appears at a path
|
|
3
|
+
* new in `after`. A hash shared by two gone or two new files names no single move, so it is left out —
|
|
4
|
+
* a wrong guess would hand one note's links and tags to another.
|
|
5
|
+
*/
|
|
6
|
+
export const detectRenames = (before, after) => {
|
|
7
|
+
const byHash = (paths, hashes) => {
|
|
8
|
+
const grouped = new Map();
|
|
9
|
+
for (const path of paths) {
|
|
10
|
+
const hash = hashes[path];
|
|
11
|
+
grouped.set(hash, [...(grouped.get(hash) ?? []), path]);
|
|
12
|
+
}
|
|
13
|
+
return grouped;
|
|
14
|
+
};
|
|
15
|
+
const gone = byHash(Object.keys(before).filter((path) => !(path in after)), before);
|
|
16
|
+
const added = byHash(Object.keys(after).filter((path) => !(path in before)), after);
|
|
17
|
+
return [...gone]
|
|
18
|
+
.flatMap(([hash, from]) => {
|
|
19
|
+
const to = added.get(hash);
|
|
20
|
+
return from.length === 1 && to?.length === 1 ? [{ from: from[0], to: to[0] }] : [];
|
|
21
|
+
})
|
|
22
|
+
.sort((a, b) => a.from.localeCompare(b.from));
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=renames.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { shownOf } from "@wirecat/cli-core";
|
|
2
|
+
export { searchNotes, } from "@wirecat/cli-core";
|
|
3
|
+
export const searchText = (result, offset = 0) => [
|
|
4
|
+
...(result.items.length === 0 ? [`No note holds "${result.query}". Run files sync if notes changed.`] : []),
|
|
5
|
+
...result.items.map((hit) => `${"key" in hit ? "key " : ""}${hit.path ?? hit.ref}${hit.found_by.length === 1 && hit.found_by[0] === "meaning" ? " (by meaning)" : ""}\n ${hit.excerpt}`),
|
|
6
|
+
...[shownOf(result.items.length, offset, result.total)].filter((line) => line !== undefined),
|
|
7
|
+
...(result.hasMore ? ["More notes match; raise --limit or ask for --page with the next number."] : []),
|
|
8
|
+
...(result.linked.length === 0
|
|
9
|
+
? []
|
|
10
|
+
: [
|
|
11
|
+
"",
|
|
12
|
+
"Linked from these notes",
|
|
13
|
+
...result.linked.map(({ ref, name, notes }) => ` ${name ?? ref} ${ref ?? "(nobody by that name yet)"} (${notes})`),
|
|
14
|
+
]),
|
|
15
|
+
].join("\n");
|
|
16
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { filesPaths } from "../paths.js";
|
|
4
|
+
const empty = () => ({ files: {}, documents: {} });
|
|
5
|
+
const fileOf = (env, id) => join(filesPaths(env).state, "folders", `${id}.json`);
|
|
6
|
+
/** `undefined` before this computer's first import of the folder. */
|
|
7
|
+
export const loadFolderState = (env, id) => {
|
|
8
|
+
try {
|
|
9
|
+
return { ...empty(), ...JSON.parse(readFileSync(fileOf(env, id), "utf8")) };
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
export const saveFolderState = (env, id, state) => {
|
|
16
|
+
const file = fileOf(env, id);
|
|
17
|
+
mkdirSync(join(file, ".."), { recursive: true });
|
|
18
|
+
writeFileSync(`${file}.tmp`, JSON.stringify(state));
|
|
19
|
+
renameSync(`${file}.tmp`, file);
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* After the folder's format changed: the next import parses every text note again, so tags and links read in the old
|
|
23
|
+
* format are replaced. A state file that already names its format needs nothing; one without it gets the old one.
|
|
24
|
+
*/
|
|
25
|
+
export const formatChanged = (env, id, previous) => {
|
|
26
|
+
const state = loadFolderState(env, id);
|
|
27
|
+
if (state?.format !== undefined)
|
|
28
|
+
return;
|
|
29
|
+
saveFolderState(env, id, { ...(state ?? empty()), format: previous });
|
|
30
|
+
};
|
|
31
|
+
/** Forgets what this computer saw of the folder, so a folder added again is read in full. */
|
|
32
|
+
export const dropFolderState = (env, id) => rmSync(fileOf(env, id), { force: true });
|
|
33
|
+
//# sourceMappingURL=state.js.map
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InvalidArgumentError } from "commander";
|
|
2
|
+
export const positive = (value) => {
|
|
3
|
+
const number = Number(value);
|
|
4
|
+
if (!Number.isInteger(number) || number < 1)
|
|
5
|
+
throw new InvalidArgumentError("a whole number above zero");
|
|
6
|
+
return number;
|
|
7
|
+
};
|
|
8
|
+
export const collect = (value, previous = []) => [...previous, value];
|
|
9
|
+
//# sourceMappingURL=options.js.map
|
package/dist/output.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { 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
|
+
//# sourceMappingURL=output.js.map
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { resolvePaths } from "@wirecat/cli-base";
|
|
2
|
+
import { IDENTITY } from "./identity.js";
|
|
3
|
+
/** files' own config, state and cache folders, with FILES_CONFIG_DIR and the others moving them. */
|
|
4
|
+
export const filesPaths = (env) => resolvePaths({ appName: IDENTITY.appName, prefix: IDENTITY.envPrefix, env });
|
|
5
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { pickPerson } from "@wirecat/cli-core";
|
|
3
|
+
const parsed = (reference) => {
|
|
4
|
+
const match = /^([a-z][a-z0-9-]*):(.+)$/.exec(reference.trim());
|
|
5
|
+
if (match === null)
|
|
6
|
+
throw new CliError("validation_error", `"${reference}" names no messenger — write it as <messenger>:<name or id>`, {
|
|
7
|
+
reason: "identity.no-messenger",
|
|
8
|
+
});
|
|
9
|
+
const [, provider = "", who = ""] = match;
|
|
10
|
+
return { provider, who };
|
|
11
|
+
};
|
|
12
|
+
/** `telegram:Ana`, `max:12345`, `email:ana@example.com` — the messenger is always named. */
|
|
13
|
+
export const identityOf = async (store, reference) => {
|
|
14
|
+
const { provider, who } = parsed(reference);
|
|
15
|
+
const people = await store.people.people(provider);
|
|
16
|
+
const exact = people.get(provider === "email" ? who.toLowerCase() : who);
|
|
17
|
+
return { provider, id: exact?.id ?? pickPerson(who, people).id };
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { loadConfigFile } from "@wirecat/cli-base";
|
|
4
|
+
import * as v from "valibot";
|
|
5
|
+
import { folderOfFile } from "../notes/bound.js";
|
|
6
|
+
import { folderNotes } from "../notes/import.js";
|
|
7
|
+
import { filesPaths } from "../paths.js";
|
|
8
|
+
const NotesMapSchema = v.record(v.string(), v.string());
|
|
9
|
+
const mapPath = (env) => join(filesPaths(env).config, "people-notes.json");
|
|
10
|
+
const donePath = (env) => join(filesPaths(env).state, "people-notes-imported.json");
|
|
11
|
+
/**
|
|
12
|
+
* Moves each entry of the old `people-notes.json` into the store as an `about` link, once. An entry whose
|
|
13
|
+
* note is not imported yet waits for a later run; the file itself is left as the owner wrote it.
|
|
14
|
+
*/
|
|
15
|
+
export const importNotesMap = async (store, env, folders) => {
|
|
16
|
+
if (!existsSync(mapPath(env)))
|
|
17
|
+
return 0;
|
|
18
|
+
const map = loadConfigFile(mapPath(env), NotesMapSchema, () => ({}));
|
|
19
|
+
let done = [];
|
|
20
|
+
try {
|
|
21
|
+
done = JSON.parse(readFileSync(donePath(env), "utf8"));
|
|
22
|
+
}
|
|
23
|
+
catch { }
|
|
24
|
+
const pending = Object.entries(map).filter(([uid]) => !done.includes(uid));
|
|
25
|
+
if (pending.length === 0)
|
|
26
|
+
return 0;
|
|
27
|
+
const byFolder = new Map();
|
|
28
|
+
let linked = 0;
|
|
29
|
+
for (const [uid, file] of pending) {
|
|
30
|
+
let place;
|
|
31
|
+
try {
|
|
32
|
+
place = folderOfFile(folders, file);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (!byFolder.has(place.folder.id))
|
|
38
|
+
byFolder.set(place.folder.id, new Map((await folderNotes(store, place.folder.id)).map((note) => [note.path, note.id])));
|
|
39
|
+
const id = byFolder.get(place.folder.id)?.get(place.path);
|
|
40
|
+
// An uid from the store before wirecat.db names nobody now: leave the entry waiting, never fail the run.
|
|
41
|
+
if (id === undefined || (await store.people.personByUid(uid)) === undefined)
|
|
42
|
+
continue;
|
|
43
|
+
// The map is the owner's own file from before links; moving it in decides nothing for them.
|
|
44
|
+
await store.notes.addLink({
|
|
45
|
+
from: `document:${id}`,
|
|
46
|
+
to: `person:${uid}`,
|
|
47
|
+
kind: "about",
|
|
48
|
+
origin: "owner",
|
|
49
|
+
by: "owner",
|
|
50
|
+
});
|
|
51
|
+
done.push(uid);
|
|
52
|
+
linked++;
|
|
53
|
+
}
|
|
54
|
+
mkdirSync(join(donePath(env), ".."), { recursive: true });
|
|
55
|
+
writeFileSync(donePath(env), JSON.stringify(done));
|
|
56
|
+
return linked;
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=notes-map.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
/**
|
|
3
|
+
* `person:me` as the owner's `person:<uid>`; any other reference as written. The store always holds an owner row; it is
|
|
4
|
+
* marked once an identity is linked to it.
|
|
5
|
+
*/
|
|
6
|
+
export const withOwner = async (store, reference) => {
|
|
7
|
+
if (reference.trim() !== "person:me")
|
|
8
|
+
return reference;
|
|
9
|
+
const owner = await store.people.owner();
|
|
10
|
+
if (owner === undefined || owner.identities.length === 0)
|
|
11
|
+
throw new CliError("not_found", "person:me: no person is marked as you in the store; mark yours with `tg <profile> contacts link <your id> me`", { reason: "person.no-owner" });
|
|
12
|
+
return `person:${owner.uid}`;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=owner.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { formatReference, looksLikeReference } from "@wirecat/cli-core";
|
|
2
|
+
import { identityOf } from "./identity.js";
|
|
3
|
+
import { withOwner } from "./owner.js";
|
|
4
|
+
/** A typed reference as written, or `<messenger>:<name or id>` turned into the person behind it. */
|
|
5
|
+
export const subjectOf = async (store, text) => {
|
|
6
|
+
const typed = (await withOwner(store, text)).trim();
|
|
7
|
+
if (typed.startsWith("person:")) {
|
|
8
|
+
const person = await store.people.personByUid(typed.slice("person:".length));
|
|
9
|
+
return person === undefined ? { ref: typed } : { ref: typed, person };
|
|
10
|
+
}
|
|
11
|
+
if (looksLikeReference(typed))
|
|
12
|
+
return { ref: typed };
|
|
13
|
+
const identity = await identityOf(store, text);
|
|
14
|
+
const person = await store.people.personOf(identity);
|
|
15
|
+
return person === undefined
|
|
16
|
+
? { ref: formatReference({ type: "contact", provider: identity.provider, id: identity.id }) }
|
|
17
|
+
: { ref: `person:${person.uid}`, person };
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=subject.js.map
|
package/dist/program.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { processStreams, resolvePaths } from "@wirecat/cli-base";
|
|
3
|
+
import { appDoctorCommand, appMcpCommand, appUpdate, commandsCommand, configCommand, createProgram as createSharedProgram, outputFor, run as runShared, runsCommand, skillCommand, upgradeCommand, } from "@wirecat/cli-core";
|
|
4
|
+
import { Command } from "commander";
|
|
5
|
+
import { trackAnswers } from "./answer.js";
|
|
6
|
+
import { configuration } from "./config.js";
|
|
7
|
+
import { declareOwnAnswers } from "./entities.js";
|
|
8
|
+
import { IDENTITY, PACKAGE, SKILL } from "./identity.js";
|
|
9
|
+
import { importCommand } from "./import/command.js";
|
|
10
|
+
import { isInstalledCopy, migrateFromMemo } from "./migrate.js";
|
|
11
|
+
import { notesCommand } from "./notes/command.js";
|
|
12
|
+
import { foldersCommand } from "./notes/folders-command.js";
|
|
13
|
+
import { searchCommand } from "./search.js";
|
|
14
|
+
import { sourcesCommand } from "./sources/command.js";
|
|
15
|
+
import { syncCommand } from "./sync.js";
|
|
16
|
+
import { provideTerminal } from "./terminal.js";
|
|
17
|
+
const update = appUpdate({
|
|
18
|
+
packageName: PACKAGE,
|
|
19
|
+
command: IDENTITY.command,
|
|
20
|
+
version: IDENTITY.version,
|
|
21
|
+
entry: import.meta.url,
|
|
22
|
+
statePath: (env) => join(resolvePaths({ appName: IDENTITY.appName, prefix: IDENTITY.envPrefix, env }).state, "update-check.json"),
|
|
23
|
+
// biome-ignore lint/plugin/no-own-settings: the update check runs before any command exists to give baseContext
|
|
24
|
+
enabled: (env) => configuration.resolveSettings({}, { env, needsProfile: false }).updateCheck,
|
|
25
|
+
offVariables: [`${IDENTITY.envPrefix}_NO_UPDATE_CHECK`],
|
|
26
|
+
});
|
|
27
|
+
const mcpCommand = () => appMcpCommand(IDENTITY, configuration, {
|
|
28
|
+
name: "notes folders",
|
|
29
|
+
untrusted: ["note text", "document text", "transcripts", "file names"],
|
|
30
|
+
permissionExample: "notes.add=deny",
|
|
31
|
+
skill: SKILL,
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* The file commands are built for one run, with that run's streams, environment and keyring: they read them when they
|
|
35
|
+
* act, not from cli-core's context.
|
|
36
|
+
*/
|
|
37
|
+
const fileCommands = (options) => {
|
|
38
|
+
const streams = options.streams ?? processStreams;
|
|
39
|
+
const env = options.env ?? process.env;
|
|
40
|
+
const keyring = options.keyring;
|
|
41
|
+
const root = new Command(IDENTITY.command);
|
|
42
|
+
notesCommand(root, streams, env);
|
|
43
|
+
foldersCommand(root, streams, env);
|
|
44
|
+
sourcesCommand(root, streams, env, {
|
|
45
|
+
...(options.fetchPage ? { fetch: options.fetchPage } : {}),
|
|
46
|
+
readers: { ...(options.readerFetch ? { fetch: options.readerFetch } : {}), ...(keyring ? { keyring } : {}) },
|
|
47
|
+
});
|
|
48
|
+
importCommand(root, streams, env, options.hear ? { hear: options.hear } : {});
|
|
49
|
+
syncCommand(root, streams, env, keyring);
|
|
50
|
+
searchCommand(root, streams, env);
|
|
51
|
+
trackAnswers(root);
|
|
52
|
+
declareOwnAnswers(root);
|
|
53
|
+
return [...root.commands];
|
|
54
|
+
};
|
|
55
|
+
export const definition = (options = {}) => ({
|
|
56
|
+
app: IDENTITY,
|
|
57
|
+
// The daily "a newer version exists" line after a command that succeeded; FILES_NO_UPDATE_CHECK turns it off.
|
|
58
|
+
update,
|
|
59
|
+
// The whole object: cli-core refuses a command by its key only when it gets the permission table too.
|
|
60
|
+
configuration,
|
|
61
|
+
firstScreen: {
|
|
62
|
+
pitch: "your notes folders, PDFs and transcripts in the shared local store, searchable by your agent.",
|
|
63
|
+
can: [
|
|
64
|
+
{ command: "folders add <path>", does: "give a notes folder or an Obsidian vault an id" },
|
|
65
|
+
{ command: "sync", does: "bring every notes folder up to date in the store" },
|
|
66
|
+
{ command: 'search notes "budget"', does: "notes by words and by meaning" },
|
|
67
|
+
{ command: "import <path> --account import:<name>", does: "a folder of PDFs, documents or recordings" },
|
|
68
|
+
{ command: "sources add <file or url>", does: "one file, web page or pasted text" },
|
|
69
|
+
{ command: "notes add <text>", does: "a note of your own about a person or a project" },
|
|
70
|
+
],
|
|
71
|
+
profile: false,
|
|
72
|
+
start: "files folders add <path>",
|
|
73
|
+
},
|
|
74
|
+
commands: () => [
|
|
75
|
+
...fileCommands(options),
|
|
76
|
+
commandsCommand(IDENTITY),
|
|
77
|
+
appDoctorCommand(IDENTITY, configuration, { packageName: PACKAGE }),
|
|
78
|
+
skillCommand(IDENTITY, SKILL),
|
|
79
|
+
mcpCommand(),
|
|
80
|
+
upgradeCommand(IDENTITY, PACKAGE, (command) => ({
|
|
81
|
+
...outputFor(command),
|
|
82
|
+
installer: () => update.installer({}),
|
|
83
|
+
latest: () => update.latest({}),
|
|
84
|
+
install: (argv) => update.runUpdate(argv, {}),
|
|
85
|
+
})),
|
|
86
|
+
configCommand(IDENTITY, configuration),
|
|
87
|
+
runsCommand(IDENTITY),
|
|
88
|
+
],
|
|
89
|
+
configure: (program) => provideTerminal(program, options.terminal),
|
|
90
|
+
prepare: (_program, environment) => {
|
|
91
|
+
if (!isInstalledCopy(process.argv[1]))
|
|
92
|
+
return;
|
|
93
|
+
migrateFromMemo(options.env ?? process.env, options.keyring ?? environment.keyring);
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
export const createProgram = (options) => createSharedProgram(definition(), options);
|
|
97
|
+
export const run = (argv, options = {}) => runShared(argv, definition(options), options);
|
|
98
|
+
//# sourceMappingURL=program.js.map
|
package/dist/progress.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const EVERY_MS = 500;
|
|
2
|
+
/**
|
|
3
|
+
* cli-core's `{"event":"progress","step":…}` stderr line, with counts a window can draw a bar by. Only with --json,
|
|
4
|
+
* at most every half second but always the first and last, and never a note's name: these lines reach the desktop
|
|
5
|
+
* app's logs.
|
|
6
|
+
*/
|
|
7
|
+
export const progressLine = (diagnostic, json, { step, unit, label }) => {
|
|
8
|
+
let last = Number.NEGATIVE_INFINITY;
|
|
9
|
+
return (done, total) => {
|
|
10
|
+
if (!json)
|
|
11
|
+
return;
|
|
12
|
+
const now = Date.now();
|
|
13
|
+
if (done !== total && now - last < EVERY_MS)
|
|
14
|
+
return;
|
|
15
|
+
last = now;
|
|
16
|
+
diagnostic(JSON.stringify({ event: "progress", step, done, total, unit, ...(label === undefined ? {} : { label }) }));
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=progress.js.map
|
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
|