@indigoai-us/hq-cli 5.3.0 → 5.4.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 (141) hide show
  1. package/dist/bin/hq-auth-refresh.d.ts +13 -0
  2. package/dist/bin/hq-auth-refresh.d.ts.map +1 -0
  3. package/dist/bin/hq-auth-refresh.js +27 -0
  4. package/dist/bin/hq-auth-refresh.js.map +1 -0
  5. package/dist/commands/auth.d.ts +17 -13
  6. package/dist/commands/auth.d.ts.map +1 -1
  7. package/dist/commands/auth.js +83 -238
  8. package/dist/commands/auth.js.map +1 -1
  9. package/dist/commands/cloud.d.ts +3 -12
  10. package/dist/commands/cloud.d.ts.map +1 -1
  11. package/dist/commands/cloud.js +55 -212
  12. package/dist/commands/cloud.js.map +1 -1
  13. package/dist/commands/login.d.ts +6 -0
  14. package/dist/commands/login.d.ts.map +1 -0
  15. package/dist/commands/login.js +25 -0
  16. package/dist/commands/login.js.map +1 -0
  17. package/dist/commands/logout.d.ts +6 -0
  18. package/dist/commands/logout.d.ts.map +1 -0
  19. package/dist/commands/logout.js +21 -0
  20. package/dist/commands/logout.js.map +1 -0
  21. package/dist/commands/onboard.d.ts +23 -0
  22. package/dist/commands/onboard.d.ts.map +1 -0
  23. package/dist/commands/onboard.js +142 -0
  24. package/dist/commands/onboard.js.map +1 -0
  25. package/dist/commands/pkg-install.d.ts +17 -0
  26. package/dist/commands/pkg-install.d.ts.map +1 -0
  27. package/dist/commands/pkg-install.js +144 -0
  28. package/dist/commands/pkg-install.js.map +1 -0
  29. package/dist/commands/pkg-list.d.ts +8 -0
  30. package/dist/commands/pkg-list.d.ts.map +1 -0
  31. package/dist/commands/pkg-list.js +70 -0
  32. package/dist/commands/pkg-list.js.map +1 -0
  33. package/dist/commands/pkg-remove.d.ts +10 -0
  34. package/dist/commands/pkg-remove.d.ts.map +1 -0
  35. package/dist/commands/pkg-remove.js +53 -0
  36. package/dist/commands/pkg-remove.js.map +1 -0
  37. package/dist/commands/pkg-update.d.ts +9 -0
  38. package/dist/commands/pkg-update.d.ts.map +1 -0
  39. package/dist/commands/pkg-update.js +124 -0
  40. package/dist/commands/pkg-update.js.map +1 -0
  41. package/dist/commands/team-sync.d.ts +14 -0
  42. package/dist/commands/team-sync.d.ts.map +1 -0
  43. package/dist/commands/team-sync.js +422 -0
  44. package/dist/commands/team-sync.js.map +1 -0
  45. package/dist/commands/whoami.d.ts +6 -0
  46. package/dist/commands/whoami.d.ts.map +1 -0
  47. package/dist/commands/whoami.js +29 -0
  48. package/dist/commands/whoami.js.map +1 -0
  49. package/dist/index.d.ts +1 -1
  50. package/dist/index.js +33 -10
  51. package/dist/index.js.map +1 -1
  52. package/dist/strategies/merge.js +2 -2
  53. package/dist/strategies/merge.js.map +1 -1
  54. package/dist/utils/auth.d.ts +27 -0
  55. package/dist/utils/auth.d.ts.map +1 -0
  56. package/dist/utils/auth.js +155 -0
  57. package/dist/utils/auth.js.map +1 -0
  58. package/dist/utils/cognito-session.d.ts +35 -0
  59. package/dist/utils/cognito-session.d.ts.map +1 -0
  60. package/dist/utils/cognito-session.js +72 -0
  61. package/dist/utils/cognito-session.js.map +1 -0
  62. package/dist/utils/git.js +1 -1
  63. package/dist/utils/git.js.map +1 -1
  64. package/dist/utils/hq-root.d.ts +10 -0
  65. package/dist/utils/hq-root.d.ts.map +1 -0
  66. package/dist/utils/hq-root.js +22 -0
  67. package/dist/utils/hq-root.js.map +1 -0
  68. package/dist/utils/integrity.d.ts +14 -0
  69. package/dist/utils/integrity.d.ts.map +1 -0
  70. package/dist/utils/integrity.js +40 -0
  71. package/dist/utils/integrity.js.map +1 -0
  72. package/dist/utils/manifest.d.ts.map +1 -1
  73. package/dist/utils/manifest.js +2 -5
  74. package/dist/utils/manifest.js.map +1 -1
  75. package/dist/utils/registry-client.d.ts +65 -0
  76. package/dist/utils/registry-client.d.ts.map +1 -0
  77. package/dist/utils/registry-client.js +102 -0
  78. package/dist/utils/registry-client.js.map +1 -0
  79. package/dist/utils/registry.d.ts +33 -0
  80. package/dist/utils/registry.d.ts.map +1 -0
  81. package/dist/utils/registry.js +58 -0
  82. package/dist/utils/registry.js.map +1 -0
  83. package/dist/utils/token-store.d.ts +28 -0
  84. package/dist/utils/token-store.d.ts.map +1 -0
  85. package/dist/utils/token-store.js +68 -0
  86. package/dist/utils/token-store.js.map +1 -0
  87. package/package.json +35 -45
  88. package/src/bin/hq-auth-refresh.ts +32 -0
  89. package/src/commands/add.ts +74 -0
  90. package/src/commands/auth.ts +153 -0
  91. package/src/commands/cloud.ts +125 -0
  92. package/src/commands/list.ts +66 -0
  93. package/src/commands/login.ts +29 -0
  94. package/src/commands/logout.ts +25 -0
  95. package/src/commands/pkg-install.ts +181 -0
  96. package/src/commands/pkg-list.ts +98 -0
  97. package/src/commands/pkg-remove.ts +71 -0
  98. package/src/commands/pkg-update.ts +189 -0
  99. package/src/commands/sync.ts +149 -0
  100. package/src/commands/team-sync.ts +629 -0
  101. package/src/commands/update.ts +71 -0
  102. package/src/commands/whoami.ts +38 -0
  103. package/src/index.ts +72 -0
  104. package/src/schemas/hq-package.schema.json +137 -0
  105. package/src/strategies/link.ts +62 -0
  106. package/src/strategies/merge.ts +142 -0
  107. package/src/types.ts +47 -0
  108. package/src/utils/auth.ts +193 -0
  109. package/src/utils/cognito-session.ts +94 -0
  110. package/src/utils/git.ts +74 -0
  111. package/src/utils/hq-root.ts +27 -0
  112. package/src/utils/integrity.ts +54 -0
  113. package/src/utils/manifest.ts +109 -0
  114. package/src/utils/registry-client.ts +204 -0
  115. package/src/utils/registry.ts +89 -0
  116. package/src/utils/token-store.ts +83 -0
  117. package/tsconfig.json +8 -0
  118. package/dist/commands/cloud-setup.d.ts +0 -19
  119. package/dist/commands/cloud-setup.d.ts.map +0 -1
  120. package/dist/commands/cloud-setup.js +0 -206
  121. package/dist/commands/cloud-setup.js.map +0 -1
  122. package/dist/commands/initial-upload.d.ts +0 -67
  123. package/dist/commands/initial-upload.d.ts.map +0 -1
  124. package/dist/commands/initial-upload.js +0 -205
  125. package/dist/commands/initial-upload.js.map +0 -1
  126. package/dist/sync-worker.d.ts +0 -11
  127. package/dist/sync-worker.d.ts.map +0 -1
  128. package/dist/sync-worker.js +0 -77
  129. package/dist/sync-worker.js.map +0 -1
  130. package/dist/utils/api-client.d.ts +0 -26
  131. package/dist/utils/api-client.d.ts.map +0 -1
  132. package/dist/utils/api-client.js +0 -87
  133. package/dist/utils/api-client.js.map +0 -1
  134. package/dist/utils/credentials.d.ts +0 -44
  135. package/dist/utils/credentials.d.ts.map +0 -1
  136. package/dist/utils/credentials.js +0 -101
  137. package/dist/utils/credentials.js.map +0 -1
  138. package/dist/utils/sync.d.ts +0 -125
  139. package/dist/utils/sync.d.ts.map +0 -1
  140. package/dist/utils/sync.js +0 -291
  141. package/dist/utils/sync.js.map +0 -1
@@ -0,0 +1,149 @@
1
+ /**
2
+ * hq modules sync command (US-004)
3
+ */
4
+
5
+ import * as fs from 'fs';
6
+ import * as path from 'path';
7
+ import { Command } from 'commander';
8
+ import {
9
+ findHqRoot,
10
+ readManifest,
11
+ readLock,
12
+ writeLock,
13
+ getModulesDir,
14
+ } from '../utils/manifest.js';
15
+ import {
16
+ cloneRepo,
17
+ fetchRepo,
18
+ pullRepo,
19
+ getCurrentCommit,
20
+ checkoutCommit,
21
+ isRepo,
22
+ ensureGitignore,
23
+ } from '../utils/git.js';
24
+ import { linkSync } from '../strategies/link.js';
25
+ import { mergeSync } from '../strategies/merge.js';
26
+ import type { ModuleDefinition, ModuleLock, SyncResult } from '../types.js';
27
+
28
+ async function syncModule(
29
+ module: ModuleDefinition,
30
+ moduleDir: string,
31
+ hqRoot: string,
32
+ locked: boolean,
33
+ lockData: ModuleLock | null
34
+ ): Promise<SyncResult> {
35
+ const repoExists = await isRepo(moduleDir);
36
+
37
+ // Clone or fetch
38
+ if (!repoExists) {
39
+ console.log(` Cloning ${module.name}...`);
40
+ await cloneRepo(module.repo, moduleDir, module.branch);
41
+ } else {
42
+ console.log(` Fetching ${module.name}...`);
43
+ await fetchRepo(moduleDir);
44
+
45
+ // Checkout locked commit if --locked
46
+ if (locked && lockData?.locked[module.name]) {
47
+ await checkoutCommit(moduleDir, lockData.locked[module.name]);
48
+ } else {
49
+ await pullRepo(moduleDir);
50
+ }
51
+ }
52
+
53
+ // Apply sync strategy
54
+ console.log(` Syncing with strategy: ${module.strategy}`);
55
+ let result: SyncResult;
56
+
57
+ switch (module.strategy) {
58
+ case 'link':
59
+ result = await linkSync(module, moduleDir, hqRoot);
60
+ break;
61
+ case 'merge':
62
+ case 'copy':
63
+ result = await mergeSync(module, moduleDir, hqRoot);
64
+ break;
65
+ default:
66
+ result = {
67
+ module: module.name,
68
+ success: false,
69
+ action: 'skipped',
70
+ message: `Unknown strategy: ${module.strategy}`,
71
+ };
72
+ }
73
+
74
+ return result;
75
+ }
76
+
77
+ export function registerSyncCommand(program: Command): void {
78
+ program
79
+ .command('sync')
80
+ .description('Sync all modules from manifest')
81
+ .option('--locked', 'Use locked versions from modules.lock')
82
+ .action(async (options: { locked?: boolean }) => {
83
+ try {
84
+ const hqRoot = findHqRoot();
85
+ const manifest = readManifest(hqRoot);
86
+
87
+ if (!manifest || manifest.modules.length === 0) {
88
+ console.log('No modules in manifest. Use "hq modules add" to add modules.');
89
+ return;
90
+ }
91
+
92
+ const modulesDir = getModulesDir(hqRoot);
93
+ if (!fs.existsSync(modulesDir)) {
94
+ fs.mkdirSync(modulesDir, { recursive: true });
95
+ }
96
+
97
+ // Ensure modules/ is gitignored
98
+ ensureGitignore(hqRoot, 'modules/');
99
+
100
+ const lockData = options.locked ? readLock(hqRoot) : null;
101
+ const results: SyncResult[] = [];
102
+ const newLock: ModuleLock = { version: '1', locked: {} };
103
+
104
+ console.log(`Syncing ${manifest.modules.length} module(s)...\n`);
105
+
106
+ for (const module of manifest.modules) {
107
+ console.log(`[${module.name}]`);
108
+ const moduleDir = path.join(modulesDir, module.name);
109
+
110
+ const result = await syncModule(
111
+ module,
112
+ moduleDir,
113
+ hqRoot,
114
+ options.locked ?? false,
115
+ lockData
116
+ );
117
+ results.push(result);
118
+
119
+ // Record commit for lock file
120
+ if (result.success) {
121
+ const commit = await getCurrentCommit(moduleDir);
122
+ newLock.locked[module.name] = commit;
123
+ }
124
+
125
+ const status = result.success ? '✓' : '✗';
126
+ const msg = result.message || `${result.filesChanged ?? 0} files`;
127
+ console.log(` ${status} ${result.action}: ${msg}\n`);
128
+ }
129
+
130
+ // Write lock file (US-008)
131
+ if (!options.locked) {
132
+ writeLock(hqRoot, newLock);
133
+ }
134
+
135
+ // Summary
136
+ const success = results.filter(r => r.success).length;
137
+ const failed = results.filter(r => !r.success).length;
138
+ console.log(`Done: ${success} succeeded, ${failed} failed`);
139
+
140
+ if (failed > 0) {
141
+ process.exit(1);
142
+ }
143
+
144
+ } catch (error) {
145
+ console.error('Error:', error instanceof Error ? error.message : error);
146
+ process.exit(1);
147
+ }
148
+ });
149
+ }