@wirecat/cli-core 0.703.0 → 0.705.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 (88) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/dist/background/daily-archive-timer.d.ts +1 -1
  3. package/dist/cli/bot/api-http.d.ts +8 -2
  4. package/dist/cli/bot/api-http.js +20 -4
  5. package/dist/cli/documents/words.d.ts +1 -1
  6. package/dist/cli/index.d.ts +3 -3
  7. package/dist/cli/index.js +3 -3
  8. package/dist/cli/messenger/store-maintenance-command.js +6 -2
  9. package/dist/cli/service-api-call.d.ts +13 -3
  10. package/dist/cli/service-api-call.js +19 -9
  11. package/dist/cli/service-api-manifest.d.ts +11 -2
  12. package/dist/cli/service-api-manifest.js +30 -9
  13. package/dist/cli/service-api.d.ts +14 -6
  14. package/dist/cli/service-api.js +137 -29
  15. package/dist/cli/token-session.d.ts +5 -2
  16. package/dist/cli/token-session.js +13 -4
  17. package/dist/content/cli/index.d.ts +33 -0
  18. package/dist/content/cli/index.js +368 -0
  19. package/dist/content/index.d.ts +8 -0
  20. package/dist/content/index.js +7 -0
  21. package/dist/content/manifest/index.d.ts +4 -0
  22. package/dist/content/manifest/index.js +4 -0
  23. package/dist/content/manifest/manifest.d.ts +92 -0
  24. package/dist/content/manifest/manifest.js +137 -0
  25. package/dist/content/manifest/map.d.ts +25 -0
  26. package/dist/content/manifest/map.js +94 -0
  27. package/dist/content/manifest/source.d.ts +41 -0
  28. package/dist/content/manifest/source.js +288 -0
  29. package/dist/content/manifest/writer.d.ts +26 -0
  30. package/dist/content/manifest/writer.js +133 -0
  31. package/dist/content/source.d.ts +64 -0
  32. package/dist/content/source.js +2 -0
  33. package/dist/content/sync.d.ts +61 -0
  34. package/dist/content/sync.js +387 -0
  35. package/dist/content/testing/index.d.ts +4 -0
  36. package/dist/content/testing/index.js +4 -0
  37. package/dist/content/testing/source-contract.d.ts +38 -0
  38. package/dist/content/testing/source-contract.js +274 -0
  39. package/dist/content/testing/source.d.ts +55 -0
  40. package/dist/content/testing/source.js +276 -0
  41. package/dist/content/testing/sync-contract.d.ts +10 -0
  42. package/dist/content/testing/sync-contract.js +172 -0
  43. package/dist/content/testing/write-contract.d.ts +14 -0
  44. package/dist/content/testing/write-contract.js +102 -0
  45. package/dist/content/writer.d.ts +64 -0
  46. package/dist/content/writer.js +38 -0
  47. package/dist/content/writes.d.ts +58 -0
  48. package/dist/content/writes.js +129 -0
  49. package/dist/documents/file-mirror-model.d.ts +90 -0
  50. package/dist/documents/file-mirror-model.js +1 -0
  51. package/dist/documents/index.d.ts +6 -3
  52. package/dist/documents/index.js +3 -1
  53. package/dist/documents/push-model.d.ts +3 -0
  54. package/dist/domain/content.d.ts +102 -0
  55. package/dist/domain/content.js +11 -0
  56. package/dist/embeddings/onnx-runtime.d.ts +1 -1
  57. package/dist/embeddings/onnx-runtime.js +42 -61
  58. package/dist/errors/reasons.js +22 -0
  59. package/dist/manifest/index.d.ts +21 -7
  60. package/dist/manifest/index.js +7 -4
  61. package/dist/ports/wirecat-tools.js +7 -0
  62. package/dist/sends/upload.js +0 -1
  63. package/dist/services/documents/mirror-watch.d.ts +12 -4
  64. package/dist/services/documents/mirror-watch.js +2 -0
  65. package/dist/services/documents/mirrors.d.ts +67 -35
  66. package/dist/services/documents/mirrors.js +72 -66
  67. package/dist/services/documents/push.d.ts +56 -4
  68. package/dist/services/documents/push.js +131 -24
  69. package/dist/services/files/mirror.d.ts +157 -0
  70. package/dist/services/files/mirror.js +660 -0
  71. package/dist/services/files/versions.d.ts +60 -0
  72. package/dist/services/files/versions.js +177 -0
  73. package/dist/services/metadata.d.ts +1 -1
  74. package/dist/store/exports.d.ts +1 -0
  75. package/dist/store/exports.js +1 -0
  76. package/dist/store/recover.js +2 -0
  77. package/dist/store/sqlite/account-purge.js +7 -0
  78. package/dist/store/sqlite/content.d.ts +100 -0
  79. package/dist/store/sqlite/content.js +375 -0
  80. package/dist/store/sqlite/entity-types.d.ts +1 -0
  81. package/dist/store/sqlite/entity-types.js +1 -0
  82. package/dist/store/sqlite/manifest.js +2 -0
  83. package/dist/store/sqlite/migrations.generated.js +26 -0
  84. package/dist/store/sqlite/schema.d.ts +1140 -0
  85. package/dist/store/sqlite/schema.js +100 -0
  86. package/dist/store/store.d.ts +3 -0
  87. package/dist/store/store.js +5 -0
  88. package/package.json +12 -4
@@ -0,0 +1,157 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ import type { FileMirrorStatePort, FileStepKind, FileTarget } from "../../documents/file-mirror-model.js";
3
+ import type { Keep } from "../../documents/push-model.js";
4
+ import { type HeldLock, type Mirror } from "../documents/mirrors.js";
5
+ import { type MirrorAction, type PushConflict } from "../documents/push.js";
6
+ import type { FileVersions } from "./versions.js";
7
+ type Side = "local" | "remote";
8
+ export interface FileMirrorOptions {
9
+ /** Absolute path of the local folder. */
10
+ root: string;
11
+ /** The remote folder, as the target addresses it. */
12
+ folder: string;
13
+ target: FileTarget;
14
+ state: FileMirrorStatePort;
15
+ /**
16
+ * Keeps every content before the sync overwrites or deletes it (a remote one an upload replaces is downloaded first
17
+ * unless the store has it; a remote deletion leaves it in the provider's trash), and logs each change.
18
+ */
19
+ versions: FileVersions;
20
+ principal: string;
21
+ /** Settles conflicts; without it they are reported and left. */
22
+ keep?: Keep;
23
+ dryRun?: boolean;
24
+ /** Lets a run delete this many files although the deletion guard would stop it. */
25
+ allowDeletions?: number;
26
+ /**
27
+ * The owner confirmed that a root reported as replaced is the right folder now: its identity is recorded again and
28
+ * the run is a first sync (identical files adopted, different ones conflicts), deleting nothing.
29
+ */
30
+ repin?: boolean;
31
+ /** How the app names the remote side; it ends a conflict copy's name. */
32
+ remote: string;
33
+ /** How the app's commands are named in the deletion guard's and the repin message; the defaults are flags. */
34
+ hints?: Partial<MirrorHints>;
35
+ /** Runs one write behind the app's permission checks; `side` says which side it changes. */
36
+ guard<T>(attempt: {
37
+ action: MirrorAction;
38
+ side: Side;
39
+ path: string;
40
+ operationId: string;
41
+ }, act: () => Promise<T>): Promise<T>;
42
+ operationId(): string;
43
+ errorOf(error: unknown): CliError;
44
+ /** Throws once the sync lock is lost; checked before every write. */
45
+ assertHeld(): void | Promise<void>;
46
+ signal?: AbortSignal;
47
+ maxFiles?: number;
48
+ now?(): number;
49
+ }
50
+ export interface MirrorHints {
51
+ /** How to preview a run: `--dry-run`. */
52
+ preview: string;
53
+ /** How to record a replaced root again: `--repin`. */
54
+ repin: string;
55
+ /** How to allow a run's deletions: `explicitly`, as in "allow them explicitly". */
56
+ allowDeletions: string;
57
+ }
58
+ export interface FileStep {
59
+ kind: FileStepKind;
60
+ path: string;
61
+ /** A rename's new path, or a kept copy's name. */
62
+ to?: string;
63
+ }
64
+ export interface FileMirrorResult {
65
+ uploaded: string[];
66
+ downloaded: string[];
67
+ trashed: {
68
+ path: string;
69
+ side: Side;
70
+ }[];
71
+ renamed: {
72
+ from: string;
73
+ to: string;
74
+ }[];
75
+ adopted: string[];
76
+ unchanged: number;
77
+ conflicts: PushConflict[];
78
+ errors: {
79
+ path: string;
80
+ code: string;
81
+ message: string;
82
+ }[];
83
+ /**
84
+ * Files of the last sync missing from a side that cannot prove a deletion: its listing was incomplete, or its root
85
+ * is gone or is another folder. Nothing is deleted for them.
86
+ */
87
+ unknown: {
88
+ path: string;
89
+ side: Side;
90
+ reason: string;
91
+ }[];
92
+ /** Every step but the unchanged files, on a dry run. */
93
+ plan?: FileStep[];
94
+ /** On a dry run, the deletions that would stop the real run without `allowDeletions`. */
95
+ tooManyDeletions?: number;
96
+ stopped?: true;
97
+ }
98
+ /**
99
+ * Syncs a local folder and a remote folder of plain files both ways, whole files at a time. Each path is compared
100
+ * three ways (local now, remote now, last sync): a change on one side is copied to the other, the same content on
101
+ * both is adopted, and different changes on both are a conflict unless `keep` settles it. Deletions go to the
102
+ * remote's trash and to `<root>/.wirecat-trash/`. A remote rename, found by the file's id, renames the local file.
103
+ * Every write is conditional on what the listing saw, so a crash at any point is settled by the next run.
104
+ */
105
+ export declare const syncFileMirror: (options: FileMirrorOptions) => Promise<FileMirrorResult>;
106
+ /** A file mirror's state in `<dir>/<id>.json`, refused rather than reset when invalid. */
107
+ export declare const fileSyncState: (dir: string, mirror: Mirror, principal: string) => FileMirrorStatePort;
108
+ /** What each mirror's next sync would send from local changes alone; the remote is not asked. */
109
+ export declare const fileMirrorStatus: (mirrors: Mirror[], stateOf: (mirror: Mirror) => FileMirrorStatePort) => Promise<{
110
+ id: string;
111
+ path: string;
112
+ folder: string;
113
+ upload: string[];
114
+ delete: string[];
115
+ unchanged: number;
116
+ remote_checked: boolean;
117
+ }[]>;
118
+ /**
119
+ * A watch's `remoteChanges` for a file target: every mirror when the remote's revision moved since the last poll (or
120
+ * at the first poll), none when it did not, and every mirror at each poll when the target has no revision.
121
+ */
122
+ export declare const fileRemoteChanges: (target: FileTarget) => (signal: AbortSignal) => Promise<string[] | "all">;
123
+ export interface FileMirrorSyncOptions extends Pick<FileMirrorOptions, "target" | "principal" | "keep" | "dryRun" | "allowDeletions" | "repin" | "hints" | "guard" | "operationId" | "errorOf" | "signal"> {
124
+ mirrors: Mirror[];
125
+ stateOf(mirror: Mirror): FileMirrorStatePort;
126
+ versionsOf(mirror: Mirror): FileVersions;
127
+ /** The sync lock, as `acquireLock` returns it or with a synchronous `assertHeld`. */
128
+ lock(): Promise<HeldLock>;
129
+ /** How the app names the remote side in reports and conflict copies. */
130
+ remote: string;
131
+ }
132
+ /** Syncs each file mirror under one lock, with one `mirror.partial` issue per mirror left with conflicts or errors. */
133
+ export declare const syncFileMirrors: (options: FileMirrorSyncOptions) => Promise<{
134
+ items: (Omit<{
135
+ id: string;
136
+ path: string;
137
+ } & FileMirrorResult, "conflicts"> & {
138
+ conflicts: {
139
+ path: string;
140
+ url?: string | undefined;
141
+ reason: string;
142
+ parts?: {
143
+ [x: string]: string;
144
+ last_sync: string;
145
+ local: string;
146
+ }[] | undefined;
147
+ local_changed_at?: string | undefined;
148
+ local_size?: number | undefined;
149
+ }[];
150
+ })[];
151
+ issues: {
152
+ code: "provider_error";
153
+ reason: string;
154
+ source: string;
155
+ }[];
156
+ }>;
157
+ export {};