@indigoai-us/hq-cloud 6.16.6 → 6.16.8

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 (49) hide show
  1. package/dist/bin/sync-runner-post-sync-flags.d.ts +27 -0
  2. package/dist/bin/sync-runner-post-sync-flags.d.ts.map +1 -0
  3. package/dist/bin/sync-runner-post-sync-flags.js +58 -0
  4. package/dist/bin/sync-runner-post-sync-flags.js.map +1 -0
  5. package/dist/bin/sync-runner-post-sync-flags.test.d.ts +2 -0
  6. package/dist/bin/sync-runner-post-sync-flags.test.d.ts.map +1 -0
  7. package/dist/bin/sync-runner-post-sync-flags.test.js +104 -0
  8. package/dist/bin/sync-runner-post-sync-flags.test.js.map +1 -0
  9. package/dist/bin/sync-runner.d.ts +6 -0
  10. package/dist/bin/sync-runner.d.ts.map +1 -1
  11. package/dist/bin/sync-runner.js +27 -5
  12. package/dist/bin/sync-runner.js.map +1 -1
  13. package/dist/bin/sync-runner.test.js +257 -0
  14. package/dist/bin/sync-runner.test.js.map +1 -1
  15. package/dist/context.d.ts.map +1 -1
  16. package/dist/context.js +7 -1
  17. package/dist/context.js.map +1 -1
  18. package/dist/context.test.js +24 -0
  19. package/dist/context.test.js.map +1 -1
  20. package/dist/credential-scope-error.d.ts +21 -0
  21. package/dist/credential-scope-error.d.ts.map +1 -0
  22. package/dist/credential-scope-error.js +57 -0
  23. package/dist/credential-scope-error.js.map +1 -0
  24. package/dist/index.d.ts +3 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +2 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/sync/index.d.ts +2 -2
  29. package/dist/sync/index.d.ts.map +1 -1
  30. package/dist/sync/index.js +1 -1
  31. package/dist/sync/index.js.map +1 -1
  32. package/dist/sync/push-event.d.ts +16 -0
  33. package/dist/sync/push-event.d.ts.map +1 -1
  34. package/dist/sync/push-event.js +46 -1
  35. package/dist/sync/push-event.js.map +1 -1
  36. package/dist/sync/push-event.test.js +38 -1
  37. package/dist/sync/push-event.test.js.map +1 -1
  38. package/dist/vault-client.d.ts +3 -2
  39. package/dist/vault-client.d.ts.map +1 -1
  40. package/dist/vault-client.js +17 -2
  41. package/dist/vault-client.js.map +1 -1
  42. package/dist/vault-client.test.js +49 -0
  43. package/dist/vault-client.test.js.map +1 -1
  44. package/dist/watcher.d.ts.map +1 -1
  45. package/dist/watcher.js +13 -3
  46. package/dist/watcher.js.map +1 -1
  47. package/dist/watcher.test.js +35 -15
  48. package/dist/watcher.test.js.map +1 -1
  49. package/package.json +2 -1
@@ -14,6 +14,7 @@ import { runRunner, runRunnerWithLoop, resolveDeletePolicy, resolveSkipPersonal,
14
14
  import { AUTH_WAIT_INITIAL_RECHECK_MS, AUTH_WAIT_RESUME_MESSAGE, AUTH_WAIT_START_MESSAGE, AUTH_WAIT_STEADY_RECHECK_MS, } from "./sync-runner-auth-wait.js";
15
15
  import { PresignObjectIO, S3SdkObjectIO } from "../object-io.js";
16
16
  import { setBandwidthGovernorForTesting } from "../bandwidth.js";
17
+ import { POST_SYNC_FLAG_KEYS, } from "./sync-runner-post-sync-flags.js";
17
18
  import { FakeClock, TreeWatcher, } from "../watcher.js";
18
19
  import { adaptivePollMs, advanceMonotonicDeadline, DEFAULT_EVENT_BATCH_LIMIT, DEFAULT_FAST_LANE_MAX_BYTES, DEFAULT_FAST_LANE_MAX_FILE_BYTES, DEFAULT_FAST_LANE_MAX_FILES, DEFAULT_FULL_RECONCILE_MS, EVENT_BATCH_LIMIT_ENV, FAST_LANE_MAX_BYTES_ENV, FAST_LANE_MAX_FILES_ENV, FULL_RECONCILE_MS_ENV, isFastLocalBatch, isFastReceiverBatch, partitionLocalBatch, journalEntriesForWatcherDelete, resolveEventBatchLimit, resolveFullReconcileMs, resolveWatchPollMs, normalizeCoordinatorPaths, shouldQuarantineWatcherDeleteIntents, shouldUseAreaStorage, WATCHER_REDISCOVERY_RETRY_MS, WATCHER_REDISCOVERY_RETRY_MAX_MS, } from "./sync-runner-watch-loop.js";
19
20
  import { AreaLedgerMigration, openJournalStateStoreForMigration, PERSONAL_VAULT_JOURNAL_SLUG, readJournal, writeJournal, } from "../journal.js";
@@ -198,6 +199,21 @@ function makeDeps(overrides = {}) {
198
199
  corruptionQuarantineFailed: false,
199
200
  indexDir: null,
200
201
  })),
202
+ postSyncFlags: {
203
+ // Unit tests for the runner keep their existing direct-env contract and
204
+ // never start a real registry fetch. The evaluator itself is covered in
205
+ // sync-runner-post-sync-flags.test.ts with fake registry responses.
206
+ isEnabled: vi.fn((key) => {
207
+ const envVar = key === POST_SYNC_FLAG_KEYS.qmdReindex
208
+ ? "HQ_QMD_REINDEX_ON_SYNC"
209
+ : key === POST_SYNC_FLAG_KEYS.conflictPrune
210
+ ? "HQ_CONFLICT_PRUNE_ON_SYNC"
211
+ : "HQ_AGENT_CODEX_MATERIALIZE";
212
+ return process.env[envVar] !== "0";
213
+ }),
214
+ ready: () => Promise.resolve(),
215
+ refresh: () => Promise.resolve(),
216
+ },
201
217
  reconcileManifest: vi
202
218
  .fn()
203
219
  .mockResolvedValue({ written: false, added: [], updated: [], skipped: [] }),
@@ -2663,6 +2679,247 @@ describe("all-complete aggregate", () => {
2663
2679
  forceCollectionRefresh: true,
2664
2680
  }));
2665
2681
  });
2682
+ it('keeps qmd reindex enabled when HQ_QMD_REINDEX_ON_SYNC is "false" (only exact "0" opts out)', async () => {
2683
+ const previous = process.env.HQ_QMD_REINDEX_ON_SYNC;
2684
+ process.env.HQ_QMD_REINDEX_ON_SYNC = "false";
2685
+ const qmdReindex = vi.fn(() => ({
2686
+ qmdAvailable: true,
2687
+ collectionsAdded: [],
2688
+ pathDriftDetected: [],
2689
+ collectionsRepaired: [],
2690
+ updated: true,
2691
+ embedded: false,
2692
+ pendingDirty: false,
2693
+ lockBusy: false,
2694
+ timedOut: false,
2695
+ corruptionQuarantined: false,
2696
+ corruptionQuarantineFailed: false,
2697
+ indexDir: null,
2698
+ }));
2699
+ try {
2700
+ const deps = makeDeps({
2701
+ createVaultClient: () => makeVaultStub({
2702
+ memberships: [{ companyUid: "cmp_a" }],
2703
+ entityGet: (uid) => Promise.resolve({ uid, slug: "acme" }),
2704
+ }),
2705
+ sync: vi.fn().mockResolvedValue(defaultSyncResult({ changedPaths: ["knowledge/note.md"] })),
2706
+ qmdReindex,
2707
+ });
2708
+ expect(await runRunner(["--companies", "--hq-root", "/tmp/fake-hq"], deps)).toBe(0);
2709
+ expect(qmdReindex).toHaveBeenCalledTimes(1);
2710
+ }
2711
+ finally {
2712
+ if (previous === undefined)
2713
+ delete process.env.HQ_QMD_REINDEX_ON_SYNC;
2714
+ else
2715
+ process.env.HQ_QMD_REINDEX_ON_SYNC = previous;
2716
+ }
2717
+ });
2718
+ it("prunes the conflict ledger by default and preserves it only for exact HQ_CONFLICT_PRUNE_ON_SYNC=0", async () => {
2719
+ const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-conflict-prune-gate-"));
2720
+ const indexPath = path.join(hqRoot, ".hq-conflicts", "index.json");
2721
+ const writeOrphan = () => {
2722
+ fs.mkdirSync(path.dirname(indexPath), { recursive: true });
2723
+ fs.writeFileSync(indexPath, JSON.stringify({
2724
+ version: 1,
2725
+ conflicts: [{
2726
+ id: "orphan",
2727
+ originalPath: "notes.md",
2728
+ conflictPath: "notes.conflict-2026-01-01T00-00-00Z-test.md",
2729
+ detectedAt: "2026-01-01T00:00:00.000Z",
2730
+ side: "pull",
2731
+ machineId: "test",
2732
+ localHash: "sha256:local",
2733
+ remoteHash: "sha256:remote",
2734
+ }],
2735
+ }));
2736
+ };
2737
+ const run = () => runRunner(["--companies", "--hq-root", hqRoot], makeDeps({
2738
+ createVaultClient: () => makeVaultStub({
2739
+ memberships: [{ companyUid: "cmp_a" }],
2740
+ entityGet: (uid) => Promise.resolve({ uid, slug: "acme" }),
2741
+ }),
2742
+ }));
2743
+ const previous = process.env.HQ_CONFLICT_PRUNE_ON_SYNC;
2744
+ try {
2745
+ delete process.env.HQ_CONFLICT_PRUNE_ON_SYNC;
2746
+ writeOrphan();
2747
+ expect(await run()).toBe(0);
2748
+ expect(JSON.parse(fs.readFileSync(indexPath, "utf8")).conflicts).toEqual([]);
2749
+ process.env.HQ_CONFLICT_PRUNE_ON_SYNC = "0";
2750
+ writeOrphan();
2751
+ expect(await run()).toBe(0);
2752
+ expect(JSON.parse(fs.readFileSync(indexPath, "utf8")).conflicts).toHaveLength(1);
2753
+ }
2754
+ finally {
2755
+ if (previous === undefined)
2756
+ delete process.env.HQ_CONFLICT_PRUNE_ON_SYNC;
2757
+ else
2758
+ process.env.HQ_CONFLICT_PRUNE_ON_SYNC = previous;
2759
+ fs.rmSync(hqRoot, { recursive: true, force: true });
2760
+ }
2761
+ });
2762
+ it("materializes Codex instructions for an agent by default, never for a person, and honors exact HQ_AGENT_CODEX_MATERIALIZE=0", async () => {
2763
+ const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-agent-codex-gate-"));
2764
+ const codexHome = fs.mkdtempSync(path.join(os.tmpdir(), "hq-agent-codex-home-"));
2765
+ const agentUid = "agt_01J9AGENTFLAGTEST0000000000";
2766
+ const agentClaims = {
2767
+ sub: "machine-agent",
2768
+ email: "agent@agents.getindigo.ai",
2769
+ "custom:entityType": "agent",
2770
+ "custom:entityUid": agentUid,
2771
+ };
2772
+ const agentToken = `header.${Buffer.from(JSON.stringify(agentClaims)).toString("base64url")}.signature`;
2773
+ const agentEntity = {
2774
+ uid: agentUid,
2775
+ type: "agent",
2776
+ slug: "agent",
2777
+ bucketName: "hq-vault-agent",
2778
+ status: "active",
2779
+ };
2780
+ fs.mkdirSync(path.join(hqRoot, "personal"), { recursive: true });
2781
+ fs.writeFileSync(path.join(hqRoot, "personal", "agents-profile.md"), "agent profile\n");
2782
+ const previousHome = process.env.CODEX_HOME;
2783
+ const previousGate = process.env.HQ_AGENT_CODEX_MATERIALIZE;
2784
+ const runAsAgent = () => runRunner(["--personal", "--hq-root", hqRoot], makeDeps({
2785
+ getAccessToken: vi.fn().mockResolvedValue(agentToken),
2786
+ getIdTokenClaims: () => null,
2787
+ createVaultClient: () => ({
2788
+ ...makeVaultStub(),
2789
+ entity: {
2790
+ get: () => Promise.resolve(undefined),
2791
+ listByType: () => Promise.resolve([agentEntity]),
2792
+ },
2793
+ }),
2794
+ }));
2795
+ try {
2796
+ process.env.CODEX_HOME = codexHome;
2797
+ delete process.env.HQ_AGENT_CODEX_MATERIALIZE;
2798
+ expect(await runAsAgent()).toBe(0);
2799
+ expect(fs.readFileSync(path.join(codexHome, "AGENTS.md"), "utf8")).toContain("agent profile");
2800
+ fs.rmSync(path.join(codexHome, "AGENTS.md"));
2801
+ process.env.HQ_AGENT_CODEX_MATERIALIZE = "0";
2802
+ expect(await runAsAgent()).toBe(0);
2803
+ expect(fs.existsSync(path.join(codexHome, "AGENTS.md"))).toBe(false);
2804
+ delete process.env.HQ_AGENT_CODEX_MATERIALIZE;
2805
+ const personDeps = makeDeps({
2806
+ createVaultClient: () => makeVaultStub({
2807
+ listPersons: () => Promise.resolve([
2808
+ {
2809
+ uid: "prs_person",
2810
+ type: "person",
2811
+ slug: "person",
2812
+ bucketName: "hq-vault-person",
2813
+ status: "active",
2814
+ },
2815
+ ]),
2816
+ }),
2817
+ });
2818
+ expect(await runRunner(["--personal", "--hq-root", hqRoot], personDeps)).toBe(0);
2819
+ expect(fs.existsSync(path.join(codexHome, "AGENTS.md"))).toBe(false);
2820
+ }
2821
+ finally {
2822
+ if (previousHome === undefined)
2823
+ delete process.env.CODEX_HOME;
2824
+ else
2825
+ process.env.CODEX_HOME = previousHome;
2826
+ if (previousGate === undefined)
2827
+ delete process.env.HQ_AGENT_CODEX_MATERIALIZE;
2828
+ else
2829
+ process.env.HQ_AGENT_CODEX_MATERIALIZE = previousGate;
2830
+ fs.rmSync(hqRoot, { recursive: true, force: true });
2831
+ fs.rmSync(codexHome, { recursive: true, force: true });
2832
+ }
2833
+ });
2834
+ it("lets a registry true override all three legacy opt-outs through one injected evaluator", async () => {
2835
+ const hqRoot = fs.mkdtempSync(path.join(os.tmpdir(), "hq-post-sync-flags-on-"));
2836
+ const codexHome = fs.mkdtempSync(path.join(os.tmpdir(), "hq-post-sync-codex-on-"));
2837
+ const agentClaims = {
2838
+ sub: "machine-agent",
2839
+ "custom:entityType": "agent",
2840
+ "custom:entityUid": "agt_01J9AGENTFLAGON000000000000",
2841
+ };
2842
+ const agentToken = `header.${Buffer.from(JSON.stringify(agentClaims)).toString("base64url")}.signature`;
2843
+ const evaluator = {
2844
+ isEnabled: vi.fn().mockReturnValue(true),
2845
+ ready: () => Promise.resolve(),
2846
+ refresh: () => Promise.resolve(),
2847
+ };
2848
+ const qmdReindex = vi.fn(() => ({
2849
+ qmdAvailable: true, collectionsAdded: [], pathDriftDetected: [], collectionsRepaired: [],
2850
+ updated: true, embedded: false, pendingDirty: false, lockBusy: false, timedOut: false,
2851
+ corruptionQuarantined: false, corruptionQuarantineFailed: false, indexDir: null,
2852
+ }));
2853
+ const indexPath = path.join(hqRoot, ".hq-conflicts", "index.json");
2854
+ fs.mkdirSync(path.dirname(indexPath), { recursive: true });
2855
+ fs.writeFileSync(indexPath, JSON.stringify({ version: 1, conflicts: [{
2856
+ id: "orphan", originalPath: "notes.md", conflictPath: "notes.conflict-test.md",
2857
+ detectedAt: "2026-01-01T00:00:00.000Z", side: "pull", machineId: "test",
2858
+ localHash: "sha256:local", remoteHash: "sha256:remote",
2859
+ }] }));
2860
+ fs.mkdirSync(path.join(hqRoot, "personal"), { recursive: true });
2861
+ fs.writeFileSync(path.join(hqRoot, "personal", "agents-profile.md"), "agent profile\n");
2862
+ const previous = {
2863
+ qmd: process.env.HQ_QMD_REINDEX_ON_SYNC,
2864
+ prune: process.env.HQ_CONFLICT_PRUNE_ON_SYNC,
2865
+ codex: process.env.HQ_AGENT_CODEX_MATERIALIZE,
2866
+ home: process.env.CODEX_HOME,
2867
+ };
2868
+ try {
2869
+ process.env.HQ_QMD_REINDEX_ON_SYNC = "0";
2870
+ process.env.HQ_CONFLICT_PRUNE_ON_SYNC = "0";
2871
+ process.env.HQ_AGENT_CODEX_MATERIALIZE = "0";
2872
+ process.env.CODEX_HOME = codexHome;
2873
+ const agentEntity = {
2874
+ uid: agentClaims["custom:entityUid"], type: "agent", slug: "agent",
2875
+ bucketName: "hq-vault-agent", status: "active",
2876
+ };
2877
+ const deps = makeDeps({
2878
+ postSyncFlags: evaluator,
2879
+ qmdReindex,
2880
+ getAccessToken: vi.fn().mockResolvedValue(agentToken),
2881
+ getIdTokenClaims: () => null,
2882
+ createVaultClient: () => ({
2883
+ ...makeVaultStub({
2884
+ memberships: [{ companyUid: "cmp_a" }],
2885
+ entityGet: (uid) => Promise.resolve({ uid, slug: "acme" }),
2886
+ }),
2887
+ entity: {
2888
+ get: (uid) => Promise.resolve({ uid, slug: "acme" }),
2889
+ listByType: () => Promise.resolve([agentEntity]),
2890
+ },
2891
+ }),
2892
+ sync: vi.fn().mockResolvedValue(defaultSyncResult({ changedPaths: ["knowledge/note.md"] })),
2893
+ });
2894
+ expect(await runRunner(["--companies", "--hq-root", hqRoot], deps)).toBe(0);
2895
+ expect(qmdReindex).toHaveBeenCalledTimes(1);
2896
+ expect(JSON.parse(fs.readFileSync(indexPath, "utf8")).conflicts).toEqual([]);
2897
+ expect(fs.existsSync(path.join(codexHome, "AGENTS.md"))).toBe(true);
2898
+ expect(evaluator.isEnabled).toHaveBeenCalledWith(POST_SYNC_FLAG_KEYS.qmdReindex);
2899
+ expect(evaluator.isEnabled).toHaveBeenCalledWith(POST_SYNC_FLAG_KEYS.conflictPrune);
2900
+ expect(evaluator.isEnabled).toHaveBeenCalledWith(POST_SYNC_FLAG_KEYS.codexMaterialize);
2901
+ }
2902
+ finally {
2903
+ if (previous.qmd === undefined)
2904
+ delete process.env.HQ_QMD_REINDEX_ON_SYNC;
2905
+ else
2906
+ process.env.HQ_QMD_REINDEX_ON_SYNC = previous.qmd;
2907
+ if (previous.prune === undefined)
2908
+ delete process.env.HQ_CONFLICT_PRUNE_ON_SYNC;
2909
+ else
2910
+ process.env.HQ_CONFLICT_PRUNE_ON_SYNC = previous.prune;
2911
+ if (previous.codex === undefined)
2912
+ delete process.env.HQ_AGENT_CODEX_MATERIALIZE;
2913
+ else
2914
+ process.env.HQ_AGENT_CODEX_MATERIALIZE = previous.codex;
2915
+ if (previous.home === undefined)
2916
+ delete process.env.CODEX_HOME;
2917
+ else
2918
+ process.env.CODEX_HOME = previous.home;
2919
+ fs.rmSync(hqRoot, { recursive: true, force: true });
2920
+ fs.rmSync(codexHome, { recursive: true, force: true });
2921
+ }
2922
+ });
2666
2923
  it("collects company-level errors into the all-complete errors array", async () => {
2667
2924
  const slugs = { cmp_a: "acme", cmp_b: "beta" };
2668
2925
  const deps = makeDeps({