@wirecat/cli-core 0.737.0 → 0.739.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/cli/documents/file-edit.js +79 -34
  3. package/dist/cli/documents/file-update.d.ts +5 -0
  4. package/dist/cli/documents/index.d.ts +1 -0
  5. package/dist/cli/documents/index.js +1 -0
  6. package/dist/cli/documents/library.js +3 -1
  7. package/dist/cli/documents/rekey.d.ts +22 -0
  8. package/dist/cli/documents/rekey.js +25 -0
  9. package/dist/cli/documents/words.d.ts +1 -1
  10. package/dist/cli/setup-command.js +4 -2
  11. package/dist/cli/token-session.d.ts +4 -2
  12. package/dist/cli/token-session.js +8 -4
  13. package/dist/documents/file-mirror-model.d.ts +4 -1
  14. package/dist/documents/model.d.ts +6 -0
  15. package/dist/errors/reasons.js +2 -15
  16. package/dist/errors/sftp-reasons.d.ts +5 -0
  17. package/dist/errors/sftp-reasons.js +15 -0
  18. package/dist/office/create.d.ts +38 -7
  19. package/dist/office/create.js +84 -20
  20. package/dist/office/index.d.ts +1 -1
  21. package/dist/services/documents/file-text.d.ts +4 -1
  22. package/dist/services/documents/file-text.js +16 -2
  23. package/dist/services/documents/ingestion.d.ts +5 -0
  24. package/dist/services/documents/ingestion.js +21 -1
  25. package/dist/services/documents/plan.js +143 -101
  26. package/dist/services/files/guarded-write.d.ts +6 -0
  27. package/dist/services/files/guarded-write.js +7 -1
  28. package/dist/services/files/mirror.js +2 -3
  29. package/dist/services/metadata.d.ts +1 -1
  30. package/dist/setup/plain.d.ts +7 -4
  31. package/dist/setup/plain.js +7 -5
  32. package/dist/store/sqlite/file-note-rekey.d.ts +8 -0
  33. package/dist/store/sqlite/file-note-rekey.js +47 -0
  34. package/dist/store/sqlite/notes.d.ts +7 -2
  35. package/dist/store/sqlite/notes.js +4 -1
  36. package/dist/terminal/hyperlink.d.ts +8 -0
  37. package/dist/terminal/hyperlink.js +21 -0
  38. package/package.json +1 -1
@@ -0,0 +1,8 @@
1
+ import type { CacheDatabase } from "../driver.js";
2
+ /**
3
+ * Readies the document at `from` to move to `target`, the path of the id its source gave the file after a replace, so
4
+ * it keeps its id and with it the tags, the notes about it and its links. A sync that ran between the replace and this
5
+ * call took the document out at `from` and filed the file anew at `target`: the new text joins the old document, the
6
+ * new one goes, and the old one is live again. False when nothing was ever at `from`.
7
+ */
8
+ export declare const foldRekeyed: (database: CacheDatabase, folder: number, from: string, target: string, at: number) => boolean;
@@ -0,0 +1,47 @@
1
+ import { keepRevision, logDocumentChange } from "./document-history.js";
2
+ import { deleteDocumentRow } from "./evidence-signature.js";
3
+ const CONTENT = ["title", "body", "front_matter", "content_hash", "metadata", "language"];
4
+ const documentAt = (database, folder, path) => {
5
+ const place = database
6
+ .prepare("SELECT document_id FROM files WHERE account_id = ? AND external_id = ? AND kind <> 'folder'")
7
+ .get(folder, path);
8
+ return place?.document_id != null
9
+ ? database.prepare("SELECT * FROM documents WHERE id = ?").get(Number(place.document_id))
10
+ : database.prepare("SELECT * FROM documents WHERE account_id = ? AND external_id = ?").get(folder, path);
11
+ };
12
+ /**
13
+ * Readies the document at `from` to move to `target`, the path of the id its source gave the file after a replace, so
14
+ * it keeps its id and with it the tags, the notes about it and its links. A sync that ran between the replace and this
15
+ * call took the document out at `from` and filed the file anew at `target`: the new text joins the old document, the
16
+ * new one goes, and the old one is live again. False when nothing was ever at `from`.
17
+ */
18
+ export const foldRekeyed = (database, folder, from, target, at) => {
19
+ const old = documentAt(database, folder, from);
20
+ if (!old)
21
+ return false;
22
+ const id = Number(old.id);
23
+ const filed = documentAt(database, folder, target);
24
+ if (filed && Number(filed.id) !== id) {
25
+ // A catalog entry not read yet has no text; the old document's stays until the next read.
26
+ if (filed.body != null) {
27
+ if ((old.body ?? "") !== "" && old.deleted_at == null)
28
+ keepRevision(database, old, at);
29
+ database
30
+ .prepare(`UPDATE documents SET ${CONTENT.map((column) => `${column} = ?`).join(", ")}, revision = revision + 1, ` +
31
+ "updated_at = ? WHERE id = ?")
32
+ .run(...CONTENT.map((column) => filed[column] ?? null), at, id);
33
+ }
34
+ deleteDocumentRow(database, Number(filed.id), at);
35
+ database
36
+ .prepare("DELETE FROM files WHERE account_id = ? AND external_id = ? AND kind <> 'folder'")
37
+ .run(folder, target);
38
+ }
39
+ if (old.deleted_at != null) {
40
+ database.prepare("UPDATE documents SET deleted_at = NULL, removal = NULL WHERE id = ?").run(id);
41
+ database
42
+ .prepare("UPDATE files SET deleted_at = NULL WHERE account_id = ? AND external_id = ? AND kind <> 'folder'")
43
+ .run(folder, from);
44
+ logDocumentChange(database, id, "restored", at);
45
+ }
46
+ return true;
47
+ };
@@ -137,8 +137,13 @@ export interface NotesStore extends NoteSearch, ImportedDocuments, AddedSources,
137
137
  note: Note;
138
138
  changed: boolean;
139
139
  }>;
140
- /** Moves a file note to a new path in its folder, keeping its id, links and tags; a gone note at `to` is dropped. */
141
- renameFileNote(folderId: string, from: string, to: string): Promise<Note>;
140
+ /**
141
+ * Moves a file note to a new path in its folder, keeping its id, links and tags; a gone note at `to` is dropped.
142
+ * `fold` is for a source that gave the file a new id: see `foldRekeyed`.
143
+ */
144
+ renameFileNote(folderId: string, from: string, to: string, options?: {
145
+ fold?: boolean;
146
+ }): Promise<Note>;
142
147
  /**
143
148
  * Sets the time the source dates each note at these paths (ISO 8601), the note's `modifiedAt`, without counting
144
149
  * as an edit: text, revision and `updatedAt` stay. Answers how many notes it changed.
@@ -13,6 +13,7 @@ import { documentHistoryOver, keepRevision, logDocumentChange, removeDocument }
13
13
  import { encodeDocumentMetadata, languageOf } from "./document-metadata.js";
14
14
  import { deleteDocumentRow, forgetEvidenceToRow } from "./evidence-signature.js";
15
15
  import { fileNoteRow } from "./file-note.js";
16
+ import { foldRekeyed } from "./file-note-rekey.js";
16
17
  import { PREFERRED_FILE, syncFile } from "./files.js";
17
18
  import { importedDocumentWhere } from "./imported-documents.js";
18
19
  import { LINK_KINDS, LINK_ORIGINS, linkKind, RELATION_KINDS } from "./link-kinds.js";
@@ -456,10 +457,12 @@ export const notesStoreOver = (context) => {
456
457
  followPreferred(id, at);
457
458
  return { note: noteAt(id, folder, path), changed: !same };
458
459
  }),
459
- renameFileNote: async (folderId, from, to) => write(database, () => {
460
+ renameFileNote: async (folderId, from, to, options) => write(database, () => {
460
461
  const folder = Number(folderRow(folderId, true).id);
461
462
  const target = textOf(to, "a note's path", 4096);
462
463
  const at = now();
464
+ if (options?.fold)
465
+ foldRekeyed(database, folder, from, target, at);
463
466
  const place = fileAt(folder, from, true);
464
467
  const legacy = database
465
468
  .prepare("SELECT id FROM documents WHERE account_id = ? AND external_id = ? AND deleted_at IS NULL")
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Whether the terminal draws an OSC 8 link. One that does not drops the escape and shows only the words, so the address
3
+ * would be lost: only terminals known to draw it get one, and `FORCE_HYPERLINK=1` or `=0` decides for any other.
4
+ * tmux and screen pass the escape on only when set up to, so they get the address.
5
+ */
6
+ export declare const drawsHyperlinks: (env: NodeJS.ProcessEnv) => boolean;
7
+ /** The words as a link to the address; a BEL or ESC in either would end the sequence early, so they are dropped. */
8
+ export declare const hyperlink: (label: string, href: string) => string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Whether the terminal draws an OSC 8 link. One that does not drops the escape and shows only the words, so the address
3
+ * would be lost: only terminals known to draw it get one, and `FORCE_HYPERLINK=1` or `=0` decides for any other.
4
+ * tmux and screen pass the escape on only when set up to, so they get the address.
5
+ */
6
+ export const drawsHyperlinks = (env) => {
7
+ if (env.FORCE_HYPERLINK !== undefined)
8
+ return env.FORCE_HYPERLINK !== "0";
9
+ if (env.TMUX || env.STY || env.CI || env.TERM === "dumb")
10
+ return false;
11
+ if (Number(env.VTE_VERSION) >= 5000)
12
+ return true;
13
+ if (env.WT_SESSION || env.KITTY_WINDOW_ID || env.KONSOLE_VERSION || env.WEZTERM_EXECUTABLE)
14
+ return true;
15
+ return ["iTerm.app", "WezTerm", "vscode", "ghostty"].includes(env.TERM_PROGRAM ?? "");
16
+ };
17
+ /** The words as a link to the address; a BEL or ESC in either would end the sequence early, so they are dropped. */
18
+ export const hyperlink = (label, href) => {
19
+ const clean = (text) => [...text].filter((char) => char >= " " && char !== "\u007f").join("");
20
+ return `\u001b]8;;${clean(href)}\u0007${clean(label)}\u001b]8;;\u0007`;
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.737.0",
3
+ "version": "0.739.0",
4
4
  "description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",