@indigoai-us/hq-cloud 6.14.22 → 6.14.24

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 (120) hide show
  1. package/dist/bin/sync-runner-company.d.ts.map +1 -1
  2. package/dist/bin/sync-runner-company.js +20 -0
  3. package/dist/bin/sync-runner-company.js.map +1 -1
  4. package/dist/bin/sync-runner-events.test.js +22 -0
  5. package/dist/bin/sync-runner-events.test.js.map +1 -1
  6. package/dist/bin/sync-runner-planning.d.ts +11 -0
  7. package/dist/bin/sync-runner-planning.d.ts.map +1 -1
  8. package/dist/bin/sync-runner-planning.js +37 -2
  9. package/dist/bin/sync-runner-planning.js.map +1 -1
  10. package/dist/bin/sync-runner-planning.test.js +1 -0
  11. package/dist/bin/sync-runner-planning.test.js.map +1 -1
  12. package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
  13. package/dist/bin/sync-runner-watch-loop.js +17 -1
  14. package/dist/bin/sync-runner-watch-loop.js.map +1 -1
  15. package/dist/bin/sync-runner.d.ts +33 -1
  16. package/dist/bin/sync-runner.d.ts.map +1 -1
  17. package/dist/bin/sync-runner.js +28 -3
  18. package/dist/bin/sync-runner.js.map +1 -1
  19. package/dist/bin/sync-runner.test.js +206 -2
  20. package/dist/bin/sync-runner.test.js.map +1 -1
  21. package/dist/cli/doctor.d.ts +119 -0
  22. package/dist/cli/doctor.d.ts.map +1 -0
  23. package/dist/cli/doctor.js +485 -0
  24. package/dist/cli/doctor.js.map +1 -0
  25. package/dist/cli/doctor.test.d.ts +13 -0
  26. package/dist/cli/doctor.test.d.ts.map +1 -0
  27. package/dist/cli/doctor.test.js +485 -0
  28. package/dist/cli/doctor.test.js.map +1 -0
  29. package/dist/cli/index.d.ts +2 -0
  30. package/dist/cli/index.d.ts.map +1 -1
  31. package/dist/cli/index.js +4 -0
  32. package/dist/cli/index.js.map +1 -1
  33. package/dist/cli/share.js +6 -1
  34. package/dist/cli/share.js.map +1 -1
  35. package/dist/cli/share.test.js +1 -0
  36. package/dist/cli/share.test.js.map +1 -1
  37. package/dist/cli/sync.d.ts +54 -0
  38. package/dist/cli/sync.d.ts.map +1 -1
  39. package/dist/cli/sync.js +223 -3
  40. package/dist/cli/sync.js.map +1 -1
  41. package/dist/cli/sync.test.js +394 -1
  42. package/dist/cli/sync.test.js.map +1 -1
  43. package/dist/cognito-auth.test.js +7 -0
  44. package/dist/cognito-auth.test.js.map +1 -1
  45. package/dist/index.d.ts +2 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +3 -0
  48. package/dist/index.js.map +1 -1
  49. package/dist/lib/conflict-file.d.ts.map +1 -1
  50. package/dist/lib/conflict-file.js +5 -1
  51. package/dist/lib/conflict-file.js.map +1 -1
  52. package/dist/lib/conflict-index.d.ts +7 -0
  53. package/dist/lib/conflict-index.d.ts.map +1 -1
  54. package/dist/lib/conflict-index.js +10 -2
  55. package/dist/lib/conflict-index.js.map +1 -1
  56. package/dist/lib/conflict.test.js +31 -0
  57. package/dist/lib/conflict.test.js.map +1 -1
  58. package/dist/lib/machine-id.test.js +14 -0
  59. package/dist/lib/machine-id.test.js.map +1 -1
  60. package/dist/local-path-codec.d.ts +18 -0
  61. package/dist/local-path-codec.d.ts.map +1 -1
  62. package/dist/local-path-codec.js +63 -0
  63. package/dist/local-path-codec.js.map +1 -1
  64. package/dist/local-path-codec.test.d.ts +14 -0
  65. package/dist/local-path-codec.test.d.ts.map +1 -0
  66. package/dist/local-path-codec.test.js +102 -0
  67. package/dist/local-path-codec.test.js.map +1 -0
  68. package/dist/machine-auth.test.js +7 -0
  69. package/dist/machine-auth.test.js.map +1 -1
  70. package/dist/s3.d.ts +5 -0
  71. package/dist/s3.d.ts.map +1 -1
  72. package/dist/s3.js +129 -3
  73. package/dist/s3.js.map +1 -1
  74. package/dist/s3.symlink-materialize.test.d.ts +18 -0
  75. package/dist/s3.symlink-materialize.test.d.ts.map +1 -0
  76. package/dist/s3.symlink-materialize.test.js +394 -0
  77. package/dist/s3.symlink-materialize.test.js.map +1 -0
  78. package/dist/s3.test.js +19 -0
  79. package/dist/s3.test.js.map +1 -1
  80. package/dist/skill-telemetry.d.ts.map +1 -1
  81. package/dist/skill-telemetry.js +23 -2
  82. package/dist/skill-telemetry.js.map +1 -1
  83. package/dist/skill-telemetry.test.js +17 -0
  84. package/dist/skill-telemetry.test.js.map +1 -1
  85. package/dist/watcher.d.ts.map +1 -1
  86. package/dist/watcher.js +10 -1
  87. package/dist/watcher.js.map +1 -1
  88. package/dist/watcher.test.js +28 -0
  89. package/dist/watcher.test.js.map +1 -1
  90. package/package.json +1 -1
  91. package/src/bin/sync-runner-company.ts +18 -0
  92. package/src/bin/sync-runner-events.test.ts +31 -0
  93. package/src/bin/sync-runner-planning.test.ts +1 -0
  94. package/src/bin/sync-runner-planning.ts +46 -3
  95. package/src/bin/sync-runner-watch-loop.ts +19 -1
  96. package/src/bin/sync-runner.test.ts +236 -1
  97. package/src/bin/sync-runner.ts +57 -2
  98. package/src/cli/doctor.test.ts +581 -0
  99. package/src/cli/doctor.ts +640 -0
  100. package/src/cli/index.ts +14 -0
  101. package/src/cli/share.test.ts +1 -0
  102. package/src/cli/share.ts +6 -1
  103. package/src/cli/sync.test.ts +473 -1
  104. package/src/cli/sync.ts +310 -3
  105. package/src/cognito-auth.test.ts +5 -0
  106. package/src/index.ts +10 -0
  107. package/src/lib/conflict-file.ts +6 -1
  108. package/src/lib/conflict-index.ts +18 -2
  109. package/src/lib/conflict.test.ts +33 -0
  110. package/src/lib/machine-id.test.ts +10 -0
  111. package/src/local-path-codec.test.ts +138 -0
  112. package/src/local-path-codec.ts +66 -0
  113. package/src/machine-auth.test.ts +5 -0
  114. package/src/s3.symlink-materialize.test.ts +492 -0
  115. package/src/s3.test.ts +24 -0
  116. package/src/s3.ts +148 -4
  117. package/src/skill-telemetry.test.ts +19 -0
  118. package/src/skill-telemetry.ts +31 -2
  119. package/src/watcher.test.ts +33 -0
  120. package/src/watcher.ts +10 -1
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Regression tests for US-002 (hq-sync-windows-skill-symlink-collision):
3
+ * the canonical-spelling fixpoint and the mixed-version amplifier round trip.
4
+ *
5
+ * Amplifier background: pre-codec engines mint vault keys verbatim from
6
+ * Windows local names (`core%3Askill`), and post-codec engines escape `%`
7
+ * before every other character locally — so each pull+re-walk hop across a
8
+ * mixed-version fleet minted one more percent generation (`%253A`,
9
+ * `%25253A`, …). These tests pin the two properties that kill the loop:
10
+ * the walk-back maps a materialized junk key to its EXACT original spelling,
11
+ * and every generation collapses to one canonical fixpoint for guard lookups.
12
+ */
13
+
14
+ import { describe, it, expect, beforeEach, afterEach } from "vitest";
15
+ import * as fs from "fs";
16
+ import * as os from "os";
17
+ import * as path from "path";
18
+ import {
19
+ canonicalVaultKeySpelling,
20
+ canonicalVaultSegmentSpelling,
21
+ localPathForVaultKey,
22
+ vaultKeyForLocalPath,
23
+ } from "./local-path-codec.js";
24
+
25
+ describe("canonicalVaultKeySpelling (US-002)", () => {
26
+ it("collapses every junk percent generation to the same fixpoint", () => {
27
+ const canonical = ".claude/skills/core:skill/scripts";
28
+ expect(canonicalVaultKeySpelling(canonical)).toBe(canonical);
29
+ expect(canonicalVaultKeySpelling(".claude/skills/core%3Askill/scripts")).toBe(canonical);
30
+ expect(canonicalVaultKeySpelling(".claude/skills/core%253Askill/scripts")).toBe(canonical);
31
+ expect(canonicalVaultKeySpelling(".claude/skills/core%25253Askill/scripts")).toBe(canonical);
32
+ });
33
+
34
+ it("distinct logical paths keep distinct fixpoints", () => {
35
+ expect(canonicalVaultKeySpelling("a%3Ab/x")).not.toBe(
36
+ canonicalVaultKeySpelling("a%3Ac/x"),
37
+ );
38
+ });
39
+
40
+ it("colon-free percent names are their OWN canonical form — never collapsed (round-9)", () => {
41
+ // `.claude/skills/foo bar` and `.claude/skills/foo%20bar` are two
42
+ // distinct legitimate skills; only namespaced (<ns>:<skill>) wrapper
43
+ // generations participate in the amplifier.
44
+ expect(canonicalVaultKeySpelling(".claude/skills/foo%20bar/SKILL.md")).toBe(
45
+ ".claude/skills/foo%20bar/SKILL.md",
46
+ );
47
+ expect(canonicalVaultKeySpelling(".claude/skills/foo bar/SKILL.md")).toBe(
48
+ ".claude/skills/foo bar/SKILL.md",
49
+ );
50
+ expect(canonicalVaultSegmentSpelling("foo%20bar")).toBe("foo%20bar");
51
+ // Namespaced generations still collapse.
52
+ expect(canonicalVaultSegmentSpelling("ns%3Askill")).toBe("ns:skill");
53
+ });
54
+
55
+ it("stops decoding at the first literal colon — a legitimately percent-named skill stays distinct", () => {
56
+ // reindex forms `core:foo%3Abar` verbatim from a source dir named
57
+ // `foo%3Abar`; decoding past the colon would collapse it into the
58
+ // unrelated `core:foo:bar` family.
59
+ expect(canonicalVaultKeySpelling(".claude/skills/core:foo%3Abar/SKILL.md")).toBe(
60
+ ".claude/skills/core:foo%3Abar/SKILL.md",
61
+ );
62
+ // The win32-encoded generation of that same weird-but-legit wrapper
63
+ // decodes exactly one step — back to the colon form, not beyond.
64
+ expect(
65
+ canonicalVaultKeySpelling(".claude/skills/core%3Afoo%253Abar/SKILL.md"),
66
+ ).toBe(".claude/skills/core:foo%3Abar/SKILL.md");
67
+ });
68
+
69
+ it("decodes ONLY the wrapper segment — child-file percent escapes stay verbatim", () => {
70
+ // `scripts/foo%20bar.sh` and `scripts/foo bar.sh` are distinct objects;
71
+ // collapsing them would let the doctor/pull guard drop the wrong one.
72
+ expect(
73
+ canonicalVaultKeySpelling(".claude/skills/core%3Askill/scripts/foo%20bar.sh"),
74
+ ).toBe(".claude/skills/core:skill/scripts/foo%20bar.sh");
75
+ expect(
76
+ canonicalVaultKeySpelling(".claude/skills/core:skill/scripts/foo%20bar.sh"),
77
+ ).toBe(".claude/skills/core:skill/scripts/foo%20bar.sh");
78
+ });
79
+
80
+ it("returns non-skills keys verbatim — the amplifier only exists in the wrapper namespace", () => {
81
+ expect(canonicalVaultKeySpelling("notes/a%3Ab.md")).toBe("notes/a%3Ab.md");
82
+ expect(canonicalVaultKeySpelling("notes/a%20b.md")).toBe("notes/a%20b.md");
83
+ });
84
+
85
+ it("leaves a % that is not a two-hex-digit escape alone", () => {
86
+ // Matches decodeLocalVaultSegment: only `%XX` (hex) is an escape.
87
+ expect(canonicalVaultKeySpelling("notes/50%-done.md")).toBe("notes/50%-done.md");
88
+ });
89
+ });
90
+
91
+ describe("mixed-version amplifier round trip (US-002)", () => {
92
+ let tmpRoot: string;
93
+
94
+ beforeEach(() => {
95
+ tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "codec-amp-test-"));
96
+ });
97
+
98
+ afterEach(() => {
99
+ fs.rmSync(tmpRoot, { recursive: true, force: true });
100
+ });
101
+
102
+ it("a literal %3A key pulled + re-walked with win32=true maps back to the EXACT original key — no %253A generation", () => {
103
+ // Key minted by a pre-codec engine from a Windows local farm name.
104
+ const win32 = true;
105
+ const junkKey = ".claude/skills/core%3Askill/scripts";
106
+
107
+ // Pull leg: materialize at the codec-derived local path. `%` is escaped
108
+ // before every other character, so the on-disk dir name is
109
+ // `core%253Askill` — that escape is exactly what makes the walk-back
110
+ // unambiguous instead of colliding with the canonical `core:skill` key.
111
+ const localPath = localPathForVaultKey(tmpRoot, junkKey, win32);
112
+ fs.mkdirSync(localPath, { recursive: true });
113
+ const farmEntries = fs.readdirSync(
114
+ path.join(tmpRoot, ".claude", "skills"),
115
+ );
116
+ expect(farmEntries).toEqual(["core%253Askill"]);
117
+
118
+ // Re-walk leg: the push walker maps the materialized name back to a key
119
+ // (share.ts walkDir convention: vaultKeyForLocalPath on the abs path).
120
+ const rewalkedKey = vaultKeyForLocalPath(tmpRoot, localPath, win32);
121
+
122
+ // The amplifier is dead only if this is the EXACT original spelling —
123
+ // any NEW spelling would upload as a fresh junk key generation.
124
+ expect(rewalkedKey).toBe(junkKey);
125
+ expect(rewalkedKey).not.toContain("%253A");
126
+ });
127
+
128
+ it("the canonical ':' key and its '%3A' twin materialize at DISTINCT local paths and round-trip independently", () => {
129
+ const win32 = true;
130
+ const canonicalLocal = localPathForVaultKey(tmpRoot, "farm/a:b", win32);
131
+ const junkLocal = localPathForVaultKey(tmpRoot, "farm/a%3Ab", win32);
132
+ // No on-disk collision between the two key families …
133
+ expect(canonicalLocal).not.toBe(junkLocal);
134
+ // … and each walks back to its own exact spelling.
135
+ expect(vaultKeyForLocalPath(tmpRoot, canonicalLocal, win32)).toBe("farm/a:b");
136
+ expect(vaultKeyForLocalPath(tmpRoot, junkLocal, win32)).toBe("farm/a%3Ab");
137
+ });
138
+ });
@@ -93,3 +93,69 @@ export function vaultKeyForLocalPath(
93
93
  .map((segment) => decodeLocalVaultSegment(segment, win32))
94
94
  .join("/");
95
95
  }
96
+
97
+ /**
98
+ * Collapse a vault-key spelling to its canonical logical form by repeatedly
99
+ * percent-decoding every segment to a fixpoint.
100
+ *
101
+ * Mixed-version amplifier context: a pre-codec Windows engine uploads its
102
+ * local farm names verbatim, minting keys like `core%3Askill`; a post-codec
103
+ * engine that materializes that key re-escapes the `%` on its next walk, and
104
+ * a pre-codec peer re-uploads `core%253Askill` — one junk generation per hop.
105
+ * Every generation decodes to the same fixpoint (`core:skill`), so the
106
+ * fixpoint — never the raw spelling — is the identity of the logical path.
107
+ * Decodes with win32 semantics unconditionally: junk spellings are a
108
+ * key-space (wire) phenomenon, not a host-platform one. Used by the pull
109
+ * planner's junk-spelling guard; deliberately NEVER used to rewrite keys
110
+ * (journals and the wire always keep the exact spelling they were minted
111
+ * with — collapsing families is the vault doctor's job, US-003).
112
+ */
113
+ export function canonicalVaultSegmentSpelling(segment: string): string {
114
+ // Junk generations are encodings of the FULL canonical wrapper name, so a
115
+ // generation never contains a literal ':' — the colon is what got encoded
116
+ // (`ns:skill` -> `ns%3Askill` -> `ns%253Askill` -> ...). The decode loop
117
+ // therefore stops the moment a spelling contains a colon: that IS the
118
+ // canonical form. This keeps a legitimately-percent-named skill distinct —
119
+ // reindex forms `core:foo%3Abar` verbatim from a source dir named
120
+ // `foo%3Abar`, and decoding past the colon would wrongly collapse it into
121
+ // `core:foo:bar`. (Colon-free names with %XX, e.g. `foo%20bar`, still
122
+ // decode — that is the cross-platform unification of a win32-encoded
123
+ // wrapper for canonical `foo bar`; a POSIX source dir literally named
124
+ // `foo%20bar` is inherently ambiguous, and the doctor's marker-body
125
+ // safety gate bounds what can be auto-deleted for such names.)
126
+ let current = segment;
127
+ while (!current.includes(":")) {
128
+ const decoded = decodeLocalVaultSegment(current, true);
129
+ if (decoded === current) break;
130
+ current = decoded;
131
+ }
132
+ // A decode chain that never reaches a colon is NOT an amplifier family —
133
+ // generated wrapper generations always decode back to `<ns>:<skill>`. A
134
+ // colon-free percent name (`foo%20bar`) is a legitimate skill's own
135
+ // spelling, distinct from `foo bar`; collapsing it would let the pull
136
+ // guard skip it and the doctor rewrite-then-delete real content. Return
137
+ // the ORIGINAL spelling so colon-free names are always their own
138
+ // canonical form.
139
+ return current.includes(":") ? current : segment;
140
+ }
141
+
142
+ export function canonicalVaultKeySpelling(key: string): string {
143
+ // Only the WRAPPER directory name under `.claude/skills/` is subject to
144
+ // the mixed-version spelling amplifier — platforms disagree solely about
145
+ // how the `<ns>:<skill>` name is spelled on disk. Child segments keep
146
+ // their percent escapes verbatim (`scripts/foo%20bar.sh` and
147
+ // `scripts/foo bar.sh` are DISTINCT objects); decoding them too would
148
+ // collapse legitimate files into one family and let the doctor or pull
149
+ // guard skip/tombstone the wrong object. Non-skills keys pass through
150
+ // untouched for the same reason.
151
+ const segments = key.split("/");
152
+ if (
153
+ segments.length < 3 ||
154
+ segments[0] !== ".claude" ||
155
+ segments[1] !== "skills"
156
+ ) {
157
+ return key;
158
+ }
159
+ segments[2] = canonicalVaultSegmentSpelling(segments[2]!);
160
+ return segments.join("/");
161
+ }
@@ -19,14 +19,17 @@ import { pathToFileURL } from "url";
19
19
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
20
20
 
21
21
  let originalHome: string | undefined;
22
+ let originalUserProfile: string | undefined;
22
23
  let originalCredsEnv: string | undefined;
23
24
  let tmpHome: string;
24
25
 
25
26
  beforeEach(() => {
26
27
  originalHome = process.env.HOME;
28
+ originalUserProfile = process.env.USERPROFILE;
27
29
  originalCredsEnv = process.env.HQ_MACHINE_CREDS_FILE;
28
30
  tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), "hq-machine-auth-test-"));
29
31
  process.env.HOME = tmpHome;
32
+ process.env.USERPROFILE = tmpHome;
30
33
  delete process.env.HQ_MACHINE_CREDS_FILE;
31
34
  vi.resetModules();
32
35
  });
@@ -35,6 +38,8 @@ afterEach(() => {
35
38
  vi.useRealTimers();
36
39
  if (originalHome === undefined) delete process.env.HOME;
37
40
  else process.env.HOME = originalHome;
41
+ if (originalUserProfile === undefined) delete process.env.USERPROFILE;
42
+ else process.env.USERPROFILE = originalUserProfile;
38
43
  if (originalCredsEnv === undefined) delete process.env.HQ_MACHINE_CREDS_FILE;
39
44
  else process.env.HQ_MACHINE_CREDS_FILE = originalCredsEnv;
40
45
  fs.rmSync(tmpHome, { recursive: true, force: true });