@gurulu/cli 0.4.2 → 0.4.4

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.
@@ -1,5 +1,8 @@
1
1
  /**
2
2
  * Phase 19.5 W2 B8 — `gurulu identity decay|transfers|cdc-sources`.
3
+ *
4
+ * Sprint E SE-D — `gurulu identity identify|alias|merge` write surface
5
+ * (mirrors MCP `gurulu.identity.identify` / `.alias` / `.merge`).
3
6
  */
4
7
  export interface IdentityArgs {
5
8
  action?: string;
@@ -7,7 +10,20 @@ export interface IdentityArgs {
7
10
  direction?: string;
8
11
  status?: string;
9
12
  limit?: number;
13
+ site?: string;
14
+ userId?: string;
15
+ email?: string;
16
+ phone?: string;
17
+ traits?: string;
18
+ previousUserId?: string;
19
+ newUserId?: string;
20
+ canonicalId?: string;
21
+ duplicateId?: string;
22
+ yes?: boolean;
10
23
  json?: boolean;
11
24
  profile?: string;
25
+ file?: string;
26
+ format?: string;
27
+ resumeFrom?: number;
12
28
  }
13
29
  export declare function identityCommand(args: IdentityArgs): Promise<void>;
@@ -1,11 +1,49 @@
1
1
  "use strict";
2
2
  /**
3
3
  * Phase 19.5 W2 B8 — `gurulu identity decay|transfers|cdc-sources`.
4
+ *
5
+ * Sprint E SE-D — `gurulu identity identify|alias|merge` write surface
6
+ * (mirrors MCP `gurulu.identity.identify` / `.alias` / `.merge`).
4
7
  */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
5
41
  Object.defineProperty(exports, "__esModule", { value: true });
6
42
  exports.identityCommand = identityCommand;
7
43
  const api_client_1 = require("../api-client");
8
44
  const ui_1 = require("../utils/ui");
45
+ const fs = __importStar(require("fs"));
46
+ const path = __importStar(require("path"));
9
47
  async function identityCommand(args) {
10
48
  const action = args.action || '';
11
49
  switch (action) {
@@ -15,9 +53,17 @@ async function identityCommand(args) {
15
53
  return transfersCmd(args);
16
54
  case 'cdc-sources':
17
55
  return cdcSourcesCmd(args);
56
+ case 'identify':
57
+ return identifyCmd(args);
58
+ case 'alias':
59
+ return aliasCmd(args);
60
+ case 'merge':
61
+ return mergeCmd(args);
62
+ case 'bulk':
63
+ return bulkCmd(args);
18
64
  default:
19
65
  (0, ui_1.error)(`Unknown identity action: ${action}`);
20
- (0, ui_1.info)('Usage: gurulu identity [decay stats|transfers list|cdc-sources list]');
66
+ (0, ui_1.info)('Usage: gurulu identity [decay stats|transfers list|cdc-sources list|identify|alias|merge|bulk]');
21
67
  process.exit(1);
22
68
  }
23
69
  }
@@ -76,6 +122,181 @@ async function transfersCmd(args) {
76
122
  ].join('\t') + '\n');
77
123
  }
78
124
  }
125
+ async function identifyCmd(args) {
126
+ if (!args.site || !args.userId) {
127
+ (0, ui_1.error)('Usage: gurulu identity identify --site=<id> --user-id=<id> [--email=...] [--phone=...] [--traits=<json>]');
128
+ process.exit(1);
129
+ }
130
+ let traits;
131
+ if (args.traits) {
132
+ try {
133
+ traits = JSON.parse(args.traits);
134
+ }
135
+ catch {
136
+ (0, ui_1.error)('--traits must be valid JSON');
137
+ process.exit(1);
138
+ }
139
+ }
140
+ const body = await (0, api_client_1.cliApiJson)('/api/cli/identity/identify', {
141
+ profile: args.profile,
142
+ method: 'POST',
143
+ json: {
144
+ siteId: args.site,
145
+ userId: args.userId,
146
+ email: args.email,
147
+ phone: args.phone,
148
+ traits,
149
+ },
150
+ });
151
+ if (args.json) {
152
+ process.stdout.write(JSON.stringify(body, null, 2) + '\n');
153
+ return;
154
+ }
155
+ (0, ui_1.success)(`Identified ${args.userId}.`);
156
+ if (body.canonicalPersonId) {
157
+ process.stdout.write(` canonicalPersonId: ${body.canonicalPersonId}\n`);
158
+ }
159
+ }
160
+ async function aliasCmd(args) {
161
+ if (!args.site || !args.previousUserId || !args.newUserId) {
162
+ (0, ui_1.error)('Usage: gurulu identity alias --site=<id> --previous-user-id=<anon> --new-user-id=<u123>');
163
+ process.exit(1);
164
+ }
165
+ const body = await (0, api_client_1.cliApiJson)('/api/cli/identity/alias', {
166
+ profile: args.profile,
167
+ method: 'POST',
168
+ json: {
169
+ siteId: args.site,
170
+ previousUserId: args.previousUserId,
171
+ newUserId: args.newUserId,
172
+ },
173
+ });
174
+ if (args.json) {
175
+ process.stdout.write(JSON.stringify(body, null, 2) + '\n');
176
+ return;
177
+ }
178
+ (0, ui_1.success)(`Aliased ${args.previousUserId} → ${args.newUserId}.`);
179
+ }
180
+ /**
181
+ * `gurulu identity bulk --site=<id> --file=<path> [--format=csv|json]
182
+ * [--resume-from=<offset>]`.
183
+ *
184
+ * Streams a CSV or JSON file to `/api/ingest/v1/identify/bulk` for
185
+ * server-side fan-out. The endpoint chunks records server-side (500 per
186
+ * tx); we only enforce a 10 000-record max here as a friendly preflight.
187
+ *
188
+ * `--resume-from` is forwarded as the `x-resume-from` header so a partial
189
+ * import can pick up where it left off without reuploading the whole
190
+ * file.
191
+ */
192
+ async function bulkCmd(args) {
193
+ if (!args.site || !args.file) {
194
+ (0, ui_1.error)('Usage: gurulu identity bulk --site=<id> --file=<path> [--format=csv|json] [--resume-from=<offset>]');
195
+ process.exit(1);
196
+ }
197
+ const filePath = path.resolve(args.file);
198
+ if (!fs.existsSync(filePath)) {
199
+ (0, ui_1.error)(`File not found: ${filePath}`);
200
+ process.exit(1);
201
+ }
202
+ // Auto-detect format from extension when --format is not supplied.
203
+ let format = (args.format || '').toLowerCase();
204
+ if (!format) {
205
+ const ext = path.extname(filePath).slice(1).toLowerCase();
206
+ format = ext === 'csv' ? 'csv' : 'json';
207
+ }
208
+ if (format !== 'csv' && format !== 'json') {
209
+ (0, ui_1.error)('--format must be csv or json');
210
+ process.exit(1);
211
+ }
212
+ const raw = fs.readFileSync(filePath, 'utf8');
213
+ let body;
214
+ let contentType;
215
+ if (format === 'csv') {
216
+ contentType = 'text/csv';
217
+ body = raw;
218
+ }
219
+ else {
220
+ contentType = 'application/json';
221
+ // Allow files that are either { records: [...] } or a bare array.
222
+ let parsed;
223
+ try {
224
+ parsed = JSON.parse(raw);
225
+ }
226
+ catch (err) {
227
+ (0, ui_1.error)(`JSON file is invalid: ${err.message}`);
228
+ process.exit(1);
229
+ }
230
+ const records = Array.isArray(parsed)
231
+ ? parsed
232
+ : Array.isArray(parsed?.records)
233
+ ? parsed.records
234
+ : null;
235
+ if (!records) {
236
+ (0, ui_1.error)('JSON file must be an array or { records: [...] }');
237
+ process.exit(1);
238
+ }
239
+ body = JSON.stringify({ siteId: args.site, records });
240
+ }
241
+ const headers = { 'content-type': contentType };
242
+ if (args.resumeFrom && args.resumeFrom > 0) {
243
+ headers['x-resume-from'] = String(args.resumeFrom);
244
+ }
245
+ const url = `/api/ingest/v1/identify/bulk?site=${encodeURIComponent(args.site)}`;
246
+ let parsedBody;
247
+ try {
248
+ const res = await (0, api_client_1.cliApi)(url, {
249
+ profile: args.profile,
250
+ method: 'POST',
251
+ headers,
252
+ body,
253
+ });
254
+ const text = await res.text();
255
+ parsedBody = text ? JSON.parse(text) : {};
256
+ if (!res.ok) {
257
+ throw new api_client_1.CliApiError(res.status, parsedBody?.error || 'http_error', parsedBody?.message || `HTTP ${res.status}`, parsedBody);
258
+ }
259
+ }
260
+ catch (err) {
261
+ if (err instanceof api_client_1.CliApiError) {
262
+ (0, ui_1.error)(`Bulk import failed: ${err.code} (${err.message})`);
263
+ process.exit(1);
264
+ }
265
+ throw err;
266
+ }
267
+ if (args.json) {
268
+ process.stdout.write(JSON.stringify(parsedBody, null, 2) + '\n');
269
+ return;
270
+ }
271
+ (0, ui_1.success)(`Bulk identify done. processed=${parsedBody.processed ?? 0} succeeded=${parsedBody.succeeded ?? 0} failed=${parsedBody.failed ?? 0}`);
272
+ if (parsedBody.errors && parsedBody.errors.length > 0) {
273
+ const sample = parsedBody.errors.slice(0, 5);
274
+ (0, ui_1.info)(`First ${sample.length} error(s):`);
275
+ for (const e of sample) {
276
+ process.stdout.write(` [${e.index}] ${e.message}\n`);
277
+ }
278
+ }
279
+ }
280
+ async function mergeCmd(args) {
281
+ if (!args.site || !args.canonicalId || !args.duplicateId) {
282
+ (0, ui_1.error)('Usage: gurulu identity merge --site=<id> --canonical-id=<winner> --duplicate-id=<loser>');
283
+ process.exit(1);
284
+ }
285
+ const body = await (0, api_client_1.cliApiJson)('/api/cli/identity/merge', {
286
+ profile: args.profile,
287
+ method: 'POST',
288
+ json: {
289
+ siteId: args.site,
290
+ canonicalId: args.canonicalId,
291
+ duplicateId: args.duplicateId,
292
+ },
293
+ });
294
+ if (args.json) {
295
+ process.stdout.write(JSON.stringify(body, null, 2) + '\n');
296
+ return;
297
+ }
298
+ (0, ui_1.success)(`Merged ${args.duplicateId} → ${args.canonicalId}.`);
299
+ }
79
300
  async function cdcSourcesCmd(args) {
80
301
  if (args.sub && args.sub !== 'list') {
81
302
  (0, ui_1.error)(`Unknown identity cdc-sources sub: ${args.sub}`);
@@ -22,7 +22,7 @@ async function initCommand(args) {
22
22
  if (!args.framework && !args.noInteractive && framework === 'unknown') {
23
23
  console.log('');
24
24
  (0, ui_1.warn)('Could not auto-detect framework.');
25
- const frameworks = ['nextjs-app', 'nextjs-pages', 'react-vite', 'react-cra', 'vue3', 'nuxt3', 'svelte', 'sveltekit', 'astro', 'express', 'nestjs', 'react-native', 'ios-swift', 'android-kotlin', 'flutter', 'html'];
25
+ const frameworks = ['nextjs-app', 'nextjs-pages', 'react-vite', 'react-cra', 'vue3', 'nuxt3', 'svelte', 'sveltekit', 'astro', 'express', 'fastify', 'hono', 'nestjs', 'react-native', 'ios-swift', 'android-kotlin', 'flutter', 'html'];
26
26
  const idx = await (0, ui_1.promptSelect)(' Select your framework: ', frameworks.map(f => (0, detect_1.getFrameworkDisplayName)(f)));
27
27
  framework = frameworks[idx];
28
28
  (0, ui_1.info)(`Using: ${(0, ui_1.bold)((0, detect_1.getFrameworkDisplayName)(framework))}`);
@@ -46,7 +46,12 @@ export interface InstallArgs {
46
46
  * up with `// TODO: <prop>` placeholders. See Sprint A fix A2.
47
47
  */
48
48
  authToken?: string;
49
+ /** Sprint E1.5 — explicit workspace path inside an npm/pnpm/yarn workspace repo. */
50
+ workspace?: string;
51
+ /** FA-1 P0-2 — override the tracker tag asset URL (self-hosted ingest). */
52
+ scriptSrc?: string;
49
53
  }
54
+ export declare function resolveWorkspaceRoot(repoRoot: string, args: InstallArgs, deps: InstallDeps): Promise<string>;
50
55
  export interface IntentPreSeedResult {
51
56
  ok: boolean;
52
57
  proposalId?: string;
@@ -143,7 +148,7 @@ export interface InstallSummary {
143
148
  framework: string | null;
144
149
  planDiff: string;
145
150
  filesChanged: number;
146
- packageManager: 'pnpm' | 'yarn' | 'npm' | null;
151
+ packageManager: 'pnpm' | 'yarn' | 'npm' | 'bun' | null;
147
152
  packageInstalled: boolean;
148
153
  envKeysWritten: string[];
149
154
  ingestOk: boolean | null;
@@ -151,6 +156,8 @@ export interface InstallSummary {
151
156
  verify: VerifyResult | null;
152
157
  rolledBack: boolean;
153
158
  errors: string[];
159
+ partiallyInstalled?: boolean;
160
+ installedComponents?: string[];
154
161
  intent?: {
155
162
  skipped: boolean;
156
163
  dryRun: boolean;
@@ -184,13 +191,14 @@ export interface InstallSummary {
184
191
  * or as a bundled package; falls back to GURULU_SCRIPTS_DIR env override).
185
192
  */
186
193
  export declare function resolveScriptsDir(startDir?: string): string;
187
- export declare function detectPackageManager(repoRoot: string): 'pnpm' | 'yarn' | 'npm';
188
- export declare function packageInstallArgs(pm: 'pnpm' | 'yarn' | 'npm'): string[];
194
+ export declare function detectPackageManager(repoRoot: string): 'pnpm' | 'yarn' | 'npm' | 'bun';
195
+ export declare function packageInstallArgs(pm: 'pnpm' | 'yarn' | 'npm' | 'bun'): string[];
189
196
  export interface EnvMergeResult {
190
197
  file: string;
191
198
  added: string[];
192
199
  skipped: string[];
193
200
  }
201
+ export declare function parseEnvFile(text: string): Set<string>;
194
202
  export declare function mergeEnvFile(repoRoot: string, framework: string, vars: Record<string, string>): EnvMergeResult;
195
203
  export declare function createDefaultDeps(scriptsDir: string): InstallDeps;
196
204
  export declare function runInstallFlow(args: InstallArgs, deps: InstallDeps, scriptsDir: string): Promise<InstallSummary>;
@@ -212,6 +220,15 @@ export interface AuthenticatedInstallDeps {
212
220
  /** Phase 18.6 — intent analyze + pre-seed integrations. */
213
221
  intent?: IntentProposalDeps;
214
222
  }
223
+ export declare function isTelemetryDisabled(): boolean;
224
+ /**
225
+ * First-run consent prompt. Persists the decision so we never re-ask.
226
+ * No-op when telemetry is already disabled, when a decision is already
227
+ * recorded, or in non-interactive (`--yes` / `--no-interactive`) mode.
228
+ */
229
+ export declare function maybePromptTelemetryConsent(ask: (q: string) => Promise<string>, args?: {
230
+ yes?: boolean;
231
+ }): Promise<void>;
215
232
  export declare function repoHashOf(repoRoot: string, remoteUrl?: string | null): string;
216
233
  export declare function pickSite(sites: AuthenticatedInstallDeps['sites'], target?: string): {
217
234
  id: string;
@@ -237,5 +254,6 @@ export declare function emitInstallTelemetry(deps: AuthenticatedInstallDeps, pay
237
254
  ok: boolean;
238
255
  quotaExceeded: boolean;
239
256
  }>;
257
+ export declare function detectCiEnv(env?: NodeJS.ProcessEnv): boolean;
240
258
  export declare function runAuthenticatedInstallFlow(args: InstallArgs, authDeps: AuthenticatedInstallDeps, installDeps: InstallDeps, scriptsDir: string): Promise<InstallSummary>;
241
259
  export declare function installCommand(args: InstallArgs): Promise<void>;