@indigoai-us/hq-cloud 5.24.0 → 5.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/sync-runner.d.ts +51 -16
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +67 -3
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/bin/sync-runner.test.js +58 -15
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/share.d.ts +9 -0
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +54 -1
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/share.test.js +6 -3
- package/dist/cli/share.test.js.map +1 -1
- package/dist/cli/sync.d.ts +21 -0
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/personal-vault-exclusions.d.ts +128 -0
- package/dist/personal-vault-exclusions.d.ts.map +1 -0
- package/dist/personal-vault-exclusions.js +231 -0
- package/dist/personal-vault-exclusions.js.map +1 -0
- package/dist/personal-vault-exclusions.test.d.ts +22 -0
- package/dist/personal-vault-exclusions.test.d.ts.map +1 -0
- package/dist/personal-vault-exclusions.test.js +198 -0
- package/dist/personal-vault-exclusions.test.js.map +1 -0
- package/package.json +1 -1
- package/src/bin/sync-runner.test.ts +71 -15
- package/src/bin/sync-runner.ts +100 -19
- package/src/cli/share.test.ts +8 -3
- package/src/cli/share.ts +66 -1
- package/src/cli/sync.ts +22 -0
- package/src/index.ts +10 -0
- package/src/personal-vault-exclusions.test.ts +256 -0
- package/src/personal-vault-exclusions.ts +277 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personal-vault default exclusions — second-tier scope filter that complements
|
|
3
|
+
* `PERSONAL_VAULT_EXCLUDED_TOP_LEVEL` (`.git`, `companies`, `repos`,
|
|
4
|
+
* `workspace`) in `./personal-vault.ts`.
|
|
5
|
+
*
|
|
6
|
+
* Where the top-level constant filters the four big buckets at scope root, this
|
|
7
|
+
* file filters categories of nested files that ride along with an HQ install
|
|
8
|
+
* but have no business round-tripping to a personal vault — regardless of
|
|
9
|
+
* where they sit in the tree:
|
|
10
|
+
*
|
|
11
|
+
* 1. Secrets at root or nested. `.env`, `.env.local`, `.env.<anything>`,
|
|
12
|
+
* `.mcp.json`. Pre-fix these were being uploaded if the user hadn't
|
|
13
|
+
* added `.env` to their `.hqignore` (the default starter `.hqignore`
|
|
14
|
+
* only listed `companies/*\/settings/`).
|
|
15
|
+
*
|
|
16
|
+
* 2. Machine-local state. `.beads/` (SQLite issue-tracker + WAL/SHM),
|
|
17
|
+
* `.obsidian/`, `.vercel/`, `.cache_*`. Per-machine layouts/caches;
|
|
18
|
+
* multi-device sync either corrupts (SQLite WAL) or causes spurious
|
|
19
|
+
* churn (caches regenerate on demand).
|
|
20
|
+
*
|
|
21
|
+
* 3. Update-flow scratch. `output/`, `_legacy-*` directories. Created by
|
|
22
|
+
* `/update-hq` / `/promote-hq-core` workflows as checkout scratch;
|
|
23
|
+
* naming themselves "legacy" / sitting under "output" is a self-
|
|
24
|
+
* declared "do not preserve" signal.
|
|
25
|
+
*
|
|
26
|
+
* 4. Pre-5.24 conflict mirror dir. `.hq-conflicts/` is a directory of
|
|
27
|
+
* mirror copies from older sync runs (sibling to the now-fixed
|
|
28
|
+
* `.conflict-YYYY-MM-DDTHH-MM-SSZ-{hash}.{ext}` ephemeral files
|
|
29
|
+
* handled by `EPHEMERAL_PATH_PATTERN` in share.ts). Same logic
|
|
30
|
+
* applies: these are local-only safety backups.
|
|
31
|
+
*
|
|
32
|
+
* 5. OS / build cruft. `.DS_Store`, `node_modules/`, `dist/`, `.next/`,
|
|
33
|
+
* `build/`. Universally noise inside HQ (personal scope should not
|
|
34
|
+
* contain code projects, but defense-in-depth catches anyone who
|
|
35
|
+
* symlinks a project subtree in).
|
|
36
|
+
*
|
|
37
|
+
* Policy: refuse + warn (5.25 default). The walk filter drops these so they
|
|
38
|
+
* never upload; the delete-plan walker uses the same filter so already-
|
|
39
|
+
* journaled entries that match a new exclusion get orphaned in the journal
|
|
40
|
+
* (no DELETE issued, no churn). A one-shot purge script handles the cleanup
|
|
41
|
+
* of objects that landed on remote before this version.
|
|
42
|
+
*
|
|
43
|
+
* Application scope: personal vault only. Company vaults have separate
|
|
44
|
+
* first-push protection (settings/, data/, workers/, .git/ exclusion in
|
|
45
|
+
* `src-tauri/src/util/ignore.rs`) and may legitimately ship `output/` or
|
|
46
|
+
* `.env*` paths inside their data folders. Wired in `share.ts` only when
|
|
47
|
+
* `options.personalMode === true`.
|
|
48
|
+
*
|
|
49
|
+
* Wire-points (parallel to `EPHEMERAL_PATH_PATTERN`):
|
|
50
|
+
* - `collectFiles` / `walkDir` (push) — wrap `shouldSync` so excluded
|
|
51
|
+
* relative paths are rejected before upload.
|
|
52
|
+
* - `computeDeletePlan` (delete) — same `shouldSync` wrap, so journal
|
|
53
|
+
* entries matching an exclusion are skipped on the delete pass too.
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* Each entry is matched against the relative path from the personal-vault
|
|
57
|
+
* sync root (which IS hq_root in personalMode), using forward-slash
|
|
58
|
+
* separators. Patterns:
|
|
59
|
+
*
|
|
60
|
+
* - `prefix:foo/` — match if the path starts with `foo/` or equals `foo`
|
|
61
|
+
* (handles both the dir itself and any descendant)
|
|
62
|
+
* - `basename:.env` — match if any path segment equals `.env`
|
|
63
|
+
* - `basename:.env-prefix:.env.` — match if the basename starts with `.env.`
|
|
64
|
+
* - `segment:node_modules` — match if any path segment equals literally
|
|
65
|
+
*
|
|
66
|
+
* The literal-segment form catches nested cases (e.g., `repos/foo/node_modules/`
|
|
67
|
+
* is already excluded by top-level repos/ skip, but `personal/x/node_modules/`
|
|
68
|
+
* would slip through without segment matching).
|
|
69
|
+
*/
|
|
70
|
+
export interface PersonalVaultExclusion {
|
|
71
|
+
/** Internal id for telemetry / explainability in events. */
|
|
72
|
+
id: string;
|
|
73
|
+
/** Human-readable category for the warning event. */
|
|
74
|
+
category: "secret" | "machine-local" | "scratch" | "conflict-mirror" | "os-cruft" | "build-output";
|
|
75
|
+
/**
|
|
76
|
+
* Predicate. Pure: relative path (forward-slash separated, no leading slash)
|
|
77
|
+
* + optional isDir hint. Returns true to EXCLUDE.
|
|
78
|
+
*/
|
|
79
|
+
test: (relPath: string, isDir?: boolean) => boolean;
|
|
80
|
+
/** Doc-only — shown alongside `id` in the warning event sample. */
|
|
81
|
+
pattern: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Cheap segment-equality check. Avoids allocating a regex per call.
|
|
85
|
+
*/
|
|
86
|
+
declare function hasSegment(relPath: string, segment: string): boolean;
|
|
87
|
+
declare function basename(relPath: string): string;
|
|
88
|
+
export declare const PERSONAL_VAULT_DEFAULT_EXCLUSIONS: readonly PersonalVaultExclusion[];
|
|
89
|
+
/**
|
|
90
|
+
* First-match result for a path. Returns the matching exclusion (so callers
|
|
91
|
+
* can surface category/id in events) or undefined for "not excluded".
|
|
92
|
+
*/
|
|
93
|
+
export declare function matchPersonalVaultExclusion(relPath: string, isDir?: boolean): PersonalVaultExclusion | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Boolean version — true if any exclusion matches.
|
|
96
|
+
*/
|
|
97
|
+
export declare function isPersonalVaultExcluded(relPath: string, isDir?: boolean): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Wrap an existing path filter (typically from `createIgnoreFilter`) with the
|
|
100
|
+
* personal-vault default exclusions. The wrapper:
|
|
101
|
+
*
|
|
102
|
+
* 1. Calls the underlying filter first; if it already rejects, defer
|
|
103
|
+
* (counter does not fire — we only want to count things the underlying
|
|
104
|
+
* filter would have allowed but the personal-vault defaults reject).
|
|
105
|
+
* 2. Computes a relative path from `syncRoot` (the personal-vault sync
|
|
106
|
+
* root, which is hq_root in personalMode).
|
|
107
|
+
* 3. Probes `matchPersonalVaultExclusion`; if it matches, returns false
|
|
108
|
+
* and tags the match via `onExcluded` so the runner can emit a single
|
|
109
|
+
* `personal-vault-out-of-policy` event with a count + sample at end of
|
|
110
|
+
* run.
|
|
111
|
+
*
|
|
112
|
+
* The wrapper keeps the `(absolutePath, isDir) => boolean` shape the existing
|
|
113
|
+
* collectFiles / walkDir / computeDeletePlan code already uses, so wiring is
|
|
114
|
+
* a single line change at the share() filter construction site.
|
|
115
|
+
*/
|
|
116
|
+
export declare function wrapFilterWithPersonalVaultDefaults(underlying: (absPath: string, isDir?: boolean) => boolean, syncRoot: string, onExcluded: (relPath: string, match: PersonalVaultExclusion) => void): (absPath: string, isDir?: boolean) => boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Test-only export. Mirrors the `_testing` namespace pattern used by
|
|
119
|
+
* `share.ts` for `EPHEMERAL_PATH_PATTERN` — direct access to the list +
|
|
120
|
+
* internal helpers for regression-critical pinning without round-tripping
|
|
121
|
+
* through share().
|
|
122
|
+
*/
|
|
123
|
+
export declare const _testing: {
|
|
124
|
+
hasSegment: typeof hasSegment;
|
|
125
|
+
basename: typeof basename;
|
|
126
|
+
};
|
|
127
|
+
export {};
|
|
128
|
+
//# sourceMappingURL=personal-vault-exclusions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"personal-vault-exclusions.d.ts","sourceRoot":"","sources":["../src/personal-vault-exclusions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAIH;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,sBAAsB;IACrC,4DAA4D;IAC5D,EAAE,EAAE,MAAM,CAAC;IACX,qDAAqD;IACrD,QAAQ,EACJ,QAAQ,GACR,eAAe,GACf,SAAS,GACT,iBAAiB,GACjB,UAAU,GACV,cAAc,CAAC;IACnB;;;OAGG;IACH,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;IACpD,mEAAmE;IACnE,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,iBAAS,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAI7D;AAED,iBAAS,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGzC;AAED,eAAO,MAAM,iCAAiC,EAAE,SAAS,sBAAsB,EAsG9E,CAAC;AAEF;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,GACd,sBAAsB,GAAG,SAAS,CAKpC;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,OAAO,CAEjF;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mCAAmC,CACjD,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,EACzD,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,sBAAsB,KAAK,IAAI,GACnE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAY/C;AAED;;;;;GAKG;AACH,eAAO,MAAM,QAAQ;;;CAGpB,CAAC"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Personal-vault default exclusions — second-tier scope filter that complements
|
|
3
|
+
* `PERSONAL_VAULT_EXCLUDED_TOP_LEVEL` (`.git`, `companies`, `repos`,
|
|
4
|
+
* `workspace`) in `./personal-vault.ts`.
|
|
5
|
+
*
|
|
6
|
+
* Where the top-level constant filters the four big buckets at scope root, this
|
|
7
|
+
* file filters categories of nested files that ride along with an HQ install
|
|
8
|
+
* but have no business round-tripping to a personal vault — regardless of
|
|
9
|
+
* where they sit in the tree:
|
|
10
|
+
*
|
|
11
|
+
* 1. Secrets at root or nested. `.env`, `.env.local`, `.env.<anything>`,
|
|
12
|
+
* `.mcp.json`. Pre-fix these were being uploaded if the user hadn't
|
|
13
|
+
* added `.env` to their `.hqignore` (the default starter `.hqignore`
|
|
14
|
+
* only listed `companies/*\/settings/`).
|
|
15
|
+
*
|
|
16
|
+
* 2. Machine-local state. `.beads/` (SQLite issue-tracker + WAL/SHM),
|
|
17
|
+
* `.obsidian/`, `.vercel/`, `.cache_*`. Per-machine layouts/caches;
|
|
18
|
+
* multi-device sync either corrupts (SQLite WAL) or causes spurious
|
|
19
|
+
* churn (caches regenerate on demand).
|
|
20
|
+
*
|
|
21
|
+
* 3. Update-flow scratch. `output/`, `_legacy-*` directories. Created by
|
|
22
|
+
* `/update-hq` / `/promote-hq-core` workflows as checkout scratch;
|
|
23
|
+
* naming themselves "legacy" / sitting under "output" is a self-
|
|
24
|
+
* declared "do not preserve" signal.
|
|
25
|
+
*
|
|
26
|
+
* 4. Pre-5.24 conflict mirror dir. `.hq-conflicts/` is a directory of
|
|
27
|
+
* mirror copies from older sync runs (sibling to the now-fixed
|
|
28
|
+
* `.conflict-YYYY-MM-DDTHH-MM-SSZ-{hash}.{ext}` ephemeral files
|
|
29
|
+
* handled by `EPHEMERAL_PATH_PATTERN` in share.ts). Same logic
|
|
30
|
+
* applies: these are local-only safety backups.
|
|
31
|
+
*
|
|
32
|
+
* 5. OS / build cruft. `.DS_Store`, `node_modules/`, `dist/`, `.next/`,
|
|
33
|
+
* `build/`. Universally noise inside HQ (personal scope should not
|
|
34
|
+
* contain code projects, but defense-in-depth catches anyone who
|
|
35
|
+
* symlinks a project subtree in).
|
|
36
|
+
*
|
|
37
|
+
* Policy: refuse + warn (5.25 default). The walk filter drops these so they
|
|
38
|
+
* never upload; the delete-plan walker uses the same filter so already-
|
|
39
|
+
* journaled entries that match a new exclusion get orphaned in the journal
|
|
40
|
+
* (no DELETE issued, no churn). A one-shot purge script handles the cleanup
|
|
41
|
+
* of objects that landed on remote before this version.
|
|
42
|
+
*
|
|
43
|
+
* Application scope: personal vault only. Company vaults have separate
|
|
44
|
+
* first-push protection (settings/, data/, workers/, .git/ exclusion in
|
|
45
|
+
* `src-tauri/src/util/ignore.rs`) and may legitimately ship `output/` or
|
|
46
|
+
* `.env*` paths inside their data folders. Wired in `share.ts` only when
|
|
47
|
+
* `options.personalMode === true`.
|
|
48
|
+
*
|
|
49
|
+
* Wire-points (parallel to `EPHEMERAL_PATH_PATTERN`):
|
|
50
|
+
* - `collectFiles` / `walkDir` (push) — wrap `shouldSync` so excluded
|
|
51
|
+
* relative paths are rejected before upload.
|
|
52
|
+
* - `computeDeletePlan` (delete) — same `shouldSync` wrap, so journal
|
|
53
|
+
* entries matching an exclusion are skipped on the delete pass too.
|
|
54
|
+
*/
|
|
55
|
+
import * as path from "path";
|
|
56
|
+
/**
|
|
57
|
+
* Cheap segment-equality check. Avoids allocating a regex per call.
|
|
58
|
+
*/
|
|
59
|
+
function hasSegment(relPath, segment) {
|
|
60
|
+
if (relPath === segment)
|
|
61
|
+
return true;
|
|
62
|
+
if (relPath.startsWith(`${segment}/`))
|
|
63
|
+
return true;
|
|
64
|
+
return relPath.includes(`/${segment}/`) || relPath.endsWith(`/${segment}`);
|
|
65
|
+
}
|
|
66
|
+
function basename(relPath) {
|
|
67
|
+
const i = relPath.lastIndexOf("/");
|
|
68
|
+
return i === -1 ? relPath : relPath.slice(i + 1);
|
|
69
|
+
}
|
|
70
|
+
export const PERSONAL_VAULT_DEFAULT_EXCLUSIONS = [
|
|
71
|
+
// ── secrets ───────────────────────────────────────────────────────────
|
|
72
|
+
{
|
|
73
|
+
id: "env-file",
|
|
74
|
+
category: "secret",
|
|
75
|
+
pattern: "**/.env, **/.env.*",
|
|
76
|
+
test: (p) => {
|
|
77
|
+
const b = basename(p);
|
|
78
|
+
return b === ".env" || b.startsWith(".env.");
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: "mcp-config",
|
|
83
|
+
category: "secret",
|
|
84
|
+
pattern: "**/.mcp.json",
|
|
85
|
+
test: (p) => basename(p) === ".mcp.json",
|
|
86
|
+
},
|
|
87
|
+
// ── machine-local tooling state ───────────────────────────────────────
|
|
88
|
+
{
|
|
89
|
+
id: "beads-db",
|
|
90
|
+
category: "machine-local",
|
|
91
|
+
pattern: "**/.beads/**",
|
|
92
|
+
test: (p) => hasSegment(p, ".beads"),
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: "obsidian-workspace",
|
|
96
|
+
category: "machine-local",
|
|
97
|
+
pattern: "**/.obsidian/**",
|
|
98
|
+
test: (p) => hasSegment(p, ".obsidian"),
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: "vercel-link",
|
|
102
|
+
category: "machine-local",
|
|
103
|
+
pattern: "**/.vercel/**",
|
|
104
|
+
test: (p) => hasSegment(p, ".vercel"),
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: "cache-dir",
|
|
108
|
+
category: "machine-local",
|
|
109
|
+
pattern: "**/.cache_*",
|
|
110
|
+
test: (p) => basename(p).startsWith(".cache_"),
|
|
111
|
+
},
|
|
112
|
+
// ── update-flow scratch ───────────────────────────────────────────────
|
|
113
|
+
{
|
|
114
|
+
id: "update-output",
|
|
115
|
+
category: "scratch",
|
|
116
|
+
pattern: "**/output/**",
|
|
117
|
+
test: (p) => hasSegment(p, "output"),
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: "legacy-dir",
|
|
121
|
+
category: "scratch",
|
|
122
|
+
pattern: "**/_legacy-*/**",
|
|
123
|
+
test: (p) => {
|
|
124
|
+
// Match any segment that starts with `_legacy-` or `_legacy_` or equals `_legacy`.
|
|
125
|
+
const segs = p.split("/");
|
|
126
|
+
return segs.some((s) => s === "_legacy" || s.startsWith("_legacy-") || s.startsWith("_legacy_"));
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
// ── pre-5.24 conflict mirror directory ────────────────────────────────
|
|
130
|
+
// Sibling to EPHEMERAL_PATH_PATTERN (handles the .conflict-<iso>-<hash>.ext
|
|
131
|
+
// file form). This handles the older directory form some HQ installs
|
|
132
|
+
// accumulated.
|
|
133
|
+
{
|
|
134
|
+
id: "hq-conflicts-dir",
|
|
135
|
+
category: "conflict-mirror",
|
|
136
|
+
pattern: "**/.hq-conflicts/**",
|
|
137
|
+
test: (p) => hasSegment(p, ".hq-conflicts"),
|
|
138
|
+
},
|
|
139
|
+
// ── OS / build cruft ──────────────────────────────────────────────────
|
|
140
|
+
{
|
|
141
|
+
id: "ds-store",
|
|
142
|
+
category: "os-cruft",
|
|
143
|
+
pattern: "**/.DS_Store",
|
|
144
|
+
test: (p) => basename(p) === ".DS_Store",
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
id: "node-modules",
|
|
148
|
+
category: "build-output",
|
|
149
|
+
pattern: "**/node_modules/**",
|
|
150
|
+
test: (p) => hasSegment(p, "node_modules"),
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
id: "dist-dir",
|
|
154
|
+
category: "build-output",
|
|
155
|
+
pattern: "**/dist/**",
|
|
156
|
+
test: (p) => hasSegment(p, "dist"),
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: "next-dir",
|
|
160
|
+
category: "build-output",
|
|
161
|
+
pattern: "**/.next/**",
|
|
162
|
+
test: (p) => hasSegment(p, ".next"),
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: "build-dir",
|
|
166
|
+
category: "build-output",
|
|
167
|
+
pattern: "**/build/**",
|
|
168
|
+
test: (p) => hasSegment(p, "build"),
|
|
169
|
+
},
|
|
170
|
+
];
|
|
171
|
+
/**
|
|
172
|
+
* First-match result for a path. Returns the matching exclusion (so callers
|
|
173
|
+
* can surface category/id in events) or undefined for "not excluded".
|
|
174
|
+
*/
|
|
175
|
+
export function matchPersonalVaultExclusion(relPath, isDir) {
|
|
176
|
+
for (const ex of PERSONAL_VAULT_DEFAULT_EXCLUSIONS) {
|
|
177
|
+
if (ex.test(relPath, isDir))
|
|
178
|
+
return ex;
|
|
179
|
+
}
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Boolean version — true if any exclusion matches.
|
|
184
|
+
*/
|
|
185
|
+
export function isPersonalVaultExcluded(relPath, isDir) {
|
|
186
|
+
return matchPersonalVaultExclusion(relPath, isDir) !== undefined;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Wrap an existing path filter (typically from `createIgnoreFilter`) with the
|
|
190
|
+
* personal-vault default exclusions. The wrapper:
|
|
191
|
+
*
|
|
192
|
+
* 1. Calls the underlying filter first; if it already rejects, defer
|
|
193
|
+
* (counter does not fire — we only want to count things the underlying
|
|
194
|
+
* filter would have allowed but the personal-vault defaults reject).
|
|
195
|
+
* 2. Computes a relative path from `syncRoot` (the personal-vault sync
|
|
196
|
+
* root, which is hq_root in personalMode).
|
|
197
|
+
* 3. Probes `matchPersonalVaultExclusion`; if it matches, returns false
|
|
198
|
+
* and tags the match via `onExcluded` so the runner can emit a single
|
|
199
|
+
* `personal-vault-out-of-policy` event with a count + sample at end of
|
|
200
|
+
* run.
|
|
201
|
+
*
|
|
202
|
+
* The wrapper keeps the `(absolutePath, isDir) => boolean` shape the existing
|
|
203
|
+
* collectFiles / walkDir / computeDeletePlan code already uses, so wiring is
|
|
204
|
+
* a single line change at the share() filter construction site.
|
|
205
|
+
*/
|
|
206
|
+
export function wrapFilterWithPersonalVaultDefaults(underlying, syncRoot, onExcluded) {
|
|
207
|
+
return (absPath, isDir) => {
|
|
208
|
+
if (!underlying(absPath, isDir))
|
|
209
|
+
return false;
|
|
210
|
+
const rel = path.relative(syncRoot, absPath).split(path.sep).join("/");
|
|
211
|
+
if (rel === "" || rel.startsWith(".."))
|
|
212
|
+
return true; // outside scope, defer
|
|
213
|
+
const match = matchPersonalVaultExclusion(rel, isDir);
|
|
214
|
+
if (match) {
|
|
215
|
+
onExcluded(rel, match);
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
return true;
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Test-only export. Mirrors the `_testing` namespace pattern used by
|
|
223
|
+
* `share.ts` for `EPHEMERAL_PATH_PATTERN` — direct access to the list +
|
|
224
|
+
* internal helpers for regression-critical pinning without round-tripping
|
|
225
|
+
* through share().
|
|
226
|
+
*/
|
|
227
|
+
export const _testing = {
|
|
228
|
+
hasSegment,
|
|
229
|
+
basename,
|
|
230
|
+
};
|
|
231
|
+
//# sourceMappingURL=personal-vault-exclusions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"personal-vault-exclusions.js","sourceRoot":"","sources":["../src/personal-vault-exclusions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAqC7B;;GAEG;AACH,SAAS,UAAU,CAAC,OAAe,EAAE,OAAe;IAClD,IAAI,OAAO,KAAK,OAAO;QAAE,OAAO,IAAI,CAAC;IACrC,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACnD,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,QAAQ,CAAC,OAAe;IAC/B,MAAM,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACnC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,K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,CAAC;QACvE,IAAI,GAAG,KAAK,EAAE,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC,CAAC,uBAAuB;QAC5E,MAAM,KAAK,GAAG,2BAA2B,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACtD,IAAI,KAAK,EAAE,CAAC;YACV,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACvB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,UAAU;IACV,QAAQ;CACT,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for `personal-vault-exclusions.ts`. Pin the regex / segment contracts
|
|
3
|
+
* for every entry in PERSONAL_VAULT_DEFAULT_EXCLUSIONS so a future edit that
|
|
4
|
+
* relaxes one (e.g. dropping the `_legacy-` prefix match, or changing the
|
|
5
|
+
* `.cache_*` shape) surfaces here instead of in the field.
|
|
6
|
+
*
|
|
7
|
+
* Two test layers:
|
|
8
|
+
*
|
|
9
|
+
* 1. Per-rule predicate tests. Each exclusion is exercised with at least
|
|
10
|
+
* one match-positive and one match-negative path so the regex shape is
|
|
11
|
+
* pinned. The `byId` event field on the runner uses `ex.id` directly,
|
|
12
|
+
* so the id stability is part of the contract too — tests assert
|
|
13
|
+
* against the literal id string.
|
|
14
|
+
*
|
|
15
|
+
* 2. Filter-wrap integration. Confirms that `wrapFilterWithPersonalVaultDefaults`
|
|
16
|
+
* defers to the underlying filter, computes the relative path correctly,
|
|
17
|
+
* and only fires the `onExcluded` callback when the underlying filter
|
|
18
|
+
* WOULD have allowed the path (so the count tracks only "newly blocked
|
|
19
|
+
* by these defaults", not "blocked by .hqignore too").
|
|
20
|
+
*/
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=personal-vault-exclusions.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"personal-vault-exclusions.test.d.ts","sourceRoot":"","sources":["../src/personal-vault-exclusions.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for `personal-vault-exclusions.ts`. Pin the regex / segment contracts
|
|
3
|
+
* for every entry in PERSONAL_VAULT_DEFAULT_EXCLUSIONS so a future edit that
|
|
4
|
+
* relaxes one (e.g. dropping the `_legacy-` prefix match, or changing the
|
|
5
|
+
* `.cache_*` shape) surfaces here instead of in the field.
|
|
6
|
+
*
|
|
7
|
+
* Two test layers:
|
|
8
|
+
*
|
|
9
|
+
* 1. Per-rule predicate tests. Each exclusion is exercised with at least
|
|
10
|
+
* one match-positive and one match-negative path so the regex shape is
|
|
11
|
+
* pinned. The `byId` event field on the runner uses `ex.id` directly,
|
|
12
|
+
* so the id stability is part of the contract too — tests assert
|
|
13
|
+
* against the literal id string.
|
|
14
|
+
*
|
|
15
|
+
* 2. Filter-wrap integration. Confirms that `wrapFilterWithPersonalVaultDefaults`
|
|
16
|
+
* defers to the underlying filter, computes the relative path correctly,
|
|
17
|
+
* and only fires the `onExcluded` callback when the underlying filter
|
|
18
|
+
* WOULD have allowed the path (so the count tracks only "newly blocked
|
|
19
|
+
* by these defaults", not "blocked by .hqignore too").
|
|
20
|
+
*/
|
|
21
|
+
import { describe, expect, it } from "vitest";
|
|
22
|
+
import * as path from "node:path";
|
|
23
|
+
import { PERSONAL_VAULT_DEFAULT_EXCLUSIONS, isPersonalVaultExcluded, matchPersonalVaultExclusion, wrapFilterWithPersonalVaultDefaults, _testing, } from "./personal-vault-exclusions.js";
|
|
24
|
+
describe("PERSONAL_VAULT_DEFAULT_EXCLUSIONS", () => {
|
|
25
|
+
it("exports a non-empty, frozen-shaped list", () => {
|
|
26
|
+
expect(PERSONAL_VAULT_DEFAULT_EXCLUSIONS.length).toBeGreaterThan(10);
|
|
27
|
+
// Every entry has the four required fields; this pins the public shape
|
|
28
|
+
// so a future addition without `category` or `id` fails fast.
|
|
29
|
+
for (const ex of PERSONAL_VAULT_DEFAULT_EXCLUSIONS) {
|
|
30
|
+
expect(typeof ex.id).toBe("string");
|
|
31
|
+
expect(ex.id.length).toBeGreaterThan(0);
|
|
32
|
+
expect(typeof ex.category).toBe("string");
|
|
33
|
+
expect(typeof ex.test).toBe("function");
|
|
34
|
+
expect(typeof ex.pattern).toBe("string");
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
it("has unique ids (event byId aggregation requires it)", () => {
|
|
38
|
+
const ids = new Set();
|
|
39
|
+
for (const ex of PERSONAL_VAULT_DEFAULT_EXCLUSIONS) {
|
|
40
|
+
expect(ids.has(ex.id)).toBe(false);
|
|
41
|
+
ids.add(ex.id);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
// ── Per-rule predicate matrix ───────────────────────────────────────────────
|
|
46
|
+
//
|
|
47
|
+
// One block per rule. The positives prove "this path SHOULD be excluded"; the
|
|
48
|
+
// negatives prove "this path SHOULD NOT" (guards against over-broad regexes
|
|
49
|
+
// that would block legitimate user content).
|
|
50
|
+
describe("env-file exclusion (secrets)", () => {
|
|
51
|
+
it.each([".env", ".env.local", ".env.production", "core/.env", "personal/.env.local"])("matches %s", (p) => {
|
|
52
|
+
expect(isPersonalVaultExcluded(p)).toBe(true);
|
|
53
|
+
expect(matchPersonalVaultExclusion(p)?.id).toBe("env-file");
|
|
54
|
+
});
|
|
55
|
+
it.each(["envconfig.md", ".env-example.md", "core/policies/env-vars.md"])("does NOT match %s", (p) => {
|
|
56
|
+
// ".env-example.md" is intentionally a negative — the basename starts
|
|
57
|
+
// with ".env-", not ".env." (dot vs hyphen). We want to allow docs
|
|
58
|
+
// that reference env-vars without the regex grabbing them.
|
|
59
|
+
const m = matchPersonalVaultExclusion(p);
|
|
60
|
+
expect(m?.id).not.toBe("env-file");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe("mcp-config exclusion (secrets)", () => {
|
|
64
|
+
it.each([".mcp.json", "personal/.mcp.json", "core/.claude/.mcp.json"])("matches %s", (p) => {
|
|
65
|
+
expect(matchPersonalVaultExclusion(p)?.id).toBe("mcp-config");
|
|
66
|
+
});
|
|
67
|
+
it.each(["mcp.json", "core/policies/mcp.md", ".mcp.example.json"])("does NOT match %s", (p) => {
|
|
68
|
+
expect(matchPersonalVaultExclusion(p)?.id).not.toBe("mcp-config");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe("beads exclusion (machine-local SQLite)", () => {
|
|
72
|
+
it.each([
|
|
73
|
+
".beads/beads.db",
|
|
74
|
+
".beads/beads.db-wal",
|
|
75
|
+
".beads/beads.db-shm",
|
|
76
|
+
".beads/beads.left.jsonl",
|
|
77
|
+
"personal/.beads/issue.json",
|
|
78
|
+
])("matches %s", (p) => {
|
|
79
|
+
expect(matchPersonalVaultExclusion(p)?.id).toBe("beads-db");
|
|
80
|
+
});
|
|
81
|
+
it.each(["beads.md", "core/knowledge/beads-guide.md"])("does NOT match %s", (p) => {
|
|
82
|
+
expect(matchPersonalVaultExclusion(p)?.id).not.toBe("beads-db");
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe("obsidian / vercel / cache exclusions", () => {
|
|
86
|
+
it("matches .obsidian/", () => {
|
|
87
|
+
expect(matchPersonalVaultExclusion(".obsidian/workspace.json")?.id).toBe("obsidian-workspace");
|
|
88
|
+
});
|
|
89
|
+
it("matches .vercel/", () => {
|
|
90
|
+
expect(matchPersonalVaultExclusion(".vercel/project.json")?.id).toBe("vercel-link");
|
|
91
|
+
});
|
|
92
|
+
it("matches .cache_ggshield", () => {
|
|
93
|
+
expect(matchPersonalVaultExclusion(".cache_ggshield")?.id).toBe("cache-dir");
|
|
94
|
+
});
|
|
95
|
+
it("matches .cache_anything", () => {
|
|
96
|
+
expect(matchPersonalVaultExclusion(".cache_foo")?.id).toBe("cache-dir");
|
|
97
|
+
});
|
|
98
|
+
it("does NOT match .cache (no underscore)", () => {
|
|
99
|
+
// `.cache_*` is the segment shape — bare `.cache` should be left for
|
|
100
|
+
// other rules / .hqignore. Pinned so a future widen-of-pattern surfaces here.
|
|
101
|
+
expect(matchPersonalVaultExclusion(".cache")).toBeUndefined();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe("update-output / legacy / hq-conflicts exclusions (scratch)", () => {
|
|
105
|
+
it.each([
|
|
106
|
+
"output/hatch-pet/scaffold.md",
|
|
107
|
+
"personal/data/output/hatch-pet/file.md",
|
|
108
|
+
"core/output/x.md",
|
|
109
|
+
])("matches %s as update-output", (p) => {
|
|
110
|
+
expect(matchPersonalVaultExclusion(p)?.id).toBe("update-output");
|
|
111
|
+
});
|
|
112
|
+
it.each([
|
|
113
|
+
"_legacy-pre14.2/x.md",
|
|
114
|
+
"personal/_legacy-2024/old.md",
|
|
115
|
+
"_legacy_v1/y.md",
|
|
116
|
+
"_legacy/z.md",
|
|
117
|
+
])("matches %s as legacy-dir", (p) => {
|
|
118
|
+
expect(matchPersonalVaultExclusion(p)?.id).toBe("legacy-dir");
|
|
119
|
+
});
|
|
120
|
+
it.each([".hq-conflicts/file.md", "personal/.hq-conflicts/x.md"])("matches %s as hq-conflicts-dir", (p) => {
|
|
121
|
+
expect(matchPersonalVaultExclusion(p)?.id).toBe("hq-conflicts-dir");
|
|
122
|
+
});
|
|
123
|
+
it("does NOT match 'output.md' (basename collision guard)", () => {
|
|
124
|
+
expect(matchPersonalVaultExclusion("core/output.md")).toBeUndefined();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
describe("OS / build cruft exclusions", () => {
|
|
128
|
+
it("matches .DS_Store anywhere", () => {
|
|
129
|
+
expect(matchPersonalVaultExclusion(".DS_Store")?.id).toBe("ds-store");
|
|
130
|
+
expect(matchPersonalVaultExclusion("personal/.DS_Store")?.id).toBe("ds-store");
|
|
131
|
+
});
|
|
132
|
+
it.each([
|
|
133
|
+
["node_modules/x.js", "node-modules"],
|
|
134
|
+
["personal/x/node_modules/y.js", "node-modules"],
|
|
135
|
+
["dist/bundle.js", "dist-dir"],
|
|
136
|
+
[".next/build/file.js", "next-dir"],
|
|
137
|
+
["build/output.js", "build-dir"],
|
|
138
|
+
])("matches %s as %s", (p, expectedId) => {
|
|
139
|
+
expect(matchPersonalVaultExclusion(p)?.id).toBe(expectedId);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
// ── _testing internals ───────────────────────────────────────────────────────
|
|
143
|
+
describe("_testing internals", () => {
|
|
144
|
+
it("hasSegment matches exact / prefix / middle / suffix forms", () => {
|
|
145
|
+
expect(_testing.hasSegment("foo", "foo")).toBe(true);
|
|
146
|
+
expect(_testing.hasSegment("foo/bar", "foo")).toBe(true);
|
|
147
|
+
expect(_testing.hasSegment("a/foo/b", "foo")).toBe(true);
|
|
148
|
+
expect(_testing.hasSegment("a/foo", "foo")).toBe(true);
|
|
149
|
+
expect(_testing.hasSegment("foobar", "foo")).toBe(false);
|
|
150
|
+
expect(_testing.hasSegment("a/foobar", "foo")).toBe(false);
|
|
151
|
+
});
|
|
152
|
+
it("basename returns the trailing segment", () => {
|
|
153
|
+
expect(_testing.basename("a/b/c.md")).toBe("c.md");
|
|
154
|
+
expect(_testing.basename("c.md")).toBe("c.md");
|
|
155
|
+
expect(_testing.basename("")).toBe("");
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
// ── Filter-wrap integration ──────────────────────────────────────────────────
|
|
159
|
+
describe("wrapFilterWithPersonalVaultDefaults", () => {
|
|
160
|
+
// Use a syncRoot path independent of the test runner's cwd so the
|
|
161
|
+
// path.relative() calls inside the wrapper produce predictable results
|
|
162
|
+
// regardless of where the test runs from.
|
|
163
|
+
const syncRoot = "/tmp/hq-root";
|
|
164
|
+
it("defers to the underlying filter when it rejects", () => {
|
|
165
|
+
const calls = [];
|
|
166
|
+
const wrapped = wrapFilterWithPersonalVaultDefaults(() => false, // underlying rejects everything
|
|
167
|
+
syncRoot, (rel, match) => calls.push({ rel, id: match.id }));
|
|
168
|
+
// Even though `.env` matches a default exclusion, the underlying
|
|
169
|
+
// filter already rejected it — onExcluded must NOT fire (we only
|
|
170
|
+
// want to count things that would have made it past the user's
|
|
171
|
+
// .hqignore but are blocked by our defaults).
|
|
172
|
+
expect(wrapped(path.join(syncRoot, ".env"))).toBe(false);
|
|
173
|
+
expect(calls).toEqual([]);
|
|
174
|
+
});
|
|
175
|
+
it("rejects and tags onExcluded when underlying allows + default blocks", () => {
|
|
176
|
+
const calls = [];
|
|
177
|
+
const wrapped = wrapFilterWithPersonalVaultDefaults(() => true, // underlying allows everything
|
|
178
|
+
syncRoot, (rel, match) => calls.push({ rel, id: match.id }));
|
|
179
|
+
expect(wrapped(path.join(syncRoot, ".env"))).toBe(false);
|
|
180
|
+
expect(wrapped(path.join(syncRoot, "personal", ".env.local"))).toBe(false);
|
|
181
|
+
expect(wrapped(path.join(syncRoot, "personal", "agents.md"))).toBe(true);
|
|
182
|
+
expect(calls).toEqual([
|
|
183
|
+
{ rel: ".env", id: "env-file" },
|
|
184
|
+
{ rel: "personal/.env.local", id: "env-file" },
|
|
185
|
+
// "personal/agents.md" was allowed — no onExcluded callback fired.
|
|
186
|
+
]);
|
|
187
|
+
});
|
|
188
|
+
it("does not fire onExcluded for paths outside syncRoot (defensive)", () => {
|
|
189
|
+
const calls = [];
|
|
190
|
+
const wrapped = wrapFilterWithPersonalVaultDefaults(() => true, syncRoot, (rel, match) => calls.push({ rel, id: match.id }));
|
|
191
|
+
// Outside-syncRoot paths come back with a `..` prefix from path.relative;
|
|
192
|
+
// the wrapper defers (returns true) without consulting the exclusion
|
|
193
|
+
// list since "outside scope" is the upstream containment check's job.
|
|
194
|
+
expect(wrapped("/tmp/other/.env")).toBe(true);
|
|
195
|
+
expect(calls).toEqual([]);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
//# sourceMappingURL=personal-vault-exclusions.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"personal-vault-exclusions.test.js","sourceRoot":"","sources":["../src/personal-vault-exclusions.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EACL,iCAAiC,EACjC,uBAAuB,EACvB,2BAA2B,EAC3B,mCAAmC,EACnC,QAAQ,GACT,MAAM,gCAAgC,CAAC;AAExC,QAAQ,CAAC,mCAAmC,EAAE,GAAG,EAAE;IACjD,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,CAAC,iCAAiC,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;QACrE,uEAAuE;QACvE,8DAA8D;QAC9D,KAAK,MAAM,EAAE,IAAI,iCAAiC,EAAE,CAAC;YACnD,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACpC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACxC,MAAM,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC1C,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YACxC,MAAM,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;QAC9B,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