Skip to content

An AI-powered task-management system you can drop into Cursor, Lovable, Windsurf, Roo, and others.

feat(auth): force org selection in parse-prd and export commands

Eyal Toledanof04a568de0dd
diff --git a/apps/cli/src/commands/export.command.ts b/apps/cli/src/commands/export.command.ts
index 913e5d5c..a096738c 100644
--- a/apps/cli/src/commands/export.command.ts
+++ b/apps/cli/src/commands/export.command.ts
@@ -28,6 +28,7 @@ import { createUrlLink } from '../ui/index.js';
import { ensureAuthenticated } from '../utils/auth-guard.js';
import { selectBriefFromInput } from '../utils/brief-selection.js';
import { displayError } from '../utils/error-handler.js';
+import { ensureOrgSelected } from '../utils/org-selection.js';
import { getProjectRoot } from '../utils/project-root.js';
/**
@@ -100,7 +101,7 @@ export class ExportCommand extends Command {
// Default action
this.action(async (options?: any) => {
- return await this.executeExport(options);
+ await this.executeExport(options);
});
}
@@ -334,6 +335,25 @@ export class ExportCommand extends Command {
return;
}
+ // Force org selection after tag selection
+ // User can choose which org to export to, with current org pre-selected
+ const authManager = (this.taskMasterCore!.auth as any).authManager;
+ if (authManager) {
+ const orgResult = await ensureOrgSelected(authManager, {
+ promptMessage: 'Select an organization to export to:',
+ forcePrompt: true
+ });
+ if (!orgResult.success) {
+ console.log(chalk.gray('\n Export cancelled.\n'));
+ this.lastResult = {
+ success: false,
+ action: 'cancelled',
+ message: orgResult.message || 'Organization selection cancelled'
+ };
+ return;
+ }
+ }
+
// Handle multiple tags export
if (selectedTags.length > 1) {
await this.executeExportMultipleTags(selectedTags, options);
diff --git a/apps/cli/src/utils/org-selection.ts b/apps/cli/src/utils/org-selection.ts
index e0b73f63..fc33c607 100644
--- a/apps/cli/src/utils/org-selection.ts
+++ b/apps/cli/src/utils/org-selection.ts
@@ -27,6 +27,8 @@ export interface EnsureOrgOptions {
silent?: boolean;
/** Custom message to show when prompting */
promptMessage?: string;
+ /** If true, always prompt for org selection even if one is already set */
+ forcePrompt?: boolean;
}
/**
@@ -55,13 +57,13 @@ export async function ensureOrgSelected(
authManager: AuthManager,
options: EnsureOrgOptions = {}
): Promise<OrgSelectionResult> {
- const { silent = false, promptMessage } = options;
+ const { silent = false, promptMessage, forcePrompt = false } = options;
try {
const context = authManager.getContext();
- // If org is already selected, return it
- if (context?.orgId) {
+ // If org is already selected and we're not forcing a prompt, return it
+ if (context?.orgId && !forcePrompt) {
return {
success: true,
orgId: context.orgId,
@@ -70,7 +72,7 @@ export async function ensureOrgSelected(
};
}
- // No org selected - check if we can auto-select
+ // Fetch available orgs
const orgs = await authManager.getOrganizations();
if (orgs.length === 0) {
@@ -104,19 +106,28 @@ export async function ensureOrgSelected(
}
// Multiple orgs - prompt for selection
- if (!silent) {
+ if (!silent && !context?.orgId) {
console.log(chalk.yellow('No organization selected.'));
}
+ // Set default to current org if one is selected
+ const defaultOrg = context?.orgId
+ ? orgs.findIndex((o) => o.id === context.orgId)
+ : 0;
+
const response = await inquirer.prompt<{ orgId: string }>([
{
type: 'list',
name: 'orgId',
message: promptMessage || 'Select an organization:',
choices: orgs.map((org) => ({
- name: org.name,
+ name:
+ org.id === context?.orgId
+ ? `${org.name} (current)`
+ : org.name,
value: org.id
- }))
+ })),
+ default: defaultOrg >= 0 ? defaultOrg : 0
}
]);
diff --git a/scripts/init.js b/scripts/init.js
index d2e5ff21..b0bd3114 100755
--- a/scripts/init.js
+++ b/scripts/init.js
@@ -651,9 +651,6 @@ async function initializeProject(options = {}) {
authCredentials
);
rl.close();
- // Exit cleanly after command completes
- // Required because Supabase client keeps connections alive
- process.exit(0);
} catch (error) {
if (rl) {
rl.close();
diff --git a/scripts/modules/commands.js b/scripts/modules/commands.js
index 00de374e..926c1753 100644
--- a/scripts/modules/commands.js
+++ b/scripts/modules/commands.js
@@ -383,9 +383,12 @@ async function handleParsePrdToHamster(prdPath) {
const authManager = AuthManager.getInstance();
- // Ensure an organization is selected before proceeding
+ // Always prompt for organization selection for parse-prd
+ // This allows users to choose which org to create the brief in
+ // even if they have one already selected in context
const orgResult = await ensureOrgSelected(authManager, {
- promptMessage: 'Select an organization to create the brief in:'
+ promptMessage: 'Select an organization to create the brief in:',
+ forcePrompt: true
});
if (!orgResult.success) {
console.error(