@tomradex/files 0.0.0-stage → 0.17.1
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/dist/agent-index.d.ts +41 -0
- package/dist/channels.d.ts +90 -0
- package/dist/folder-store.d.ts +41 -0
- package/dist/git-backend.d.ts +29 -0
- package/dist/git-store.d.ts +205 -0
- package/dist/git-sync.d.ts +100 -0
- package/dist/index.d.ts +11 -0
- package/dist/mime.d.ts +6 -0
- package/dist/runtime.js +1 -0
- package/dist/scopes.d.ts +29 -0
- package/dist/service.d.ts +222 -0
- package/dist/store.d.ts +64 -0
- package/dist/tools.d.ts +9 -0
- package/dist/types.d.ts +334 -0
- package/dist/words.d.ts +22 -0
- package/package.json +46 -4
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Copyright 2026 Haoyuan Tang
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Apache License
|
|
5
|
+
Version 2.0, January 2004
|
|
6
|
+
http://www.apache.org/licenses/
|
|
7
|
+
|
|
8
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
9
|
+
|
|
10
|
+
1. Definitions.
|
|
11
|
+
|
|
12
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
13
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
14
|
+
|
|
15
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
16
|
+
the copyright owner that is granting the License.
|
|
17
|
+
|
|
18
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
19
|
+
other entities that control, are controlled by, or are under common
|
|
20
|
+
control with that entity. For the purposes of this definition,
|
|
21
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
22
|
+
direction or management of such entity, whether by contract or
|
|
23
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
24
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
25
|
+
|
|
26
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
27
|
+
exercising permissions granted by this License.
|
|
28
|
+
|
|
29
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
30
|
+
including but not limited to software source code, documentation
|
|
31
|
+
source, and configuration files.
|
|
32
|
+
|
|
33
|
+
"Object" form shall mean any form resulting from mechanical
|
|
34
|
+
transformation or translation of a Source form, including but
|
|
35
|
+
not limited to compiled object code, generated documentation,
|
|
36
|
+
and conversions to other media types.
|
|
37
|
+
|
|
38
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
39
|
+
Object form, made available under the License, as indicated by a
|
|
40
|
+
copyright notice that is included in or attached to the work
|
|
41
|
+
(an example is provided in the Appendix below).
|
|
42
|
+
|
|
43
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
44
|
+
form, that is based on (or derived from) the Work and for which the
|
|
45
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
46
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
47
|
+
of this License, Derivative Works shall not include works that remain
|
|
48
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
49
|
+
the Work and Derivative Works thereof.
|
|
50
|
+
|
|
51
|
+
"Contribution" shall mean any work of authorship, including
|
|
52
|
+
the original version of the Work and any modifications or additions
|
|
53
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
54
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
55
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
56
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
57
|
+
means any form of electronic, verbal, or written communication sent
|
|
58
|
+
to the Licensor or its representatives, including but not limited to
|
|
59
|
+
communication on electronic mailing lists, source code control systems,
|
|
60
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
61
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
62
|
+
excluding communication that is conspicuously marked or otherwise
|
|
63
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
64
|
+
|
|
65
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
66
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
67
|
+
subsequently incorporated within the Work.
|
|
68
|
+
|
|
69
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
70
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
71
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
72
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
73
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
74
|
+
Work and such Derivative Works in Source or Object form.
|
|
75
|
+
|
|
76
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
77
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
78
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
79
|
+
(except as stated in this section) patent license to make, have made,
|
|
80
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
81
|
+
where such license applies only to those patent claims licensable
|
|
82
|
+
by such Contributor that are necessarily infringed by their
|
|
83
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
84
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
85
|
+
institute patent litigation against any entity (including a
|
|
86
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
87
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
88
|
+
or contributory patent infringement, then any patent licenses
|
|
89
|
+
granted to You under this License for that Work shall terminate
|
|
90
|
+
as of the date such litigation is filed.
|
|
91
|
+
|
|
92
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
93
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
94
|
+
modifications, and in Source or Object form, provided that You
|
|
95
|
+
meet the following conditions:
|
|
96
|
+
|
|
97
|
+
(a) You must give any other recipients of the Work or
|
|
98
|
+
Derivative Works a copy of this License; and
|
|
99
|
+
|
|
100
|
+
(b) You must cause any modified files to carry prominent notices
|
|
101
|
+
stating that You changed the files; and
|
|
102
|
+
|
|
103
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
104
|
+
that You distribute, all copyright, patent, trademark, and
|
|
105
|
+
attribution notices from the Source form of the Work,
|
|
106
|
+
excluding those notices that do not pertain to any part of
|
|
107
|
+
the Derivative Works; and
|
|
108
|
+
|
|
109
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
110
|
+
distribution, then any Derivative Works that You distribute must
|
|
111
|
+
include a readable copy of the attribution notices contained
|
|
112
|
+
within such NOTICE file, excluding those notices that do not
|
|
113
|
+
pertain to any part of the Derivative Works, in at least one
|
|
114
|
+
of the following places: within a NOTICE text file distributed
|
|
115
|
+
as part of the Derivative Works; within the Source form or
|
|
116
|
+
documentation, if provided along with the Derivative Works; or,
|
|
117
|
+
within a display generated by the Derivative Works, if and
|
|
118
|
+
wherever such third-party notices normally appear. The contents
|
|
119
|
+
of the NOTICE file are for informational purposes only and
|
|
120
|
+
do not modify the License. You may add Your own attribution
|
|
121
|
+
notices within Derivative Works that You distribute, alongside
|
|
122
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
123
|
+
that such additional attribution notices cannot be construed
|
|
124
|
+
as modifying the License.
|
|
125
|
+
|
|
126
|
+
You may add Your own copyright statement to Your modifications and
|
|
127
|
+
may provide additional or different license terms and conditions
|
|
128
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
129
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
130
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
131
|
+
the conditions stated in this License.
|
|
132
|
+
|
|
133
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
134
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
135
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
136
|
+
this License, without any additional terms or conditions.
|
|
137
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
138
|
+
the terms of any separate license agreement you may have executed
|
|
139
|
+
with Licensor regarding such Contributions.
|
|
140
|
+
|
|
141
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
142
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
143
|
+
except as required for reasonable and customary use in describing the
|
|
144
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
145
|
+
|
|
146
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
147
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
148
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
149
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
150
|
+
implied, including, without limitation, any warranties or conditions
|
|
151
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
152
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
153
|
+
appropriateness of using or redistributing the Work and assume any
|
|
154
|
+
risks associated with Your exercise of permissions under this License.
|
|
155
|
+
|
|
156
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
157
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
158
|
+
unless required by applicable law (such as deliberate and grossly
|
|
159
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
160
|
+
liable to You for damages, including any direct, indirect, special,
|
|
161
|
+
incidental, or consequential damages of any character arising as a
|
|
162
|
+
result of this License or out of the use or inability to use the
|
|
163
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
164
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
165
|
+
other commercial damages or losses), even if such Contributor
|
|
166
|
+
has been advised of the possibility of such damages.
|
|
167
|
+
|
|
168
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
169
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
170
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
171
|
+
or other liability obligations and/or rights consistent with this
|
|
172
|
+
License. However, in accepting such obligations, You may act only
|
|
173
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
174
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
175
|
+
defend, and hold each Contributor harmless for any liability
|
|
176
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
177
|
+
of your accepting any such warranty or additional liability.
|
|
178
|
+
|
|
179
|
+
END OF TERMS AND CONDITIONS
|
|
180
|
+
|
|
181
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
182
|
+
|
|
183
|
+
To apply the Apache License to your work, attach the following
|
|
184
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
185
|
+
replaced with your own identifying information. (Don't include
|
|
186
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
187
|
+
comment syntax for the file format. We also recommend that a
|
|
188
|
+
file or class name and description of purpose be included on the
|
|
189
|
+
same "printed page" as the copyright notice for easier
|
|
190
|
+
identification within third-party archives.
|
|
191
|
+
|
|
192
|
+
Copyright [yyyy] [name of copyright owner]
|
|
193
|
+
|
|
194
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
195
|
+
you may not use this file except in compliance with the License.
|
|
196
|
+
You may obtain a copy of the License at
|
|
197
|
+
|
|
198
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
199
|
+
|
|
200
|
+
Unless required by applicable law or agreed to in writing, software
|
|
201
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
202
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
203
|
+
See the License for the specific language governing permissions and
|
|
204
|
+
limitations under the License.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { FileEntry, FilesAgentPolicy } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* What an agent is told a project holds, before it asks anything. The point is
|
|
4
|
+
* discovery, not access: a path left out of the index still reads and writes,
|
|
5
|
+
* and the person who left it out only meant "do not bring this up".
|
|
6
|
+
*/
|
|
7
|
+
export interface AgentIndex {
|
|
8
|
+
markdown: string;
|
|
9
|
+
/** Files named or counted here. */
|
|
10
|
+
listed: number;
|
|
11
|
+
/** Files in the store, including the ones left out. */
|
|
12
|
+
total: number;
|
|
13
|
+
tokens: number;
|
|
14
|
+
/** Changes when the rendered text does, so a session can notice it went stale. */
|
|
15
|
+
digest: string;
|
|
16
|
+
}
|
|
17
|
+
export interface AgentIndexInput {
|
|
18
|
+
entries: FileEntry[];
|
|
19
|
+
policy: FilesAgentPolicy;
|
|
20
|
+
/** The heading a document gives itself, when it gives one. */
|
|
21
|
+
titleOf(entry: FileEntry): string | null;
|
|
22
|
+
/** Roughly how many tokens the whole index may take. */
|
|
23
|
+
budget?: number;
|
|
24
|
+
/** Folders that stay expanded whatever the budget: the ticket's own, and wherever its materials live. */
|
|
25
|
+
focus?: string[];
|
|
26
|
+
/** This machine's copy, named only for an engine that can open it itself. */
|
|
27
|
+
root?: string | null;
|
|
28
|
+
/** The engine has its own file tools, so the folder is worth naming. */
|
|
29
|
+
native?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare const estimateTokens: (text: string) => number;
|
|
32
|
+
export declare const formatSize: (bytes: number) => string;
|
|
33
|
+
/** Same year needs no year: the index is read by something that knows what today is. */
|
|
34
|
+
export declare function shortDate(at: number, now?: number): string;
|
|
35
|
+
/**
|
|
36
|
+
* Fold the biggest, deepest folder that nobody asked to keep open, and keep
|
|
37
|
+
* folding until the index fits. What is folded still says how much it holds and
|
|
38
|
+
* how recent it is, which is enough for the model to decide to look.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildAgentIndex(input: AgentIndexInput): AgentIndex;
|
|
41
|
+
//# sourceMappingURL=agent-index.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { FileDescription, FileReference, Item } from "@tomradex/domain";
|
|
2
|
+
import type { AttachmentInput, ConflictChoice, ConnectionState, FileConflict, FileContent, FileEntry, FileVersion, FilesAgentPolicy, FilesBackendView, FilesInfo, FilesStatus, FilesSyncPolicy, ListMode, SaveResult, SyncMode } from "./types.js";
|
|
3
|
+
import type { AgentIndex } from "./agent-index.js";
|
|
4
|
+
declare module "@tomradex/ipc" {
|
|
5
|
+
interface Channels {
|
|
6
|
+
"files.backends": () => FilesBackendView[];
|
|
7
|
+
"files.info": (projectId: string) => FilesInfo;
|
|
8
|
+
"files.status": (projectId: string) => FilesStatus;
|
|
9
|
+
/** Every entry, folders before files, depth first; the renderer nests them by path. */
|
|
10
|
+
"files.tree": (projectId: string) => FileEntry[];
|
|
11
|
+
"files.list": (projectId: string, dir?: string) => FileEntry[];
|
|
12
|
+
"files.read": (projectId: string, path: string) => FileContent | null;
|
|
13
|
+
/** An immutable version, as a ticket pinned it — null when it is gone or was never there. */
|
|
14
|
+
"files.readVersion": (projectId: string, ref: FileReference) => FileContent | null;
|
|
15
|
+
/** Where a file is now, by its id. */
|
|
16
|
+
"files.locate": (projectId: string, fileId: string) => string | null;
|
|
17
|
+
"files.history": (projectId: string, path: string, limit?: number) => FileVersion[];
|
|
18
|
+
"files.write": (projectId: string, path: string, body: string, opts?: {
|
|
19
|
+
encoding?: "utf8" | "base64";
|
|
20
|
+
message?: string;
|
|
21
|
+
}) => FileContent;
|
|
22
|
+
/** A text save that will not land over somebody else's: `expect` is the `hash` the editor read, null for a new file. */
|
|
23
|
+
"files.save": (projectId: string, path: string, body: string, opts?: {
|
|
24
|
+
expect?: string | null;
|
|
25
|
+
message?: string;
|
|
26
|
+
}) => SaveResult;
|
|
27
|
+
/** Copy files or folders from this machine into a folder of the store. */
|
|
28
|
+
"files.import": (projectId: string, dir: string, sources: string[]) => FileEntry[];
|
|
29
|
+
/** Each returns the history record it made (`files:<id>`, for `oplog.revert`), or null when nothing changed. */
|
|
30
|
+
"files.mkdir": (projectId: string, path: string) => string | null;
|
|
31
|
+
"files.move": (projectId: string, from: string, to: string) => string | null;
|
|
32
|
+
/** Copy a file or folder to a new path, as a version of its own with a fresh fileId. */
|
|
33
|
+
"files.copy": (projectId: string, from: string, to: string) => string | null;
|
|
34
|
+
"files.remove": (projectId: string, path: string) => string | null;
|
|
35
|
+
"files.sync": (projectId: string) => FilesStatus;
|
|
36
|
+
"files.syncPolicy": (projectId: string) => FilesSyncPolicy;
|
|
37
|
+
"files.setSyncRules": (projectId: string, paths: string[], mode: SyncMode | "inherit") => FilesSyncPolicy;
|
|
38
|
+
/** Which paths Tomrade names to agents on its own. Disclosure, never access. */
|
|
39
|
+
"files.agentPolicy": (projectId: string) => FilesAgentPolicy;
|
|
40
|
+
"files.setAgentRules": (projectId: string, paths: string[], mode: ListMode | "inherit") => FilesAgentPolicy;
|
|
41
|
+
/** Exactly what an agent is told this project holds, for the person to read before an agent does. */
|
|
42
|
+
"files.agentIndex": (projectId: string, opts?: {
|
|
43
|
+
budget?: number;
|
|
44
|
+
focus?: string[];
|
|
45
|
+
native?: boolean;
|
|
46
|
+
}) => AgentIndex | null;
|
|
47
|
+
"files.conflicts": (projectId: string) => FileConflict[];
|
|
48
|
+
"files.resolve": (projectId: string, path: string, choice: ConflictChoice) => FilesStatus;
|
|
49
|
+
"files.resolveAll": (projectId: string, choice: ConflictChoice) => FilesStatus;
|
|
50
|
+
/** Share the project's files through a backend's remote, and sync at once. */
|
|
51
|
+
"files.bind": (projectId: string, backendId: string, config: Record<string, unknown>) => FilesStatus;
|
|
52
|
+
"files.unbind": (projectId: string) => FilesInfo;
|
|
53
|
+
"files.browse": (backendId: string) => {
|
|
54
|
+
label: string;
|
|
55
|
+
config: unknown;
|
|
56
|
+
}[];
|
|
57
|
+
"files.draft": (backendId: string, name: string) => unknown;
|
|
58
|
+
"files.connection": (backendId: string) => ConnectionState;
|
|
59
|
+
"files.connect": (backendId: string, secret: string) => ConnectionState;
|
|
60
|
+
"files.signIn": (backendId: string) => ConnectionState;
|
|
61
|
+
"files.disconnect": (backendId: string) => void;
|
|
62
|
+
/** Pin a file's latest version to a ticket as material or an output artifact. */
|
|
63
|
+
"files.attach": (projectId: string, itemId: string, input: {
|
|
64
|
+
path: string;
|
|
65
|
+
role: "input" | "output";
|
|
66
|
+
name?: string;
|
|
67
|
+
}) => Item;
|
|
68
|
+
/** Pin several latest file versions to a ticket in one item write. */
|
|
69
|
+
"files.attachMany": (projectId: string, itemId: string, input: {
|
|
70
|
+
paths: string[];
|
|
71
|
+
role: "input" | "output";
|
|
72
|
+
}) => Item;
|
|
73
|
+
/** The top-level folder a ticket's files land in: its workstream's name. */
|
|
74
|
+
"files.folderFor": (projectId: string, itemId: string) => string;
|
|
75
|
+
/** Copy files from this machine into the ticket's workstream folder and pin them. */
|
|
76
|
+
"files.importFor": (projectId: string, itemId: string, input: {
|
|
77
|
+
sources: string[];
|
|
78
|
+
role: "input" | "output";
|
|
79
|
+
}) => Item;
|
|
80
|
+
/** Files for a ticket body to link to, saved as one version under `<workstream>/attachments/<KEY>/`, in input order. */
|
|
81
|
+
"files.addAttachments": (projectId: string, itemId: string, files: AttachmentInput[]) => FileDescription[];
|
|
82
|
+
/** A file's latest content by its id, wherever it has moved; null when it is not here (deleted, or not synced yet). */
|
|
83
|
+
"files.readById": (projectId: string, fileId: string) => FileContent | null;
|
|
84
|
+
}
|
|
85
|
+
interface Broadcasts {
|
|
86
|
+
/** This project's files or their sync state moved; refetch everything keyed by it. */
|
|
87
|
+
"files.changed": (projectId: string) => void;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=channels.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type FileContent, type FileEntry, type FileSearchInput, type FileSearchResult, type FileStore, type FilesStatus, type WriteEntry } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The files folder as it is, for a machine without git: every read and write
|
|
4
|
+
* works on the folder itself; versions, undo and sharing wait until git is
|
|
5
|
+
* there, and the next open then keeps the same folder under git.
|
|
6
|
+
*/
|
|
7
|
+
export declare class FolderFileStore implements FileStore {
|
|
8
|
+
readonly dir: string;
|
|
9
|
+
private readonly opts;
|
|
10
|
+
constructor(dir: string, opts: {
|
|
11
|
+
detail: string;
|
|
12
|
+
onChange(): void;
|
|
13
|
+
});
|
|
14
|
+
private abs;
|
|
15
|
+
private readDir;
|
|
16
|
+
list(dir?: string): Promise<FileEntry[]>;
|
|
17
|
+
tree(): Promise<FileEntry[]>;
|
|
18
|
+
read(p: string): Promise<FileContent | null>;
|
|
19
|
+
readVersion(): Promise<FileContent | null>;
|
|
20
|
+
resolveVersion(): Promise<null>;
|
|
21
|
+
locate(): Promise<string | null>;
|
|
22
|
+
history(): Promise<[]>;
|
|
23
|
+
write(p: string, body: Buffer, opts?: {
|
|
24
|
+
expect?: string | null;
|
|
25
|
+
}): Promise<FileContent>;
|
|
26
|
+
writeMany(entries: WriteEntry[]): Promise<void>;
|
|
27
|
+
mkdir(p: string): Promise<void>;
|
|
28
|
+
private pair;
|
|
29
|
+
move(from: string, to: string): Promise<void>;
|
|
30
|
+
copy(from: string, to: string): Promise<void>;
|
|
31
|
+
remove(p: string): Promise<void>;
|
|
32
|
+
settle(): Promise<boolean>;
|
|
33
|
+
/** A plain scan; literal unless asked, and a file too large to read whole is skipped. */
|
|
34
|
+
search(input: FileSearchInput): Promise<FileSearchResult>;
|
|
35
|
+
status(): Promise<FilesStatus>;
|
|
36
|
+
sync(): Promise<FilesStatus>;
|
|
37
|
+
conflicts(): Promise<[]>;
|
|
38
|
+
resolve(): Promise<void>;
|
|
39
|
+
close(): void;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=folder-store.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type GitCredential } from "@tomradex/git";
|
|
2
|
+
import { type GitRemoteTarget } from "./git-store.js";
|
|
3
|
+
import type { FilesBackend, FilesConnection } from "./types.js";
|
|
4
|
+
export interface GitBackendOptions<C> {
|
|
5
|
+
id: string;
|
|
6
|
+
title: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
configSchema: FilesBackend<C>["configSchema"];
|
|
9
|
+
defaults: C;
|
|
10
|
+
settingsSection?: string;
|
|
11
|
+
connection?: FilesConnection;
|
|
12
|
+
/** How git authenticates to the remote, asked before each command; null leaves the user's own git credentials in charge. */
|
|
13
|
+
credential?: () => GitCredential | null;
|
|
14
|
+
browse?: FilesBackend<C>["browse"];
|
|
15
|
+
draft?: FilesBackend<C>["draft"];
|
|
16
|
+
describe?: (config: C) => string;
|
|
17
|
+
/** The git remote a config stands for; null for a backend that shares nothing. */
|
|
18
|
+
remote: ((config: C) => Promise<GitRemoteTarget> | GitRemoteTarget) | null;
|
|
19
|
+
/** Bring the remote into being — create the repository, say. */
|
|
20
|
+
ensureRemote?: (config: C) => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A backend that keeps the files as a git repository and, given a remote,
|
|
24
|
+
* shares them through it. What a remote backend adds is exactly what git
|
|
25
|
+
* cannot do by itself: name the remote from a non-secret config, find one,
|
|
26
|
+
* make one.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createGitBackend<C>(opts: GitBackendOptions<C>): FilesBackend<C>;
|
|
29
|
+
//# sourceMappingURL=git-backend.d.ts.map
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import type { FileReference } from "@tomradex/domain";
|
|
2
|
+
import { type Git } from "@tomradex/git";
|
|
3
|
+
import { type ConflictChoice, type FileConflict, type FileContent, type FileEntry, type FileStore, type FileVersion, type FileSearchInput, type FileSearchResult, type FilesAgentPolicy, type FilesStatus, type FilesSyncPolicy, type ListMode, type ProjectRepository, type SyncMode, type WriteEntry, type WriteOptions } from "./types.js";
|
|
4
|
+
export declare const IDS_DIR = ".tomrade-files";
|
|
5
|
+
export declare const IDS_FILE = ".tomrade-files/ids.jsonl";
|
|
6
|
+
/** The most of a binary file a read hands back; anything a ticket body links must fit. */
|
|
7
|
+
export declare const BINARY_LIMIT: number;
|
|
8
|
+
export declare const TREE_LIMIT = 20000;
|
|
9
|
+
export declare const sha256: (bytes: Buffer) => string;
|
|
10
|
+
export interface GitRemoteTarget {
|
|
11
|
+
url: string;
|
|
12
|
+
branch: string;
|
|
13
|
+
directory?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface GitStoreOptions {
|
|
16
|
+
git: Git;
|
|
17
|
+
gitBinary: string;
|
|
18
|
+
dir: string;
|
|
19
|
+
/** Resolved on every use, so a changed credential is picked up. Null: this machine only. */
|
|
20
|
+
remote: (() => Promise<GitRemoteTarget> | GitRemoteTarget) | null;
|
|
21
|
+
/** Bring the remote into being before the first push. */
|
|
22
|
+
ensureRemote?: () => Promise<void>;
|
|
23
|
+
/** The repository holding the project itself; neither its root nor the store's own folder in it is shared. */
|
|
24
|
+
projectRepository?: () => Promise<ProjectRepository | null>;
|
|
25
|
+
/** Non-secret, for status lines; the folder when null. */
|
|
26
|
+
location: string | null;
|
|
27
|
+
warn(message: string): void;
|
|
28
|
+
onChange(): void;
|
|
29
|
+
watch?: boolean;
|
|
30
|
+
/** Outside edits are saved this long after the last one. */
|
|
31
|
+
settleMs?: number;
|
|
32
|
+
/** A save is pushed this long after it, when there is a remote. */
|
|
33
|
+
pushMs?: number;
|
|
34
|
+
}
|
|
35
|
+
/** Relative, forward-slashed, inside the store, nothing hidden. "" is the root. */
|
|
36
|
+
export declare function normalizeRel(input: string): string;
|
|
37
|
+
export interface Ledger {
|
|
38
|
+
byId: Map<string, {
|
|
39
|
+
path: string | null;
|
|
40
|
+
at: number;
|
|
41
|
+
}>;
|
|
42
|
+
byPath: Map<string, string>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The id ledger is append-only and merges by union, so both machines' lines
|
|
46
|
+
* survive a clash; the latest `at` per id wins, and a path names the id that
|
|
47
|
+
* last claimed it.
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseLedger(text: string): Ledger;
|
|
50
|
+
export declare function contentOf(rel: string, bytes: Buffer, fileId: string | null, versionId: string | null): FileContent;
|
|
51
|
+
/**
|
|
52
|
+
* A folder of files kept as a git repository: every save is a version, ids
|
|
53
|
+
* follow files across renames, and a remote — when the backend supplies one —
|
|
54
|
+
* is fetched, merged and pushed. Conflicts are left in the working copy for a
|
|
55
|
+
* person to settle; nothing here ever forces.
|
|
56
|
+
*/
|
|
57
|
+
export declare class GitFileStore implements FileStore {
|
|
58
|
+
private readonly opts;
|
|
59
|
+
readonly dir: string;
|
|
60
|
+
private readonly g;
|
|
61
|
+
private branch;
|
|
62
|
+
private watcher;
|
|
63
|
+
private settleTimer;
|
|
64
|
+
private pushTimer;
|
|
65
|
+
private quietUntil;
|
|
66
|
+
private syncing;
|
|
67
|
+
private syncQueue;
|
|
68
|
+
private lastSyncAt;
|
|
69
|
+
private problem;
|
|
70
|
+
private ensured;
|
|
71
|
+
private closed;
|
|
72
|
+
private chain;
|
|
73
|
+
private policy;
|
|
74
|
+
private agents;
|
|
75
|
+
private syncState;
|
|
76
|
+
/** The version each path last changed in, so publishing never has to ask git per file. */
|
|
77
|
+
private latest;
|
|
78
|
+
private stateKey;
|
|
79
|
+
private syncedHead;
|
|
80
|
+
private policyDirty;
|
|
81
|
+
private agentsDirty;
|
|
82
|
+
constructor(opts: GitStoreOptions);
|
|
83
|
+
private git;
|
|
84
|
+
/** Index-changing git calls run one at a time; an agent's write must not interleave with the watcher's save. */
|
|
85
|
+
private locked;
|
|
86
|
+
private abs;
|
|
87
|
+
private quiet;
|
|
88
|
+
open(): Promise<this>;
|
|
89
|
+
private meta;
|
|
90
|
+
/** Both dimensions live in one file; writing one always writes the pair. */
|
|
91
|
+
private savePolicy;
|
|
92
|
+
syncPolicy(): Promise<FilesSyncPolicy>;
|
|
93
|
+
agentPolicy(): Promise<FilesAgentPolicy>;
|
|
94
|
+
setAgentRules(paths: string[], mode: ListMode | "inherit"): Promise<FilesAgentPolicy>;
|
|
95
|
+
setSyncRules(paths: string[], mode: SyncMode | "inherit"): Promise<FilesSyncPolicy>;
|
|
96
|
+
private loadSyncState;
|
|
97
|
+
private saveSyncState;
|
|
98
|
+
/** "versions/<fileId>/<versionId>", or null for a pair that could never have been one of ours. */
|
|
99
|
+
private recordPath;
|
|
100
|
+
/** The portable record of a version, when this store has one. */
|
|
101
|
+
private record;
|
|
102
|
+
private records;
|
|
103
|
+
/** Remember a version portably. Bytes are kept only for versions that are not commits of this store. */
|
|
104
|
+
private archive;
|
|
105
|
+
/** A recorded version's bytes: from beside the record, else from this store's own history. */
|
|
106
|
+
private versionBytes;
|
|
107
|
+
/** Take the remote's version records; each is immutable and kept whatever the selection says now. */
|
|
108
|
+
private importRecords;
|
|
109
|
+
/** Publish records of shared versions the remote lacks. Private paths, and versions from before a path was shared, stay here. */
|
|
110
|
+
private exportRecords;
|
|
111
|
+
private scaffold;
|
|
112
|
+
close(): void;
|
|
113
|
+
private watch;
|
|
114
|
+
private unwatch;
|
|
115
|
+
private scheduleSettle;
|
|
116
|
+
private afterChange;
|
|
117
|
+
private schedulePush;
|
|
118
|
+
head(): Promise<string | null>;
|
|
119
|
+
/** The blob or tree a path names at a version, or null when it is not there. Same id, same content. */
|
|
120
|
+
private objectAt;
|
|
121
|
+
private merging;
|
|
122
|
+
private readLedger;
|
|
123
|
+
/** Every path with a pending change, keyed by path; renames are keyed by their new name. */
|
|
124
|
+
private statusMap;
|
|
125
|
+
private unmergedPaths;
|
|
126
|
+
private stagedChanges;
|
|
127
|
+
/**
|
|
128
|
+
* Give every saved file an id, carry ids across renames, and close the ids of
|
|
129
|
+
* deleted files. `carry` names the id a path had at the version being
|
|
130
|
+
* restored, so a file that comes back is the same file, not a new one.
|
|
131
|
+
*/
|
|
132
|
+
private recordIds;
|
|
133
|
+
/** Stage everything but files still in conflict, and commit when there is anything to commit. */
|
|
134
|
+
private commitAll;
|
|
135
|
+
/** The version a path last changed in; asked of git once for files from before this was kept. */
|
|
136
|
+
private versionOf;
|
|
137
|
+
private showBuffer;
|
|
138
|
+
private entryOf;
|
|
139
|
+
private readDir;
|
|
140
|
+
list(dir?: string): Promise<FileEntry[]>;
|
|
141
|
+
tree(): Promise<FileEntry[]>;
|
|
142
|
+
/**
|
|
143
|
+
* `git grep` over the working copy: the tracked files plus anything saved but
|
|
144
|
+
* not yet committed, which is exactly the set the store shows. Literal by
|
|
145
|
+
* default, because the queries are written by a model and a pathological
|
|
146
|
+
* expression must not be able to hold the store open.
|
|
147
|
+
*/
|
|
148
|
+
search(input: FileSearchInput): Promise<FileSearchResult>;
|
|
149
|
+
/** Exit 1 is "no match", not a failure; anything slower than this is a query not worth waiting for. */
|
|
150
|
+
private grep;
|
|
151
|
+
read(p: string): Promise<FileContent | null>;
|
|
152
|
+
private commitOf;
|
|
153
|
+
private pathAt;
|
|
154
|
+
readVersion(ref: FileReference): Promise<FileContent | null>;
|
|
155
|
+
resolveVersion(ref: FileReference): Promise<FileReference | null>;
|
|
156
|
+
locate(fileId: string): Promise<string | null>;
|
|
157
|
+
history(p: string, limit?: number): Promise<FileVersion[]>;
|
|
158
|
+
write(p: string, body: Buffer, opts?: WriteOptions): Promise<FileContent>;
|
|
159
|
+
writeMany(entries: WriteEntry[], opts?: {
|
|
160
|
+
message?: string;
|
|
161
|
+
}): Promise<void>;
|
|
162
|
+
/** Every path checked, and every `expect` held, before any byte lands. */
|
|
163
|
+
private guard;
|
|
164
|
+
private put;
|
|
165
|
+
mkdir(p: string): Promise<void>;
|
|
166
|
+
move(from: string, to: string, opts?: WriteOptions): Promise<void>;
|
|
167
|
+
copy(from: string, to: string, opts?: WriteOptions): Promise<void>;
|
|
168
|
+
remove(p: string, opts?: WriteOptions): Promise<void>;
|
|
169
|
+
/** git keeps no folders, so one that a removed path leaves empty would linger on disk as a phantom entry. */
|
|
170
|
+
private pruneEmptyParents;
|
|
171
|
+
settle(msg?: string): Promise<boolean>;
|
|
172
|
+
/**
|
|
173
|
+
* Undo and redo, one operation's paths at a time. Outside edits are saved
|
|
174
|
+
* first so the comparison sees the working copy; a path that is not as
|
|
175
|
+
* version `from` left it has moved on and refuses the whole restore. Ids
|
|
176
|
+
* come back with their files: a path gets the id it had at `to`.
|
|
177
|
+
*/
|
|
178
|
+
restore(paths: string[], from: string, to: string, message: string): Promise<string | null>;
|
|
179
|
+
status(): Promise<FilesStatus>;
|
|
180
|
+
sync(): Promise<FilesStatus>;
|
|
181
|
+
/**
|
|
182
|
+
* Save, then — with a remote — probe, fetch, merge, push. Leaves `problem`
|
|
183
|
+
* for `status()` to report. Only the steps that touch the index and working
|
|
184
|
+
* copy hold the store's lock: the network calls have no timeout, and a save,
|
|
185
|
+
* a delete or an undo waiting behind an unreachable remote would read as the
|
|
186
|
+
* app not responding. Fetch writes refs and objects only, and push reads
|
|
187
|
+
* them, so a local commit landing beside either is safe.
|
|
188
|
+
*/
|
|
189
|
+
private doSync;
|
|
190
|
+
/**
|
|
191
|
+
* Merge both policy dimensions before looking at bytes. Sharing fails closed
|
|
192
|
+
* on a concurrent edit to the same rule — bytes are at stake. Listing is only
|
|
193
|
+
* about what Tomrade volunteers, so a clash settles on the quieter side
|
|
194
|
+
* instead of stopping the exchange.
|
|
195
|
+
*/
|
|
196
|
+
private mergePolicy;
|
|
197
|
+
private mergeDimension;
|
|
198
|
+
private reconcile;
|
|
199
|
+
private stage;
|
|
200
|
+
conflicts(): Promise<FileConflict[]>;
|
|
201
|
+
resolve(p: string, choice: ConflictChoice): Promise<void>;
|
|
202
|
+
/** "notes (theirs).md", or "notes (theirs 2).md" when that is taken too. */
|
|
203
|
+
private sibling;
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=git-store.d.ts.map
|