@indigoai-us/hq-cloud 5.24.0 → 5.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/bin/sync-runner.d.ts +151 -17
  2. package/dist/bin/sync-runner.d.ts.map +1 -1
  3. package/dist/bin/sync-runner.js +280 -18
  4. package/dist/bin/sync-runner.js.map +1 -1
  5. package/dist/bin/sync-runner.test.js +429 -15
  6. package/dist/bin/sync-runner.test.js.map +1 -1
  7. package/dist/cli/share.d.ts +9 -0
  8. package/dist/cli/share.d.ts.map +1 -1
  9. package/dist/cli/share.js +54 -1
  10. package/dist/cli/share.js.map +1 -1
  11. package/dist/cli/share.test.js +6 -3
  12. package/dist/cli/share.test.js.map +1 -1
  13. package/dist/cli/sync.d.ts +21 -0
  14. package/dist/cli/sync.d.ts.map +1 -1
  15. package/dist/cli/sync.js.map +1 -1
  16. package/dist/index.d.ts +4 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +6 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/personal-vault-exclusions.d.ts +128 -0
  21. package/dist/personal-vault-exclusions.d.ts.map +1 -0
  22. package/dist/personal-vault-exclusions.js +231 -0
  23. package/dist/personal-vault-exclusions.js.map +1 -0
  24. package/dist/personal-vault-exclusions.test.d.ts +22 -0
  25. package/dist/personal-vault-exclusions.test.d.ts.map +1 -0
  26. package/dist/personal-vault-exclusions.test.js +198 -0
  27. package/dist/personal-vault-exclusions.test.js.map +1 -0
  28. package/dist/sync/index.d.ts +11 -0
  29. package/dist/sync/index.d.ts.map +1 -0
  30. package/dist/sync/index.js +9 -0
  31. package/dist/sync/index.js.map +1 -0
  32. package/dist/sync/push-event.d.ts +110 -0
  33. package/dist/sync/push-event.d.ts.map +1 -0
  34. package/dist/sync/push-event.js +153 -0
  35. package/dist/sync/push-event.js.map +1 -0
  36. package/dist/sync/push-event.test.d.ts +15 -0
  37. package/dist/sync/push-event.test.d.ts.map +1 -0
  38. package/dist/sync/push-event.test.js +188 -0
  39. package/dist/sync/push-event.test.js.map +1 -0
  40. package/dist/sync/push-transport.d.ts +67 -0
  41. package/dist/sync/push-transport.d.ts.map +1 -0
  42. package/dist/sync/push-transport.js +66 -0
  43. package/dist/sync/push-transport.js.map +1 -0
  44. package/dist/watcher.d.ts +160 -0
  45. package/dist/watcher.d.ts.map +1 -1
  46. package/dist/watcher.js +298 -0
  47. package/dist/watcher.js.map +1 -1
  48. package/dist/watcher.test.d.ts +2 -0
  49. package/dist/watcher.test.d.ts.map +1 -0
  50. package/dist/watcher.test.js +334 -0
  51. package/dist/watcher.test.js.map +1 -0
  52. package/package.json +3 -2
  53. package/src/bin/sync-runner.test.ts +557 -15
  54. package/src/bin/sync-runner.ts +404 -27
  55. package/src/cli/share.test.ts +8 -3
  56. package/src/cli/share.ts +66 -1
  57. package/src/cli/sync.ts +22 -0
  58. package/src/index.ts +27 -0
  59. package/src/personal-vault-exclusions.test.ts +256 -0
  60. package/src/personal-vault-exclusions.ts +277 -0
  61. package/src/sync/index.ts +19 -0
  62. package/src/sync/push-event.test.ts +224 -0
  63. package/src/sync/push-event.ts +208 -0
  64. package/src/sync/push-transport.ts +84 -0
  65. package/src/watcher.test.ts +388 -0
  66. package/src/watcher.ts +386 -0
package/src/cli/sync.ts CHANGED
@@ -120,6 +120,28 @@ export type SyncProgressEvent =
120
120
  journalEtag: string;
121
121
  remoteEtag: string;
122
122
  reason: "stale-etag" | "legacy-no-etag";
123
+ }
124
+ | {
125
+ /**
126
+ * Emitted at most ONCE per `share()` call (push leg of a sync run) when
127
+ * `personalMode === true` and the personal-vault default-exclusion list
128
+ * blocked one or more files that would otherwise have uploaded. Gives
129
+ * the UI a single summary signal — "N files quietly excluded by default
130
+ * policy" — without firing one event per excluded file (which would
131
+ * dominate the event stream on first-sync of a dirty tree).
132
+ *
133
+ * `count` is the total number of paths the exclusion filter rejected
134
+ * (deduplicated across the walk). `samplePaths` carries up to 10
135
+ * forward-slash-separated relative paths for diagnostic display. `byId`
136
+ * is a per-exclusion-rule breakdown so the UI can render which class
137
+ * of exclusion did the work (secret / machine-local / scratch / …).
138
+ *
139
+ * Not emitted when `count === 0` — silent on a clean tree.
140
+ */
141
+ type: "personal-vault-out-of-policy";
142
+ count: number;
143
+ samplePaths: string[];
144
+ byId: Record<string, number>;
123
145
  };
124
146
 
125
147
  export interface SyncOptions {
package/src/index.ts CHANGED
@@ -108,6 +108,16 @@ export {
108
108
  computePersonalVaultPaths,
109
109
  } from "./personal-vault.js";
110
110
 
111
+ // Personal-vault default-exclusions (5.25+) — second-tier deep-walk filter
112
+ // for secrets, machine-local state, scratch dirs, OS/build cruft.
113
+ export {
114
+ PERSONAL_VAULT_DEFAULT_EXCLUSIONS,
115
+ isPersonalVaultExcluded,
116
+ matchPersonalVaultExclusion,
117
+ wrapFilterWithPersonalVaultDefaults,
118
+ } from "./personal-vault-exclusions.js";
119
+ export type { PersonalVaultExclusion } from "./personal-vault-exclusions.js";
120
+
111
121
  // VaultClient SDK (VLT-7)
112
122
  export { VaultClient, pickCanonicalPersonEntity } from "./vault-client.js";
113
123
  export {
@@ -271,3 +281,20 @@ export {
271
281
  _setSignalsS3Factory,
272
282
  _resetSignalsS3Factory,
273
283
  } from "./signals/internals.js";
284
+
285
+ // Event-driven sync — PushEvent wire contract + PushTransport shipping seam
286
+ // (ported from hq-pro PR #112 per project event-driven-sync-menubar US-007).
287
+ export {
288
+ CONTENT_HASH_PATTERN,
289
+ ISO8601_DATETIME_PATTERN,
290
+ PushEventSchema,
291
+ PushEventDecodeError,
292
+ encodePushEvent,
293
+ decodePushEvent,
294
+ NoopPushTransport,
295
+ } from "./sync/index.js";
296
+ export type {
297
+ PushEvent,
298
+ PushEventDecodeIssue,
299
+ PushTransport,
300
+ } from "./sync/index.js";
@@ -0,0 +1,256 @@
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
+
22
+ import { describe, expect, it } from "vitest";
23
+ import * as path from "node:path";
24
+ import {
25
+ PERSONAL_VAULT_DEFAULT_EXCLUSIONS,
26
+ isPersonalVaultExcluded,
27
+ matchPersonalVaultExclusion,
28
+ wrapFilterWithPersonalVaultDefaults,
29
+ _testing,
30
+ } from "./personal-vault-exclusions.js";
31
+
32
+ describe("PERSONAL_VAULT_DEFAULT_EXCLUSIONS", () => {
33
+ it("exports a non-empty, frozen-shaped list", () => {
34
+ expect(PERSONAL_VAULT_DEFAULT_EXCLUSIONS.length).toBeGreaterThan(10);
35
+ // Every entry has the four required fields; this pins the public shape
36
+ // so a future addition without `category` or `id` fails fast.
37
+ for (const ex of PERSONAL_VAULT_DEFAULT_EXCLUSIONS) {
38
+ expect(typeof ex.id).toBe("string");
39
+ expect(ex.id.length).toBeGreaterThan(0);
40
+ expect(typeof ex.category).toBe("string");
41
+ expect(typeof ex.test).toBe("function");
42
+ expect(typeof ex.pattern).toBe("string");
43
+ }
44
+ });
45
+
46
+ it("has unique ids (event byId aggregation requires it)", () => {
47
+ const ids = new Set<string>();
48
+ for (const ex of PERSONAL_VAULT_DEFAULT_EXCLUSIONS) {
49
+ expect(ids.has(ex.id)).toBe(false);
50
+ ids.add(ex.id);
51
+ }
52
+ });
53
+ });
54
+
55
+ // ── Per-rule predicate matrix ───────────────────────────────────────────────
56
+ //
57
+ // One block per rule. The positives prove "this path SHOULD be excluded"; the
58
+ // negatives prove "this path SHOULD NOT" (guards against over-broad regexes
59
+ // that would block legitimate user content).
60
+
61
+ describe("env-file exclusion (secrets)", () => {
62
+ it.each([".env", ".env.local", ".env.production", "core/.env", "personal/.env.local"])(
63
+ "matches %s",
64
+ (p) => {
65
+ expect(isPersonalVaultExcluded(p)).toBe(true);
66
+ expect(matchPersonalVaultExclusion(p)?.id).toBe("env-file");
67
+ },
68
+ );
69
+
70
+ it.each(["envconfig.md", ".env-example.md", "core/policies/env-vars.md"])(
71
+ "does NOT match %s",
72
+ (p) => {
73
+ // ".env-example.md" is intentionally a negative — the basename starts
74
+ // with ".env-", not ".env." (dot vs hyphen). We want to allow docs
75
+ // that reference env-vars without the regex grabbing them.
76
+ const m = matchPersonalVaultExclusion(p);
77
+ expect(m?.id).not.toBe("env-file");
78
+ },
79
+ );
80
+ });
81
+
82
+ describe("mcp-config exclusion (secrets)", () => {
83
+ it.each([".mcp.json", "personal/.mcp.json", "core/.claude/.mcp.json"])(
84
+ "matches %s",
85
+ (p) => {
86
+ expect(matchPersonalVaultExclusion(p)?.id).toBe("mcp-config");
87
+ },
88
+ );
89
+
90
+ it.each(["mcp.json", "core/policies/mcp.md", ".mcp.example.json"])(
91
+ "does NOT match %s",
92
+ (p) => {
93
+ expect(matchPersonalVaultExclusion(p)?.id).not.toBe("mcp-config");
94
+ },
95
+ );
96
+ });
97
+
98
+ describe("beads exclusion (machine-local SQLite)", () => {
99
+ it.each([
100
+ ".beads/beads.db",
101
+ ".beads/beads.db-wal",
102
+ ".beads/beads.db-shm",
103
+ ".beads/beads.left.jsonl",
104
+ "personal/.beads/issue.json",
105
+ ])("matches %s", (p) => {
106
+ expect(matchPersonalVaultExclusion(p)?.id).toBe("beads-db");
107
+ });
108
+
109
+ it.each(["beads.md", "core/knowledge/beads-guide.md"])("does NOT match %s", (p) => {
110
+ expect(matchPersonalVaultExclusion(p)?.id).not.toBe("beads-db");
111
+ });
112
+ });
113
+
114
+ describe("obsidian / vercel / cache exclusions", () => {
115
+ it("matches .obsidian/", () => {
116
+ expect(matchPersonalVaultExclusion(".obsidian/workspace.json")?.id).toBe("obsidian-workspace");
117
+ });
118
+ it("matches .vercel/", () => {
119
+ expect(matchPersonalVaultExclusion(".vercel/project.json")?.id).toBe("vercel-link");
120
+ });
121
+ it("matches .cache_ggshield", () => {
122
+ expect(matchPersonalVaultExclusion(".cache_ggshield")?.id).toBe("cache-dir");
123
+ });
124
+ it("matches .cache_anything", () => {
125
+ expect(matchPersonalVaultExclusion(".cache_foo")?.id).toBe("cache-dir");
126
+ });
127
+ it("does NOT match .cache (no underscore)", () => {
128
+ // `.cache_*` is the segment shape — bare `.cache` should be left for
129
+ // other rules / .hqignore. Pinned so a future widen-of-pattern surfaces here.
130
+ expect(matchPersonalVaultExclusion(".cache")).toBeUndefined();
131
+ });
132
+ });
133
+
134
+ describe("update-output / legacy / hq-conflicts exclusions (scratch)", () => {
135
+ it.each([
136
+ "output/hatch-pet/scaffold.md",
137
+ "personal/data/output/hatch-pet/file.md",
138
+ "core/output/x.md",
139
+ ])("matches %s as update-output", (p) => {
140
+ expect(matchPersonalVaultExclusion(p)?.id).toBe("update-output");
141
+ });
142
+
143
+ it.each([
144
+ "_legacy-pre14.2/x.md",
145
+ "personal/_legacy-2024/old.md",
146
+ "_legacy_v1/y.md",
147
+ "_legacy/z.md",
148
+ ])("matches %s as legacy-dir", (p) => {
149
+ expect(matchPersonalVaultExclusion(p)?.id).toBe("legacy-dir");
150
+ });
151
+
152
+ it.each([".hq-conflicts/file.md", "personal/.hq-conflicts/x.md"])(
153
+ "matches %s as hq-conflicts-dir",
154
+ (p) => {
155
+ expect(matchPersonalVaultExclusion(p)?.id).toBe("hq-conflicts-dir");
156
+ },
157
+ );
158
+
159
+ it("does NOT match 'output.md' (basename collision guard)", () => {
160
+ expect(matchPersonalVaultExclusion("core/output.md")).toBeUndefined();
161
+ });
162
+ });
163
+
164
+ describe("OS / build cruft exclusions", () => {
165
+ it("matches .DS_Store anywhere", () => {
166
+ expect(matchPersonalVaultExclusion(".DS_Store")?.id).toBe("ds-store");
167
+ expect(matchPersonalVaultExclusion("personal/.DS_Store")?.id).toBe("ds-store");
168
+ });
169
+
170
+ it.each([
171
+ ["node_modules/x.js", "node-modules"],
172
+ ["personal/x/node_modules/y.js", "node-modules"],
173
+ ["dist/bundle.js", "dist-dir"],
174
+ [".next/build/file.js", "next-dir"],
175
+ ["build/output.js", "build-dir"],
176
+ ])("matches %s as %s", (p, expectedId) => {
177
+ expect(matchPersonalVaultExclusion(p)?.id).toBe(expectedId);
178
+ });
179
+ });
180
+
181
+ // ── _testing internals ───────────────────────────────────────────────────────
182
+
183
+ describe("_testing internals", () => {
184
+ it("hasSegment matches exact / prefix / middle / suffix forms", () => {
185
+ expect(_testing.hasSegment("foo", "foo")).toBe(true);
186
+ expect(_testing.hasSegment("foo/bar", "foo")).toBe(true);
187
+ expect(_testing.hasSegment("a/foo/b", "foo")).toBe(true);
188
+ expect(_testing.hasSegment("a/foo", "foo")).toBe(true);
189
+ expect(_testing.hasSegment("foobar", "foo")).toBe(false);
190
+ expect(_testing.hasSegment("a/foobar", "foo")).toBe(false);
191
+ });
192
+
193
+ it("basename returns the trailing segment", () => {
194
+ expect(_testing.basename("a/b/c.md")).toBe("c.md");
195
+ expect(_testing.basename("c.md")).toBe("c.md");
196
+ expect(_testing.basename("")).toBe("");
197
+ });
198
+ });
199
+
200
+ // ── Filter-wrap integration ──────────────────────────────────────────────────
201
+
202
+ describe("wrapFilterWithPersonalVaultDefaults", () => {
203
+ // Use a syncRoot path independent of the test runner's cwd so the
204
+ // path.relative() calls inside the wrapper produce predictable results
205
+ // regardless of where the test runs from.
206
+ const syncRoot = "/tmp/hq-root";
207
+
208
+ it("defers to the underlying filter when it rejects", () => {
209
+ const calls: Array<{ rel: string; id: string }> = [];
210
+ const wrapped = wrapFilterWithPersonalVaultDefaults(
211
+ () => false, // underlying rejects everything
212
+ syncRoot,
213
+ (rel, match) => calls.push({ rel, id: match.id }),
214
+ );
215
+
216
+ // Even though `.env` matches a default exclusion, the underlying
217
+ // filter already rejected it — onExcluded must NOT fire (we only
218
+ // want to count things that would have made it past the user's
219
+ // .hqignore but are blocked by our defaults).
220
+ expect(wrapped(path.join(syncRoot, ".env"))).toBe(false);
221
+ expect(calls).toEqual([]);
222
+ });
223
+
224
+ it("rejects and tags onExcluded when underlying allows + default blocks", () => {
225
+ const calls: Array<{ rel: string; id: string }> = [];
226
+ const wrapped = wrapFilterWithPersonalVaultDefaults(
227
+ () => true, // underlying allows everything
228
+ syncRoot,
229
+ (rel, match) => calls.push({ rel, id: match.id }),
230
+ );
231
+
232
+ expect(wrapped(path.join(syncRoot, ".env"))).toBe(false);
233
+ expect(wrapped(path.join(syncRoot, "personal", ".env.local"))).toBe(false);
234
+ expect(wrapped(path.join(syncRoot, "personal", "agents.md"))).toBe(true);
235
+ expect(calls).toEqual([
236
+ { rel: ".env", id: "env-file" },
237
+ { rel: "personal/.env.local", id: "env-file" },
238
+ // "personal/agents.md" was allowed — no onExcluded callback fired.
239
+ ]);
240
+ });
241
+
242
+ it("does not fire onExcluded for paths outside syncRoot (defensive)", () => {
243
+ const calls: Array<{ rel: string; id: string }> = [];
244
+ const wrapped = wrapFilterWithPersonalVaultDefaults(
245
+ () => true,
246
+ syncRoot,
247
+ (rel, match) => calls.push({ rel, id: match.id }),
248
+ );
249
+
250
+ // Outside-syncRoot paths come back with a `..` prefix from path.relative;
251
+ // the wrapper defers (returns true) without consulting the exclusion
252
+ // list since "outside scope" is the upstream containment check's job.
253
+ expect(wrapped("/tmp/other/.env")).toBe(true);
254
+ expect(calls).toEqual([]);
255
+ });
256
+ });
@@ -0,0 +1,277 @@
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
+ import * as path from "path";
57
+
58
+ /**
59
+ * Each entry is matched against the relative path from the personal-vault
60
+ * sync root (which IS hq_root in personalMode), using forward-slash
61
+ * separators. Patterns:
62
+ *
63
+ * - `prefix:foo/` — match if the path starts with `foo/` or equals `foo`
64
+ * (handles both the dir itself and any descendant)
65
+ * - `basename:.env` — match if any path segment equals `.env`
66
+ * - `basename:.env-prefix:.env.` — match if the basename starts with `.env.`
67
+ * - `segment:node_modules` — match if any path segment equals literally
68
+ *
69
+ * The literal-segment form catches nested cases (e.g., `repos/foo/node_modules/`
70
+ * is already excluded by top-level repos/ skip, but `personal/x/node_modules/`
71
+ * would slip through without segment matching).
72
+ */
73
+ export interface PersonalVaultExclusion {
74
+ /** Internal id for telemetry / explainability in events. */
75
+ id: string;
76
+ /** Human-readable category for the warning event. */
77
+ category:
78
+ | "secret"
79
+ | "machine-local"
80
+ | "scratch"
81
+ | "conflict-mirror"
82
+ | "os-cruft"
83
+ | "build-output";
84
+ /**
85
+ * Predicate. Pure: relative path (forward-slash separated, no leading slash)
86
+ * + optional isDir hint. Returns true to EXCLUDE.
87
+ */
88
+ test: (relPath: string, isDir?: boolean) => boolean;
89
+ /** Doc-only — shown alongside `id` in the warning event sample. */
90
+ pattern: string;
91
+ }
92
+
93
+ /**
94
+ * Cheap segment-equality check. Avoids allocating a regex per call.
95
+ */
96
+ function hasSegment(relPath: string, segment: string): boolean {
97
+ if (relPath === segment) return true;
98
+ if (relPath.startsWith(`${segment}/`)) return true;
99
+ return relPath.includes(`/${segment}/`) || relPath.endsWith(`/${segment}`);
100
+ }
101
+
102
+ function basename(relPath: string): string {
103
+ const i = relPath.lastIndexOf("/");
104
+ return i === -1 ? relPath : relPath.slice(i + 1);
105
+ }
106
+
107
+ export const PERSONAL_VAULT_DEFAULT_EXCLUSIONS: readonly PersonalVaultExclusion[] = [
108
+ // ── secrets ───────────────────────────────────────────────────────────
109
+ {
110
+ id: "env-file",
111
+ category: "secret",
112
+ pattern: "**/.env, **/.env.*",
113
+ test: (p) => {
114
+ const b = basename(p);
115
+ return b === ".env" || b.startsWith(".env.");
116
+ },
117
+ },
118
+ {
119
+ id: "mcp-config",
120
+ category: "secret",
121
+ pattern: "**/.mcp.json",
122
+ test: (p) => basename(p) === ".mcp.json",
123
+ },
124
+ // ── machine-local tooling state ───────────────────────────────────────
125
+ {
126
+ id: "beads-db",
127
+ category: "machine-local",
128
+ pattern: "**/.beads/**",
129
+ test: (p) => hasSegment(p, ".beads"),
130
+ },
131
+ {
132
+ id: "obsidian-workspace",
133
+ category: "machine-local",
134
+ pattern: "**/.obsidian/**",
135
+ test: (p) => hasSegment(p, ".obsidian"),
136
+ },
137
+ {
138
+ id: "vercel-link",
139
+ category: "machine-local",
140
+ pattern: "**/.vercel/**",
141
+ test: (p) => hasSegment(p, ".vercel"),
142
+ },
143
+ {
144
+ id: "cache-dir",
145
+ category: "machine-local",
146
+ pattern: "**/.cache_*",
147
+ test: (p) => basename(p).startsWith(".cache_"),
148
+ },
149
+ // ── update-flow scratch ───────────────────────────────────────────────
150
+ {
151
+ id: "update-output",
152
+ category: "scratch",
153
+ pattern: "**/output/**",
154
+ test: (p) => hasSegment(p, "output"),
155
+ },
156
+ {
157
+ id: "legacy-dir",
158
+ category: "scratch",
159
+ pattern: "**/_legacy-*/**",
160
+ test: (p) => {
161
+ // Match any segment that starts with `_legacy-` or `_legacy_` or equals `_legacy`.
162
+ const segs = p.split("/");
163
+ return segs.some(
164
+ (s) => s === "_legacy" || s.startsWith("_legacy-") || s.startsWith("_legacy_"),
165
+ );
166
+ },
167
+ },
168
+ // ── pre-5.24 conflict mirror directory ────────────────────────────────
169
+ // Sibling to EPHEMERAL_PATH_PATTERN (handles the .conflict-<iso>-<hash>.ext
170
+ // file form). This handles the older directory form some HQ installs
171
+ // accumulated.
172
+ {
173
+ id: "hq-conflicts-dir",
174
+ category: "conflict-mirror",
175
+ pattern: "**/.hq-conflicts/**",
176
+ test: (p) => hasSegment(p, ".hq-conflicts"),
177
+ },
178
+ // ── OS / build cruft ──────────────────────────────────────────────────
179
+ {
180
+ id: "ds-store",
181
+ category: "os-cruft",
182
+ pattern: "**/.DS_Store",
183
+ test: (p) => basename(p) === ".DS_Store",
184
+ },
185
+ {
186
+ id: "node-modules",
187
+ category: "build-output",
188
+ pattern: "**/node_modules/**",
189
+ test: (p) => hasSegment(p, "node_modules"),
190
+ },
191
+ {
192
+ id: "dist-dir",
193
+ category: "build-output",
194
+ pattern: "**/dist/**",
195
+ test: (p) => hasSegment(p, "dist"),
196
+ },
197
+ {
198
+ id: "next-dir",
199
+ category: "build-output",
200
+ pattern: "**/.next/**",
201
+ test: (p) => hasSegment(p, ".next"),
202
+ },
203
+ {
204
+ id: "build-dir",
205
+ category: "build-output",
206
+ pattern: "**/build/**",
207
+ test: (p) => hasSegment(p, "build"),
208
+ },
209
+ ];
210
+
211
+ /**
212
+ * First-match result for a path. Returns the matching exclusion (so callers
213
+ * can surface category/id in events) or undefined for "not excluded".
214
+ */
215
+ export function matchPersonalVaultExclusion(
216
+ relPath: string,
217
+ isDir?: boolean,
218
+ ): PersonalVaultExclusion | undefined {
219
+ for (const ex of PERSONAL_VAULT_DEFAULT_EXCLUSIONS) {
220
+ if (ex.test(relPath, isDir)) return ex;
221
+ }
222
+ return undefined;
223
+ }
224
+
225
+ /**
226
+ * Boolean version — true if any exclusion matches.
227
+ */
228
+ export function isPersonalVaultExcluded(relPath: string, isDir?: boolean): boolean {
229
+ return matchPersonalVaultExclusion(relPath, isDir) !== undefined;
230
+ }
231
+
232
+ /**
233
+ * Wrap an existing path filter (typically from `createIgnoreFilter`) with the
234
+ * personal-vault default exclusions. The wrapper:
235
+ *
236
+ * 1. Calls the underlying filter first; if it already rejects, defer
237
+ * (counter does not fire — we only want to count things the underlying
238
+ * filter would have allowed but the personal-vault defaults reject).
239
+ * 2. Computes a relative path from `syncRoot` (the personal-vault sync
240
+ * root, which is hq_root in personalMode).
241
+ * 3. Probes `matchPersonalVaultExclusion`; if it matches, returns false
242
+ * and tags the match via `onExcluded` so the runner can emit a single
243
+ * `personal-vault-out-of-policy` event with a count + sample at end of
244
+ * run.
245
+ *
246
+ * The wrapper keeps the `(absolutePath, isDir) => boolean` shape the existing
247
+ * collectFiles / walkDir / computeDeletePlan code already uses, so wiring is
248
+ * a single line change at the share() filter construction site.
249
+ */
250
+ export function wrapFilterWithPersonalVaultDefaults(
251
+ underlying: (absPath: string, isDir?: boolean) => boolean,
252
+ syncRoot: string,
253
+ onExcluded: (relPath: string, match: PersonalVaultExclusion) => void,
254
+ ): (absPath: string, isDir?: boolean) => boolean {
255
+ return (absPath: string, isDir?: boolean) => {
256
+ if (!underlying(absPath, isDir)) return false;
257
+ const rel = path.relative(syncRoot, absPath).split(path.sep).join("/");
258
+ if (rel === "" || rel.startsWith("..")) return true; // outside scope, defer
259
+ const match = matchPersonalVaultExclusion(rel, isDir);
260
+ if (match) {
261
+ onExcluded(rel, match);
262
+ return false;
263
+ }
264
+ return true;
265
+ };
266
+ }
267
+
268
+ /**
269
+ * Test-only export. Mirrors the `_testing` namespace pattern used by
270
+ * `share.ts` for `EPHEMERAL_PATH_PATTERN` — direct access to the list +
271
+ * internal helpers for regression-critical pinning without round-tripping
272
+ * through share().
273
+ */
274
+ export const _testing = {
275
+ hasSegment,
276
+ basename,
277
+ };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @indigoai-us/hq-cloud — event-driven sync (`src/sync`) barrel.
3
+ *
4
+ * Surfaces the PushEvent wire contract + the PushTransport shipping seam
5
+ * ported from hq-pro PR #112 (project event-driven-sync-menubar US-007).
6
+ */
7
+
8
+ export {
9
+ CONTENT_HASH_PATTERN,
10
+ ISO8601_DATETIME_PATTERN,
11
+ PushEventSchema,
12
+ PushEventDecodeError,
13
+ encodePushEvent,
14
+ decodePushEvent,
15
+ } from "./push-event.js";
16
+ export type { PushEvent, PushEventDecodeIssue } from "./push-event.js";
17
+
18
+ export { NoopPushTransport } from "./push-transport.js";
19
+ export type { PushTransport } from "./push-transport.js";