@indigoai-us/hq-cloud 6.18.59 → 6.18.61
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/dist/bin/sync-runner-company.d.ts.map +1 -1
- package/dist/bin/sync-runner-company.js +3 -2
- package/dist/bin/sync-runner-company.js.map +1 -1
- package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-loop.js +5 -2
- package/dist/bin/sync-runner-watch-loop.js.map +1 -1
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +8 -1
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/cli/share.d.ts +1 -1
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +300 -23
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/sync.d.ts +13 -1
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +193 -8
- package/dist/cli/sync.js.map +1 -1
- package/dist/cloud-placeholder.d.ts +67 -0
- package/dist/cloud-placeholder.d.ts.map +1 -0
- package/dist/cloud-placeholder.js +300 -0
- package/dist/cloud-placeholder.js.map +1 -0
- package/dist/conflict-notices.d.ts +18 -1
- package/dist/conflict-notices.d.ts.map +1 -1
- package/dist/conflict-notices.js +27 -2
- package/dist/conflict-notices.js.map +1 -1
- package/dist/hq-root-recovery.d.ts +57 -5
- package/dist/hq-root-recovery.d.ts.map +1 -1
- package/dist/hq-root-recovery.js +172 -3
- package/dist/hq-root-recovery.js.map +1 -1
- package/dist/ignore.d.ts +29 -1
- package/dist/ignore.d.ts.map +1 -1
- package/dist/ignore.js +51 -5
- package/dist/ignore.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/conflict-index.d.ts +22 -0
- package/dist/lib/conflict-index.d.ts.map +1 -1
- package/dist/lib/conflict-index.js +62 -1
- package/dist/lib/conflict-index.js.map +1 -1
- package/dist/lib/same-path-upload-lock.d.ts +104 -0
- package/dist/lib/same-path-upload-lock.d.ts.map +1 -0
- package/dist/lib/same-path-upload-lock.js +257 -0
- package/dist/lib/same-path-upload-lock.js.map +1 -0
- package/dist/personal-vault.d.ts.map +1 -1
- package/dist/personal-vault.js +5 -1
- package/dist/personal-vault.js.map +1 -1
- package/dist/session-log-capture.d.ts +10 -0
- package/dist/session-log-capture.d.ts.map +1 -1
- package/dist/session-log-capture.js +140 -14
- package/dist/session-log-capture.js.map +1 -1
- package/dist/sync/pull-scope.d.ts +7 -0
- package/dist/sync/pull-scope.d.ts.map +1 -1
- package/dist/sync/pull-scope.js +7 -0
- package/dist/sync/pull-scope.js.map +1 -1
- package/dist/sync-decision-log.d.ts +1 -1
- package/dist/sync-decision-log.d.ts.map +1 -1
- package/dist/sync-decision-log.js.map +1 -1
- package/dist/watch-owner-lease.d.ts +14 -0
- package/dist/watch-owner-lease.d.ts.map +1 -1
- package/dist/watch-owner-lease.js +17 -0
- package/dist/watch-owner-lease.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export declare const CLOUD_PLACEHOLDER_SUFFIX = ".hqcloud";
|
|
2
|
+
export declare const CLOUD_PLACEHOLDER_HEADER = "HQ-CLOUD-FILE v1";
|
|
3
|
+
/** Placeholders are written < 1 KB; anything past this is not one. */
|
|
4
|
+
export declare const CLOUD_PLACEHOLDER_MAX_BYTES = 4096;
|
|
5
|
+
export interface CloudPlaceholder {
|
|
6
|
+
/** HQ-root-relative (or vault-relative) POSIX path of the original file. */
|
|
7
|
+
path: string;
|
|
8
|
+
size: number;
|
|
9
|
+
/** Lowercase hex digest, or `null` when recorded as `unknown`. */
|
|
10
|
+
sha256: string | null;
|
|
11
|
+
gitBlob?: string;
|
|
12
|
+
vault: "personal" | "company";
|
|
13
|
+
key: string;
|
|
14
|
+
offloadedAt?: string;
|
|
15
|
+
remoteEtag?: string;
|
|
16
|
+
retrieve?: string;
|
|
17
|
+
/** Set by sync when the remote object was deleted after the offload. */
|
|
18
|
+
orphaned?: boolean;
|
|
19
|
+
orphanedReason?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Parse placeholder text. Returns `null` for anything that is not a complete
|
|
23
|
+
* HQ-CLOUD-FILE v1 record. Never throws.
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseCloudPlaceholder(text: string): CloudPlaceholder | null;
|
|
26
|
+
/** Render a placeholder in the canonical v1 layout. */
|
|
27
|
+
export declare function formatCloudPlaceholder(p: CloudPlaceholder): string;
|
|
28
|
+
export declare function cloudPlaceholderPathFor(localPath: string): string;
|
|
29
|
+
export declare function isCloudPlaceholderName(name: string): boolean;
|
|
30
|
+
/** Test hook: forget which placeholders were already logged. */
|
|
31
|
+
export declare function resetCloudPlaceholderWarningsForTesting(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Read and validate the placeholder at `placeholderPath`, which must stand in
|
|
34
|
+
* for `originalLocalPath`. Returns `null` (logging once) when it is missing a
|
|
35
|
+
* required field, names another file, or is too large to be a placeholder.
|
|
36
|
+
* Returns `null` silently when no placeholder exists.
|
|
37
|
+
*/
|
|
38
|
+
export declare function readCloudPlaceholder(placeholderPath: string, originalLocalPath?: string): CloudPlaceholder | null;
|
|
39
|
+
/**
|
|
40
|
+
* True when `localPath` is absent and a valid placeholder for it sits beside
|
|
41
|
+
* it. Callers use this to keep a missing file from being treated as deleted.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isCloudOnlyLocally(localPath: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* True when `localPath` is absent and ANY regular file `<localPath>.hqcloud`
|
|
46
|
+
* sits beside it, valid or not. Push uses this to refuse a remote delete: a
|
|
47
|
+
* malformed, mismatched, or future-format placeholder still means the user
|
|
48
|
+
* did not delete the file. Invalid placeholders are logged once.
|
|
49
|
+
*/
|
|
50
|
+
export declare function hasCloudPlaceholderSibling(localPath: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* True for a `.hqcloud` file that is a valid placeholder for its sibling.
|
|
53
|
+
* Push uses this to keep placeholders out of vault uploads.
|
|
54
|
+
*/
|
|
55
|
+
export declare function isValidCloudPlaceholderFile(placeholderPath: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Mark the valid placeholder for `localPath` as orphaned: the remote object it
|
|
58
|
+
* points at was deleted (a teammate's delete or a vault tombstone). The file
|
|
59
|
+
* stays on disk so the user can see what happened; fetchers must refuse it so
|
|
60
|
+
* a later fetch + push cannot undo the delete. Returns true when it wrote.
|
|
61
|
+
*/
|
|
62
|
+
export declare function markCloudPlaceholderOrphaned(localPath: string, reason: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Atomically rewrite a placeholder (temp file + rename in the same folder).
|
|
65
|
+
*/
|
|
66
|
+
export declare function writeCloudPlaceholder(placeholderPath: string, placeholder: CloudPlaceholder): void;
|
|
67
|
+
//# sourceMappingURL=cloud-placeholder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-placeholder.d.ts","sourceRoot":"","sources":["../src/cloud-placeholder.ts"],"names":[],"mappings":"AAoDA,eAAO,MAAM,wBAAwB,aAAa,CAAC;AACnD,eAAO,MAAM,wBAAwB,qBAAqB,CAAC;AAC3D,sEAAsE;AACtE,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAEhD,MAAM,WAAW,gBAAgB;IAC/B,4EAA4E;IAC5E,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,kEAAkE;IAClE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAID;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAuC3E;AAED,uDAAuD;AACvD,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAsBlE;AAED,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5D;AAYD,gEAAgE;AAChE,wBAAgB,uCAAuC,IAAI,IAAI,CAE9D;AAoBD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,MAAM,EACvB,iBAAiB,GAAE,MAAmE,GACrF,gBAAgB,GAAG,IAAI,CAiCzB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAS7D;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAiBrE;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAG5E;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAOvF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,eAAe,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,GAAG,IAAI,CASlG"}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HQ cloud-only placeholders (`<name>.hqcloud`).
|
|
3
|
+
*
|
|
4
|
+
* `hq storage offload --current` (hq-cli) uploads an idle large file to the
|
|
5
|
+
* user's personal vault, removes it locally, and leaves a small sibling text
|
|
6
|
+
* file `<name>.hqcloud` describing where the bytes live. To sync, the
|
|
7
|
+
* original path is "cloud-only locally", not deleted:
|
|
8
|
+
*
|
|
9
|
+
* - push never plans a remote delete for `x` while a valid `x.hqcloud`
|
|
10
|
+
* describes it, and never uploads the placeholder itself;
|
|
11
|
+
* - pull never re-downloads `x` over a valid placeholder, and when the
|
|
12
|
+
* remote object changed it rewrites the placeholder metadata instead.
|
|
13
|
+
*
|
|
14
|
+
* A placeholder only counts as cloud-only (pull skips the download) when it
|
|
15
|
+
* parses as HQ-CLOUD-FILE v1 AND its `path` names the exact file it stands in
|
|
16
|
+
* for. Delete suppression is wider: ANY sibling `x.hqcloud`, valid or not,
|
|
17
|
+
* blocks a remote delete of `x`, because a missed delete only leaves a stale
|
|
18
|
+
* remote copy while a wrong delete removes teammates' files. No `*.hqcloud`
|
|
19
|
+
* file is ever uploaded. Each rejected placeholder is logged once per process.
|
|
20
|
+
*
|
|
21
|
+
* Format (UTF-8, < 1 KB):
|
|
22
|
+
*
|
|
23
|
+
* HQ-CLOUD-FILE v1
|
|
24
|
+
* path: companies/acme/media/promo.mp4
|
|
25
|
+
* size: 524288000
|
|
26
|
+
* sha256: <64 hex>
|
|
27
|
+
* git-blob: <sha1> (optional)
|
|
28
|
+
* vault: personal|company
|
|
29
|
+
* key: .hq-offload/blobs/<sha>
|
|
30
|
+
* offloaded-at: <ISO time> (optional)
|
|
31
|
+
* remote-etag: <etag> (optional; written by sync when it updates
|
|
32
|
+
* the placeholder after a remote change)
|
|
33
|
+
* retrieve: hq storage fetch "<path>" (optional)
|
|
34
|
+
* orphaned: true (optional; written by sync when a teammate
|
|
35
|
+
* deleted the remote object)
|
|
36
|
+
* orphaned-reason: <text> (optional; why it was orphaned)
|
|
37
|
+
* <free text>
|
|
38
|
+
*
|
|
39
|
+
* When sync records a teammate's newer remote version it cannot know that
|
|
40
|
+
* version's sha256 without downloading it, so it writes `sha256: unknown`,
|
|
41
|
+
* `vault: company`, `key: <vault key>` and `remote-etag: <etag>`. Fetchers
|
|
42
|
+
* must verify by size and ETag in that case.
|
|
43
|
+
*
|
|
44
|
+
* When a pull sees the remote `x` deleted (tombstone, or gone from the vault)
|
|
45
|
+
* while a valid `x.hqcloud` is held, sync rewrites the placeholder with
|
|
46
|
+
* `orphaned: true` and keeps it so the user can see what happened. Fetchers
|
|
47
|
+
* must refuse an orphaned placeholder (or warn and require explicit
|
|
48
|
+
* confirmation); restoring it would undo the teammate's delete.
|
|
49
|
+
*/
|
|
50
|
+
import * as fs from "fs";
|
|
51
|
+
import * as path from "path";
|
|
52
|
+
export const CLOUD_PLACEHOLDER_SUFFIX = ".hqcloud";
|
|
53
|
+
export const CLOUD_PLACEHOLDER_HEADER = "HQ-CLOUD-FILE v1";
|
|
54
|
+
/** Placeholders are written < 1 KB; anything past this is not one. */
|
|
55
|
+
export const CLOUD_PLACEHOLDER_MAX_BYTES = 4096;
|
|
56
|
+
const SHA256_RE = /^[0-9a-f]{64}$/;
|
|
57
|
+
/**
|
|
58
|
+
* Parse placeholder text. Returns `null` for anything that is not a complete
|
|
59
|
+
* HQ-CLOUD-FILE v1 record. Never throws.
|
|
60
|
+
*/
|
|
61
|
+
export function parseCloudPlaceholder(text) {
|
|
62
|
+
const lines = text.replace(/^\uFEFF/, "").split(/\r?\n/);
|
|
63
|
+
if (lines[0]?.trim() !== CLOUD_PLACEHOLDER_HEADER)
|
|
64
|
+
return null;
|
|
65
|
+
const fields = new Map();
|
|
66
|
+
for (const line of lines.slice(1)) {
|
|
67
|
+
const match = /^([a-z0-9-]+):\s?(.*)$/.exec(line);
|
|
68
|
+
if (!match)
|
|
69
|
+
continue;
|
|
70
|
+
if (!fields.has(match[1]))
|
|
71
|
+
fields.set(match[1], match[2].trim());
|
|
72
|
+
}
|
|
73
|
+
const p = fields.get("path");
|
|
74
|
+
const sizeText = fields.get("size");
|
|
75
|
+
const shaText = fields.get("sha256")?.toLowerCase();
|
|
76
|
+
const vault = fields.get("vault");
|
|
77
|
+
const key = fields.get("key");
|
|
78
|
+
if (!p || !sizeText || !shaText || !key)
|
|
79
|
+
return null;
|
|
80
|
+
if (!/^\d+$/.test(sizeText))
|
|
81
|
+
return null;
|
|
82
|
+
const size = Number(sizeText);
|
|
83
|
+
if (!Number.isSafeInteger(size))
|
|
84
|
+
return null;
|
|
85
|
+
if (shaText !== "unknown" && !SHA256_RE.test(shaText))
|
|
86
|
+
return null;
|
|
87
|
+
if (vault !== "personal" && vault !== "company")
|
|
88
|
+
return null;
|
|
89
|
+
const placeholder = {
|
|
90
|
+
path: p,
|
|
91
|
+
size,
|
|
92
|
+
sha256: shaText === "unknown" ? null : shaText,
|
|
93
|
+
vault,
|
|
94
|
+
key,
|
|
95
|
+
};
|
|
96
|
+
const gitBlob = fields.get("git-blob");
|
|
97
|
+
if (gitBlob)
|
|
98
|
+
placeholder.gitBlob = gitBlob;
|
|
99
|
+
const offloadedAt = fields.get("offloaded-at");
|
|
100
|
+
if (offloadedAt)
|
|
101
|
+
placeholder.offloadedAt = offloadedAt;
|
|
102
|
+
const remoteEtag = fields.get("remote-etag");
|
|
103
|
+
if (remoteEtag)
|
|
104
|
+
placeholder.remoteEtag = remoteEtag;
|
|
105
|
+
const retrieve = fields.get("retrieve");
|
|
106
|
+
if (retrieve)
|
|
107
|
+
placeholder.retrieve = retrieve;
|
|
108
|
+
if (fields.get("orphaned")?.toLowerCase() === "true")
|
|
109
|
+
placeholder.orphaned = true;
|
|
110
|
+
const orphanedReason = fields.get("orphaned-reason");
|
|
111
|
+
if (orphanedReason)
|
|
112
|
+
placeholder.orphanedReason = orphanedReason;
|
|
113
|
+
return placeholder;
|
|
114
|
+
}
|
|
115
|
+
/** Render a placeholder in the canonical v1 layout. */
|
|
116
|
+
export function formatCloudPlaceholder(p) {
|
|
117
|
+
const lines = [
|
|
118
|
+
CLOUD_PLACEHOLDER_HEADER,
|
|
119
|
+
`path: ${p.path}`,
|
|
120
|
+
`size: ${p.size}`,
|
|
121
|
+
`sha256: ${p.sha256 ?? "unknown"}`,
|
|
122
|
+
];
|
|
123
|
+
if (p.gitBlob)
|
|
124
|
+
lines.push(`git-blob: ${p.gitBlob}`);
|
|
125
|
+
lines.push(`vault: ${p.vault}`, `key: ${p.key}`);
|
|
126
|
+
if (p.offloadedAt)
|
|
127
|
+
lines.push(`offloaded-at: ${p.offloadedAt}`);
|
|
128
|
+
if (p.remoteEtag)
|
|
129
|
+
lines.push(`remote-etag: ${p.remoteEtag}`);
|
|
130
|
+
lines.push(`retrieve: ${p.retrieve ?? `hq storage fetch "${p.path}"`}`);
|
|
131
|
+
if (p.orphaned) {
|
|
132
|
+
lines.push("orphaned: true");
|
|
133
|
+
if (p.orphanedReason) {
|
|
134
|
+
lines.push(`orphaned-reason: ${p.orphanedReason.replace(/[\r\n]+/g, " ")}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
lines.push("This file is stored in HQ cloud storage. Open it in HQ, or run the command above to download it.");
|
|
138
|
+
return `${lines.join("\n")}\n`;
|
|
139
|
+
}
|
|
140
|
+
export function cloudPlaceholderPathFor(localPath) {
|
|
141
|
+
return `${localPath}${CLOUD_PLACEHOLDER_SUFFIX}`;
|
|
142
|
+
}
|
|
143
|
+
export function isCloudPlaceholderName(name) {
|
|
144
|
+
return name.endsWith(CLOUD_PLACEHOLDER_SUFFIX) && name.length > CLOUD_PLACEHOLDER_SUFFIX.length;
|
|
145
|
+
}
|
|
146
|
+
const warned = new Set();
|
|
147
|
+
function warnOnce(placeholderPath, reason) {
|
|
148
|
+
if (warned.has(placeholderPath))
|
|
149
|
+
return;
|
|
150
|
+
warned.add(placeholderPath);
|
|
151
|
+
console.error(` Warning: ${placeholderPath} is not a valid HQ cloud placeholder (${reason}); it will not be uploaded, and sync will not delete the file it names.`);
|
|
152
|
+
}
|
|
153
|
+
/** Test hook: forget which placeholders were already logged. */
|
|
154
|
+
export function resetCloudPlaceholderWarningsForTesting() {
|
|
155
|
+
warned.clear();
|
|
156
|
+
}
|
|
157
|
+
function toPosix(p) {
|
|
158
|
+
return p.split(path.sep).join("/");
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* True when the placeholder's `path` names `originalLocalPath`. The recorded
|
|
162
|
+
* path is HQ-root-relative while sync roots are often a company folder, so
|
|
163
|
+
* the absolute original path must END with the recorded path on a segment
|
|
164
|
+
* boundary.
|
|
165
|
+
*/
|
|
166
|
+
function placeholderNamesPath(placeholder, originalLocalPath) {
|
|
167
|
+
// Windows writers may record `companies\acme\x.mp4`; compare as POSIX.
|
|
168
|
+
const recorded = placeholder.path.replace(/\\/g, "/").replace(/^\.?\/+/, "");
|
|
169
|
+
if (!recorded || recorded.split("/").includes(".."))
|
|
170
|
+
return false;
|
|
171
|
+
const absolute = toPosix(path.resolve(originalLocalPath)).replace(/\\/g, "/");
|
|
172
|
+
return absolute === recorded || absolute.endsWith(`/${recorded}`);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Read and validate the placeholder at `placeholderPath`, which must stand in
|
|
176
|
+
* for `originalLocalPath`. Returns `null` (logging once) when it is missing a
|
|
177
|
+
* required field, names another file, or is too large to be a placeholder.
|
|
178
|
+
* Returns `null` silently when no placeholder exists.
|
|
179
|
+
*/
|
|
180
|
+
export function readCloudPlaceholder(placeholderPath, originalLocalPath = placeholderPath.slice(0, -CLOUD_PLACEHOLDER_SUFFIX.length)) {
|
|
181
|
+
let stat;
|
|
182
|
+
try {
|
|
183
|
+
stat = fs.lstatSync(placeholderPath);
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
const code = err?.code;
|
|
187
|
+
if (code !== "ENOENT" && code !== "ENOTDIR") {
|
|
188
|
+
warnOnce(placeholderPath, `unreadable: ${code ?? String(err)}`);
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
if (!stat.isFile())
|
|
193
|
+
return null;
|
|
194
|
+
if (stat.size > CLOUD_PLACEHOLDER_MAX_BYTES) {
|
|
195
|
+
warnOnce(placeholderPath, "too large");
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
let text;
|
|
199
|
+
try {
|
|
200
|
+
text = fs.readFileSync(placeholderPath, "utf8");
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
warnOnce(placeholderPath, `unreadable: ${err.message}`);
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
const parsed = parseCloudPlaceholder(text);
|
|
207
|
+
if (!parsed) {
|
|
208
|
+
warnOnce(placeholderPath, "malformed");
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
if (!placeholderNamesPath(parsed, originalLocalPath)) {
|
|
212
|
+
warnOnce(placeholderPath, `path mismatch: ${parsed.path}`);
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
return parsed;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* True when `localPath` is absent and a valid placeholder for it sits beside
|
|
219
|
+
* it. Callers use this to keep a missing file from being treated as deleted.
|
|
220
|
+
*/
|
|
221
|
+
export function isCloudOnlyLocally(localPath) {
|
|
222
|
+
try {
|
|
223
|
+
fs.lstatSync(localPath);
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
catch (err) {
|
|
227
|
+
const code = err?.code;
|
|
228
|
+
if (code !== "ENOENT")
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
return readCloudPlaceholder(cloudPlaceholderPathFor(localPath), localPath) !== null;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* True when `localPath` is absent and ANY regular file `<localPath>.hqcloud`
|
|
235
|
+
* sits beside it, valid or not. Push uses this to refuse a remote delete: a
|
|
236
|
+
* malformed, mismatched, or future-format placeholder still means the user
|
|
237
|
+
* did not delete the file. Invalid placeholders are logged once.
|
|
238
|
+
*/
|
|
239
|
+
export function hasCloudPlaceholderSibling(localPath) {
|
|
240
|
+
try {
|
|
241
|
+
fs.lstatSync(localPath);
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
const code = err?.code;
|
|
246
|
+
if (code !== "ENOENT")
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
const placeholderPath = cloudPlaceholderPathFor(localPath);
|
|
250
|
+
try {
|
|
251
|
+
if (!fs.lstatSync(placeholderPath).isFile())
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
// Parsed only for the one-time warning; the answer does not depend on it.
|
|
258
|
+
readCloudPlaceholder(placeholderPath, localPath);
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* True for a `.hqcloud` file that is a valid placeholder for its sibling.
|
|
263
|
+
* Push uses this to keep placeholders out of vault uploads.
|
|
264
|
+
*/
|
|
265
|
+
export function isValidCloudPlaceholderFile(placeholderPath) {
|
|
266
|
+
if (!isCloudPlaceholderName(path.basename(placeholderPath)))
|
|
267
|
+
return false;
|
|
268
|
+
return readCloudPlaceholder(placeholderPath) !== null;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Mark the valid placeholder for `localPath` as orphaned: the remote object it
|
|
272
|
+
* points at was deleted (a teammate's delete or a vault tombstone). The file
|
|
273
|
+
* stays on disk so the user can see what happened; fetchers must refuse it so
|
|
274
|
+
* a later fetch + push cannot undo the delete. Returns true when it wrote.
|
|
275
|
+
*/
|
|
276
|
+
export function markCloudPlaceholderOrphaned(localPath, reason) {
|
|
277
|
+
if (!isCloudOnlyLocally(localPath))
|
|
278
|
+
return false;
|
|
279
|
+
const placeholderPath = cloudPlaceholderPathFor(localPath);
|
|
280
|
+
const current = readCloudPlaceholder(placeholderPath, localPath);
|
|
281
|
+
if (!current || current.orphaned)
|
|
282
|
+
return false;
|
|
283
|
+
writeCloudPlaceholder(placeholderPath, { ...current, orphaned: true, orphanedReason: reason });
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Atomically rewrite a placeholder (temp file + rename in the same folder).
|
|
288
|
+
*/
|
|
289
|
+
export function writeCloudPlaceholder(placeholderPath, placeholder) {
|
|
290
|
+
const tmp = `${placeholderPath}.${process.pid}.${Date.now()}.tmp`;
|
|
291
|
+
fs.writeFileSync(tmp, formatCloudPlaceholder(placeholder), "utf8");
|
|
292
|
+
try {
|
|
293
|
+
fs.renameSync(tmp, placeholderPath);
|
|
294
|
+
}
|
|
295
|
+
catch (err) {
|
|
296
|
+
fs.rmSync(tmp, { force: true });
|
|
297
|
+
throw err;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=cloud-placeholder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud-placeholder.js","sourceRoot":"","sources":["../src/cloud-placeholder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,CAAC,MAAM,wBAAwB,GAAG,UAAU,CAAC;AACnD,MAAM,CAAC,MAAM,wBAAwB,GAAG,kBAAkB,CAAC;AAC3D,sEAAsE;AACtE,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAmBhD,MAAM,SAAS,GAAG,gBAAgB,CAAC;AAEnC;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,wBAAwB;QAAE,OAAO,IAAI,CAAC;IAC/D,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,KAAK,MAAM,IAAI,IAA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C,SAAiB,EAAE,MAAc;IAC5E,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC;QAAE,OAAO,KAAK,CAAC;IACjD,MAAM,eAAe,GAAG,uBAAuB,CAAC,SAAS,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,oBAAoB,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;IACjE,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC/C,qBAAqB,CAAC,eAAe,EAAE,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC;IAC/F,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,eAAuB,EAAE,WAA6B;IAC1F,MAAM,GAAG,GAAG,GAAG,eAAe,IAAI,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC;IAClE,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,sBAAsB,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC;IACnE,IAAI,CAAC;QACH,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACtC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAChC,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -11,8 +11,25 @@ export interface ConflictParkedNotice {
|
|
|
11
11
|
sideKept: ConflictKeptSide;
|
|
12
12
|
parkedAt: string;
|
|
13
13
|
}
|
|
14
|
-
export type RecordConflictParkedInput = Omit<ConflictParkedNotice, "id"
|
|
14
|
+
export type RecordConflictParkedInput = Omit<ConflictParkedNotice, "id"> & {
|
|
15
|
+
/**
|
|
16
|
+
* Hash of the local body and normalized etag of the remote version at park
|
|
17
|
+
* time. With scope and path they identify one divergence and derive the
|
|
18
|
+
* notice id. They are inputs only: the stored notice stays content-free.
|
|
19
|
+
*/
|
|
20
|
+
localHash?: string;
|
|
21
|
+
remoteEtag?: string;
|
|
22
|
+
};
|
|
15
23
|
export declare function conflictNoticeId(scope: "company" | "personal", companySlug: string | null, backupPath: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Id of the divergence a notice reports: (scope, company, path, local hash,
|
|
26
|
+
* remote etag). The backup path carries a timestamp, so ids derived from it
|
|
27
|
+
* made every re-park of an unchanged file a new notice; 29 of the 50 queued
|
|
28
|
+
* notices on 2026-10-10 were repeats of 3 INDEX.md files and evicted real
|
|
29
|
+
* conflicts from the bounded queue. Repeats of one divergence now share an
|
|
30
|
+
* id, so they neither re-queue nor re-announce after an acknowledgement.
|
|
31
|
+
*/
|
|
32
|
+
export declare function conflictDivergenceNoticeId(scope: "company" | "personal", companySlug: string | null, relativePath: string, localHash: string, remoteEtag: string): string;
|
|
16
33
|
/** Record only after the caller has confirmed that the backup was written. */
|
|
17
34
|
export declare function recordConflictParked(input: RecordConflictParkedInput): ConflictParkedNotice;
|
|
18
35
|
/** Append a tombstone in a separate O_APPEND file; it never rewrites runner data. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conflict-notices.d.ts","sourceRoot":"","sources":["../src/conflict-notices.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C,MAAM,MAAM,oBAAoB,GAC5B,aAAa,GACb,cAAc,GACd,8BAA8B,CAAC;AACnC,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,QAAQ,CAAC;AAElD,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,SAAS,GAAG,UAAU,CAAC;IAC9B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CA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EAAE,MAAM,GACjB,MAAM,CASR;AA4GD,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,oBAAoB,CAmB3F;AAGD,qFAAqF;AACrF,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,MAAM,EAAE,cAAc,SAA2B,GAAG,IAAI,CAarG;AAED,wBAAgB,0BAA0B,IAAI,oBAAoB,EAAE,CAKnE"}
|
package/dist/conflict-notices.js
CHANGED
|
@@ -25,6 +25,30 @@ function lockRoot() {
|
|
|
25
25
|
export function conflictNoticeId(scope, companySlug, backupPath) {
|
|
26
26
|
return createHash("sha256").update(scope).update("\0").update(companySlug ?? "").update("\0").update(backupPath).digest("hex");
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Id of the divergence a notice reports: (scope, company, path, local hash,
|
|
30
|
+
* remote etag). The backup path carries a timestamp, so ids derived from it
|
|
31
|
+
* made every re-park of an unchanged file a new notice; 29 of the 50 queued
|
|
32
|
+
* notices on 2026-10-10 were repeats of 3 INDEX.md files and evicted real
|
|
33
|
+
* conflicts from the bounded queue. Repeats of one divergence now share an
|
|
34
|
+
* id, so they neither re-queue nor re-announce after an acknowledgement.
|
|
35
|
+
*/
|
|
36
|
+
export function conflictDivergenceNoticeId(scope, companySlug, relativePath, localHash, remoteEtag) {
|
|
37
|
+
return createHash("sha256")
|
|
38
|
+
.update("divergence-v1")
|
|
39
|
+
.update("\0").update(scope)
|
|
40
|
+
.update("\0").update(companySlug ?? "")
|
|
41
|
+
.update("\0").update(relativePath)
|
|
42
|
+
.update("\0").update(localHash)
|
|
43
|
+
.update("\0").update(remoteEtag)
|
|
44
|
+
.digest("hex");
|
|
45
|
+
}
|
|
46
|
+
function noticeIdFor(input) {
|
|
47
|
+
if (input.localHash && input.remoteEtag) {
|
|
48
|
+
return conflictDivergenceNoticeId(input.scope, input.companySlug, input.relativePath, input.localHash, input.remoteEtag);
|
|
49
|
+
}
|
|
50
|
+
return conflictNoticeId(input.scope, input.companySlug, input.backupPath);
|
|
51
|
+
}
|
|
28
52
|
function readNotices() {
|
|
29
53
|
try {
|
|
30
54
|
const parsed = JSON.parse(fs.readFileSync(noticesPath(), "utf8"));
|
|
@@ -127,9 +151,10 @@ function validateInput(input) {
|
|
|
127
151
|
/** Record only after the caller has confirmed that the backup was written. */
|
|
128
152
|
export function recordConflictParked(input) {
|
|
129
153
|
validateInput(input);
|
|
154
|
+
const { localHash: _localHash, remoteEtag: _remoteEtag, ...stored } = input;
|
|
130
155
|
const notice = {
|
|
131
|
-
...
|
|
132
|
-
id:
|
|
156
|
+
...stored,
|
|
157
|
+
id: noticeIdFor(input),
|
|
133
158
|
};
|
|
134
159
|
return withOperationLockSync(lockRoot(), "conflict-notices", () => {
|
|
135
160
|
const acknowledged = readAcknowledgedIds();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conflict-notices.js","sourceRoot":"","sources":["../src/conflict-notices.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"conflict-notices.js","sourceRoot":"","sources":["../src/conflict-notices.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;A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AAC,EAAE,CAAC,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,0BAA0B;IACxC,MAAM,YAAY,GAAG,mBAAmB,EAAE,CAAC;IAC3C,OAAO,WAAW,EAAE;SACjB,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SAChD,KAAK,CAAC,CAAC,4BAA4B,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -10,20 +10,72 @@
|
|
|
10
10
|
* which survived the 2026-09-18 wipe that removed `core/`, `personal/`, and
|
|
11
11
|
* `.git` while leaving the sync daemon running.
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
import * as fs from "fs";
|
|
14
|
+
export type GitSidecarAction = "restored" | "snapshotted" | "unchanged" | "absent"
|
|
15
|
+
/** A background snapshot failed; the error was logged. */
|
|
16
|
+
| "failed"
|
|
17
|
+
/** A background snapshot was skipped because a recent attempt failed. */
|
|
18
|
+
| "deferred"
|
|
19
|
+
/** A background snapshot was skipped: the copy would not leave the free-space reserve. */
|
|
20
|
+
| "insufficient-space";
|
|
14
21
|
export declare function gitSidecarDir(hqRoot: string, homeDir?: string): string;
|
|
15
22
|
export declare function shouldCopyGitSidecarEntry(src: string): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Only regular files, directories, and symlinks belong in the sidecar. Git's
|
|
25
|
+
* builtin fsmonitor leaves a Unix socket named `fsmonitor--daemon.ipc` in
|
|
26
|
+
* `.git`; Node 22's `fs.cpSync` hits an internal "Unreachable code" assertion
|
|
27
|
+
* on a socket, and FIFOs and device nodes are refused too, so one such entry
|
|
28
|
+
* made every snapshot fail. An entry that vanished mid-copy is skipped too.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isCopyableGitSidecarStats(stats: fs.Stats): boolean;
|
|
16
31
|
export declare function snapshotHqGit(hqRoot: string, opts?: {
|
|
17
32
|
homeDir?: string;
|
|
18
33
|
}): GitSidecarAction;
|
|
34
|
+
/** Wait this long before retrying a background snapshot that failed. */
|
|
35
|
+
export declare const GIT_SIDECAR_RETRY_AFTER_MS: number;
|
|
36
|
+
/**
|
|
37
|
+
* Free space the sidecar copy must leave on the destination volume. The HQ
|
|
38
|
+
* `.git` can be larger than the disk's remaining space; filling the disk
|
|
39
|
+
* stops sync itself (ENOSPC on its own lock and state files).
|
|
40
|
+
*/
|
|
41
|
+
export declare const GIT_SIDECAR_MIN_FREE_BYTES: number;
|
|
42
|
+
export interface GitSidecarSnapshotOptions {
|
|
43
|
+
homeDir?: string;
|
|
44
|
+
/** Test seam; production uses Date.now. */
|
|
45
|
+
now?: () => number;
|
|
46
|
+
retryAfterMs?: number;
|
|
47
|
+
/** Test seam; production reads `fs.promises.statfs` for the destination volume. */
|
|
48
|
+
freeBytes?: (dir: string) => Promise<number>;
|
|
49
|
+
minFreeBytes?: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Snapshot `.git` without blocking the caller's event loop. The HQ `.git` can
|
|
53
|
+
* be many gigabytes, and the watch runner calls this at startup and on every
|
|
54
|
+
* pass, so the copy runs on libuv's threadpool through `fs.promises.cp`.
|
|
55
|
+
* Concurrent calls for one sidecar share a single copy, and after a failed
|
|
56
|
+
* copy the next attempt waits `retryAfterMs` instead of recopying every pass.
|
|
57
|
+
* The copy is skipped when it would leave less than `minFreeBytes` free on
|
|
58
|
+
* the destination volume.
|
|
59
|
+
* The returned promise never rejects.
|
|
60
|
+
*/
|
|
61
|
+
export declare function snapshotHqGitInBackground(hqRoot: string, opts?: GitSidecarSnapshotOptions): Promise<GitSidecarAction>;
|
|
19
62
|
export declare function restoreHqGitIfMissing(hqRoot: string, opts?: {
|
|
20
63
|
homeDir?: string;
|
|
21
64
|
}): GitSidecarAction;
|
|
22
65
|
export declare function ensureLocalLayoutDirs(hqRoot: string): number;
|
|
66
|
+
export interface HqRootRecoveryResult {
|
|
67
|
+
layoutCreated: number;
|
|
68
|
+
/** "restored" when `.git` came back from the sidecar; otherwise "scheduled". */
|
|
69
|
+
git: GitSidecarAction | "scheduled";
|
|
70
|
+
/** Settles when the background `.git` snapshot finishes; never rejects. */
|
|
71
|
+
snapshot?: Promise<GitSidecarAction>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Restore `.git` and the empty layout dirs synchronously (sync must see them),
|
|
75
|
+
* then refresh the `.git` sidecar in the background so a large repository
|
|
76
|
+
* never stalls the watch runner's event loop.
|
|
77
|
+
*/
|
|
23
78
|
export declare function recoverHqRootLocalState(hqRoot: string, opts?: {
|
|
24
79
|
homeDir?: string;
|
|
25
|
-
}):
|
|
26
|
-
layoutCreated: number;
|
|
27
|
-
git: GitSidecarAction;
|
|
28
|
-
};
|
|
80
|
+
}): HqRootRecoveryResult;
|
|
29
81
|
//# sourceMappingURL=hq-root-recovery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hq-root-recovery.d.ts","sourceRoot":"","sources":["../src/hq-root-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"hq-root-recovery.d.ts","sourceRoot":"","sources":["../src/hq-root-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAQzB,MAAM,MAAM,gBAAgB,GACxB,UAAU,GACV,aAAa,GACb,WAAW,GACX,QAAQ;AACV,0DAA0D;GACxD,QAAQ;AACV,yEAAyE;GACvE,UAAU;AACZ,0FAA0F;GACxF,oBAAoB,CAAC;AAEzB,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,MAAqB,GAAG,MAAM,CAEpF;AAMD,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,OAAO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