@controlvector/cv-agent 1.10.1 → 1.11.1

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.
package/dist/bundle.cjs CHANGED
@@ -6,9 +6,16 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __esm = (fn, res) => function __init() {
10
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
+ };
9
12
  var __commonJS = (cb, mod) => function __require() {
10
13
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
14
  };
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
12
19
  var __copyProps = (to, from, except, desc) => {
13
20
  if (from && typeof from === "object" || typeof from === "function") {
14
21
  for (let key of __getOwnPropNames(from))
@@ -3019,98 +3026,7 @@ var require_commander = __commonJS({
3019
3026
  }
3020
3027
  });
3021
3028
 
3022
- // node_modules/commander/esm.mjs
3023
- var import_index = __toESM(require_commander(), 1);
3024
- var {
3025
- program,
3026
- createCommand,
3027
- createArgument,
3028
- createOption,
3029
- CommanderError,
3030
- InvalidArgumentError,
3031
- InvalidOptionArgumentError,
3032
- // deprecated old name
3033
- Command,
3034
- Argument,
3035
- Option,
3036
- Help
3037
- } = import_index.default;
3038
-
3039
- // src/commands/setup.ts
3040
- var import_node_child_process = require("node:child_process");
3041
- var import_node_fs = require("node:fs");
3042
- var import_node_path = require("node:path");
3043
- var import_node_os2 = require("node:os");
3044
-
3045
3029
  // node_modules/chalk/source/vendor/ansi-styles/index.js
3046
- var ANSI_BACKGROUND_OFFSET = 10;
3047
- var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
3048
- var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
3049
- var wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
3050
- var styles = {
3051
- modifier: {
3052
- reset: [0, 0],
3053
- // 21 isn't widely supported and 22 does the same thing
3054
- bold: [1, 22],
3055
- dim: [2, 22],
3056
- italic: [3, 23],
3057
- underline: [4, 24],
3058
- overline: [53, 55],
3059
- inverse: [7, 27],
3060
- hidden: [8, 28],
3061
- strikethrough: [9, 29]
3062
- },
3063
- color: {
3064
- black: [30, 39],
3065
- red: [31, 39],
3066
- green: [32, 39],
3067
- yellow: [33, 39],
3068
- blue: [34, 39],
3069
- magenta: [35, 39],
3070
- cyan: [36, 39],
3071
- white: [37, 39],
3072
- // Bright color
3073
- blackBright: [90, 39],
3074
- gray: [90, 39],
3075
- // Alias of `blackBright`
3076
- grey: [90, 39],
3077
- // Alias of `blackBright`
3078
- redBright: [91, 39],
3079
- greenBright: [92, 39],
3080
- yellowBright: [93, 39],
3081
- blueBright: [94, 39],
3082
- magentaBright: [95, 39],
3083
- cyanBright: [96, 39],
3084
- whiteBright: [97, 39]
3085
- },
3086
- bgColor: {
3087
- bgBlack: [40, 49],
3088
- bgRed: [41, 49],
3089
- bgGreen: [42, 49],
3090
- bgYellow: [43, 49],
3091
- bgBlue: [44, 49],
3092
- bgMagenta: [45, 49],
3093
- bgCyan: [46, 49],
3094
- bgWhite: [47, 49],
3095
- // Bright color
3096
- bgBlackBright: [100, 49],
3097
- bgGray: [100, 49],
3098
- // Alias of `bgBlackBright`
3099
- bgGrey: [100, 49],
3100
- // Alias of `bgBlackBright`
3101
- bgRedBright: [101, 49],
3102
- bgGreenBright: [102, 49],
3103
- bgYellowBright: [103, 49],
3104
- bgBlueBright: [104, 49],
3105
- bgMagentaBright: [105, 49],
3106
- bgCyanBright: [106, 49],
3107
- bgWhiteBright: [107, 49]
3108
- }
3109
- };
3110
- var modifierNames = Object.keys(styles.modifier);
3111
- var foregroundColorNames = Object.keys(styles.color);
3112
- var backgroundColorNames = Object.keys(styles.bgColor);
3113
- var colorNames = [...foregroundColorNames, ...backgroundColorNames];
3114
3030
  function assembleStyles() {
3115
3031
  const codes = /* @__PURE__ */ new Map();
3116
3032
  for (const [groupName, group] of Object.entries(styles)) {
@@ -3225,26 +3141,89 @@ function assembleStyles() {
3225
3141
  });
3226
3142
  return styles;
3227
3143
  }
3228
- var ansiStyles = assembleStyles();
3229
- var ansi_styles_default = ansiStyles;
3144
+ var ANSI_BACKGROUND_OFFSET, wrapAnsi16, wrapAnsi256, wrapAnsi16m, styles, modifierNames, foregroundColorNames, backgroundColorNames, colorNames, ansiStyles, ansi_styles_default;
3145
+ var init_ansi_styles = __esm({
3146
+ "node_modules/chalk/source/vendor/ansi-styles/index.js"() {
3147
+ ANSI_BACKGROUND_OFFSET = 10;
3148
+ wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
3149
+ wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`;
3150
+ wrapAnsi16m = (offset = 0) => (red, green, blue) => `\x1B[${38 + offset};2;${red};${green};${blue}m`;
3151
+ styles = {
3152
+ modifier: {
3153
+ reset: [0, 0],
3154
+ // 21 isn't widely supported and 22 does the same thing
3155
+ bold: [1, 22],
3156
+ dim: [2, 22],
3157
+ italic: [3, 23],
3158
+ underline: [4, 24],
3159
+ overline: [53, 55],
3160
+ inverse: [7, 27],
3161
+ hidden: [8, 28],
3162
+ strikethrough: [9, 29]
3163
+ },
3164
+ color: {
3165
+ black: [30, 39],
3166
+ red: [31, 39],
3167
+ green: [32, 39],
3168
+ yellow: [33, 39],
3169
+ blue: [34, 39],
3170
+ magenta: [35, 39],
3171
+ cyan: [36, 39],
3172
+ white: [37, 39],
3173
+ // Bright color
3174
+ blackBright: [90, 39],
3175
+ gray: [90, 39],
3176
+ // Alias of `blackBright`
3177
+ grey: [90, 39],
3178
+ // Alias of `blackBright`
3179
+ redBright: [91, 39],
3180
+ greenBright: [92, 39],
3181
+ yellowBright: [93, 39],
3182
+ blueBright: [94, 39],
3183
+ magentaBright: [95, 39],
3184
+ cyanBright: [96, 39],
3185
+ whiteBright: [97, 39]
3186
+ },
3187
+ bgColor: {
3188
+ bgBlack: [40, 49],
3189
+ bgRed: [41, 49],
3190
+ bgGreen: [42, 49],
3191
+ bgYellow: [43, 49],
3192
+ bgBlue: [44, 49],
3193
+ bgMagenta: [45, 49],
3194
+ bgCyan: [46, 49],
3195
+ bgWhite: [47, 49],
3196
+ // Bright color
3197
+ bgBlackBright: [100, 49],
3198
+ bgGray: [100, 49],
3199
+ // Alias of `bgBlackBright`
3200
+ bgGrey: [100, 49],
3201
+ // Alias of `bgBlackBright`
3202
+ bgRedBright: [101, 49],
3203
+ bgGreenBright: [102, 49],
3204
+ bgYellowBright: [103, 49],
3205
+ bgBlueBright: [104, 49],
3206
+ bgMagentaBright: [105, 49],
3207
+ bgCyanBright: [106, 49],
3208
+ bgWhiteBright: [107, 49]
3209
+ }
3210
+ };
3211
+ modifierNames = Object.keys(styles.modifier);
3212
+ foregroundColorNames = Object.keys(styles.color);
3213
+ backgroundColorNames = Object.keys(styles.bgColor);
3214
+ colorNames = [...foregroundColorNames, ...backgroundColorNames];
3215
+ ansiStyles = assembleStyles();
3216
+ ansi_styles_default = ansiStyles;
3217
+ }
3218
+ });
3230
3219
 
3231
3220
  // node_modules/chalk/source/vendor/supports-color/index.js
3232
- var import_node_process = __toESM(require("node:process"), 1);
3233
- var import_node_os = __toESM(require("node:os"), 1);
3234
- var import_node_tty = __toESM(require("node:tty"), 1);
3235
3221
  function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
3236
3222
  const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
3237
3223
  const position = argv.indexOf(prefix + flag);
3238
3224
  const terminatorPosition = argv.indexOf("--");
3239
3225
  return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
3240
3226
  }
3241
- var { env } = import_node_process.default;
3242
- var flagForceColor;
3243
- if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
3244
- flagForceColor = 0;
3245
- } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
3246
- flagForceColor = 1;
3247
- }
3248
3227
  function envForceColor() {
3249
3228
  if ("FORCE_COLOR" in env) {
3250
3229
  if (env.FORCE_COLOR === "true") {
@@ -3354,11 +3333,25 @@ function createSupportsColor(stream, options = {}) {
3354
3333
  });
3355
3334
  return translateLevel(level);
3356
3335
  }
3357
- var supportsColor = {
3358
- stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }),
3359
- stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) })
3360
- };
3361
- var supports_color_default = supportsColor;
3336
+ var import_node_process, import_node_os, import_node_tty, env, flagForceColor, supportsColor, supports_color_default;
3337
+ var init_supports_color = __esm({
3338
+ "node_modules/chalk/source/vendor/supports-color/index.js"() {
3339
+ import_node_process = __toESM(require("node:process"), 1);
3340
+ import_node_os = __toESM(require("node:os"), 1);
3341
+ import_node_tty = __toESM(require("node:tty"), 1);
3342
+ ({ env } = import_node_process.default);
3343
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
3344
+ flagForceColor = 0;
3345
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
3346
+ flagForceColor = 1;
3347
+ }
3348
+ supportsColor = {
3349
+ stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }),
3350
+ stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) })
3351
+ };
3352
+ supports_color_default = supportsColor;
3353
+ }
3354
+ });
3362
3355
 
3363
3356
  // node_modules/chalk/source/utilities.js
3364
3357
  function stringReplaceAll(string, substring, replacer) {
@@ -3389,153 +3382,389 @@ function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
3389
3382
  returnValue += string.slice(endIndex);
3390
3383
  return returnValue;
3391
3384
  }
3385
+ var init_utilities = __esm({
3386
+ "node_modules/chalk/source/utilities.js"() {
3387
+ }
3388
+ });
3392
3389
 
3393
3390
  // node_modules/chalk/source/index.js
3394
- var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default;
3395
- var GENERATOR = Symbol("GENERATOR");
3396
- var STYLER = Symbol("STYLER");
3397
- var IS_EMPTY = Symbol("IS_EMPTY");
3398
- var levelMapping = [
3399
- "ansi",
3400
- "ansi",
3401
- "ansi256",
3402
- "ansi16m"
3403
- ];
3404
- var styles2 = /* @__PURE__ */ Object.create(null);
3405
- var applyOptions = (object, options = {}) => {
3406
- if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
3407
- throw new Error("The `level` option should be an integer from 0 to 3");
3408
- }
3409
- const colorLevel = stdoutColor ? stdoutColor.level : 0;
3410
- object.level = options.level === void 0 ? colorLevel : options.level;
3411
- };
3412
- var chalkFactory = (options) => {
3413
- const chalk2 = (...strings) => strings.join(" ");
3414
- applyOptions(chalk2, options);
3415
- Object.setPrototypeOf(chalk2, createChalk.prototype);
3416
- return chalk2;
3417
- };
3418
3391
  function createChalk(options) {
3419
3392
  return chalkFactory(options);
3420
3393
  }
3421
- Object.setPrototypeOf(createChalk.prototype, Function.prototype);
3422
- for (const [styleName, style] of Object.entries(ansi_styles_default)) {
3423
- styles2[styleName] = {
3424
- get() {
3425
- const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
3426
- Object.defineProperty(this, styleName, { value: builder });
3427
- return builder;
3394
+ var stdoutColor, stderrColor, GENERATOR, STYLER, IS_EMPTY, levelMapping, styles2, applyOptions, chalkFactory, getModelAnsi, usedModels, proto, createStyler, createBuilder, applyStyle, chalk, chalkStderr, source_default;
3395
+ var init_source = __esm({
3396
+ "node_modules/chalk/source/index.js"() {
3397
+ init_ansi_styles();
3398
+ init_supports_color();
3399
+ init_utilities();
3400
+ ({ stdout: stdoutColor, stderr: stderrColor } = supports_color_default);
3401
+ GENERATOR = Symbol("GENERATOR");
3402
+ STYLER = Symbol("STYLER");
3403
+ IS_EMPTY = Symbol("IS_EMPTY");
3404
+ levelMapping = [
3405
+ "ansi",
3406
+ "ansi",
3407
+ "ansi256",
3408
+ "ansi16m"
3409
+ ];
3410
+ styles2 = /* @__PURE__ */ Object.create(null);
3411
+ applyOptions = (object, options = {}) => {
3412
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
3413
+ throw new Error("The `level` option should be an integer from 0 to 3");
3414
+ }
3415
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
3416
+ object.level = options.level === void 0 ? colorLevel : options.level;
3417
+ };
3418
+ chalkFactory = (options) => {
3419
+ const chalk2 = (...strings) => strings.join(" ");
3420
+ applyOptions(chalk2, options);
3421
+ Object.setPrototypeOf(chalk2, createChalk.prototype);
3422
+ return chalk2;
3423
+ };
3424
+ Object.setPrototypeOf(createChalk.prototype, Function.prototype);
3425
+ for (const [styleName, style] of Object.entries(ansi_styles_default)) {
3426
+ styles2[styleName] = {
3427
+ get() {
3428
+ const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
3429
+ Object.defineProperty(this, styleName, { value: builder });
3430
+ return builder;
3431
+ }
3432
+ };
3428
3433
  }
3429
- };
3430
- }
3431
- styles2.visible = {
3432
- get() {
3433
- const builder = createBuilder(this, this[STYLER], true);
3434
- Object.defineProperty(this, "visible", { value: builder });
3435
- return builder;
3434
+ styles2.visible = {
3435
+ get() {
3436
+ const builder = createBuilder(this, this[STYLER], true);
3437
+ Object.defineProperty(this, "visible", { value: builder });
3438
+ return builder;
3439
+ }
3440
+ };
3441
+ getModelAnsi = (model, level, type, ...arguments_) => {
3442
+ if (model === "rgb") {
3443
+ if (level === "ansi16m") {
3444
+ return ansi_styles_default[type].ansi16m(...arguments_);
3445
+ }
3446
+ if (level === "ansi256") {
3447
+ return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
3448
+ }
3449
+ return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
3450
+ }
3451
+ if (model === "hex") {
3452
+ return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
3453
+ }
3454
+ return ansi_styles_default[type][model](...arguments_);
3455
+ };
3456
+ usedModels = ["rgb", "hex", "ansi256"];
3457
+ for (const model of usedModels) {
3458
+ styles2[model] = {
3459
+ get() {
3460
+ const { level } = this;
3461
+ return function(...arguments_) {
3462
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
3463
+ return createBuilder(this, styler, this[IS_EMPTY]);
3464
+ };
3465
+ }
3466
+ };
3467
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
3468
+ styles2[bgModel] = {
3469
+ get() {
3470
+ const { level } = this;
3471
+ return function(...arguments_) {
3472
+ const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
3473
+ return createBuilder(this, styler, this[IS_EMPTY]);
3474
+ };
3475
+ }
3476
+ };
3477
+ }
3478
+ proto = Object.defineProperties(() => {
3479
+ }, {
3480
+ ...styles2,
3481
+ level: {
3482
+ enumerable: true,
3483
+ get() {
3484
+ return this[GENERATOR].level;
3485
+ },
3486
+ set(level) {
3487
+ this[GENERATOR].level = level;
3488
+ }
3489
+ }
3490
+ });
3491
+ createStyler = (open, close, parent) => {
3492
+ let openAll;
3493
+ let closeAll;
3494
+ if (parent === void 0) {
3495
+ openAll = open;
3496
+ closeAll = close;
3497
+ } else {
3498
+ openAll = parent.openAll + open;
3499
+ closeAll = close + parent.closeAll;
3500
+ }
3501
+ return {
3502
+ open,
3503
+ close,
3504
+ openAll,
3505
+ closeAll,
3506
+ parent
3507
+ };
3508
+ };
3509
+ createBuilder = (self, _styler, _isEmpty) => {
3510
+ const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
3511
+ Object.setPrototypeOf(builder, proto);
3512
+ builder[GENERATOR] = self;
3513
+ builder[STYLER] = _styler;
3514
+ builder[IS_EMPTY] = _isEmpty;
3515
+ return builder;
3516
+ };
3517
+ applyStyle = (self, string) => {
3518
+ if (self.level <= 0 || !string) {
3519
+ return self[IS_EMPTY] ? "" : string;
3520
+ }
3521
+ let styler = self[STYLER];
3522
+ if (styler === void 0) {
3523
+ return string;
3524
+ }
3525
+ const { openAll, closeAll } = styler;
3526
+ if (string.includes("\x1B")) {
3527
+ while (styler !== void 0) {
3528
+ string = stringReplaceAll(string, styler.close, styler.open);
3529
+ styler = styler.parent;
3530
+ }
3531
+ }
3532
+ const lfIndex = string.indexOf("\n");
3533
+ if (lfIndex !== -1) {
3534
+ string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
3535
+ }
3536
+ return openAll + string + closeAll;
3537
+ };
3538
+ Object.defineProperties(createChalk.prototype, styles2);
3539
+ chalk = createChalk();
3540
+ chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
3541
+ source_default = chalk;
3436
3542
  }
3437
- };
3438
- var getModelAnsi = (model, level, type, ...arguments_) => {
3439
- if (model === "rgb") {
3440
- if (level === "ansi16m") {
3441
- return ansi_styles_default[type].ansi16m(...arguments_);
3543
+ });
3544
+
3545
+ // src/utils/org-resolver.ts
3546
+ var org_resolver_exports = {};
3547
+ __export(org_resolver_exports, {
3548
+ confirmAutoMatch: () => confirmAutoMatch,
3549
+ parseMultiOrgError: () => parseMultiOrgError,
3550
+ persistOrg: () => persistOrg,
3551
+ pickOrg: () => pickOrg,
3552
+ promptPersistScope: () => promptPersistScope,
3553
+ resolveOrg: () => resolveOrg,
3554
+ resolveToUUID: () => resolveToUUID
3555
+ });
3556
+ function resolveOrg(opts) {
3557
+ if (opts.cliFlag?.trim()) {
3558
+ return { value: opts.cliFlag.trim(), source: "cli" };
3559
+ }
3560
+ const envVal = process.env.CV_HUB_ORG?.trim();
3561
+ if (envVal) {
3562
+ return { value: envVal, source: "env" };
3563
+ }
3564
+ const cwd = opts.cwd || process.cwd();
3565
+ try {
3566
+ const repoConfigPath = (0, import_node_path2.join)(cwd, ".cva", "agent.json");
3567
+ if ((0, import_node_fs3.existsSync)(repoConfigPath)) {
3568
+ const config = JSON.parse((0, import_node_fs3.readFileSync)(repoConfigPath, "utf-8"));
3569
+ if (config.organization?.trim()) {
3570
+ return { value: config.organization.trim(), source: "repo-config" };
3571
+ }
3442
3572
  }
3443
- if (level === "ansi256") {
3444
- return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_));
3573
+ } catch {
3574
+ }
3575
+ try {
3576
+ const globalConfigPath = (0, import_node_path2.join)((0, import_node_os3.homedir)(), ".config", "cva", "config.json");
3577
+ if ((0, import_node_fs3.existsSync)(globalConfigPath)) {
3578
+ const config = JSON.parse((0, import_node_fs3.readFileSync)(globalConfigPath, "utf-8"));
3579
+ if (config.organization?.trim()) {
3580
+ return { value: config.organization.trim(), source: "global-config" };
3581
+ }
3445
3582
  }
3446
- return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_));
3583
+ } catch {
3447
3584
  }
3448
- if (model === "hex") {
3449
- return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_));
3585
+ return { value: "", source: null };
3586
+ }
3587
+ function resolveToUUID(identifier, orgs) {
3588
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3589
+ if (uuidRegex.test(identifier)) {
3590
+ const match = orgs.find((o) => o.id.toLowerCase() === identifier.toLowerCase());
3591
+ if (match) return match.id;
3592
+ }
3593
+ const slugMatch = orgs.find((o) => o.slug.toLowerCase() === identifier.toLowerCase());
3594
+ if (slugMatch) return slugMatch.id;
3595
+ throw new Error(
3596
+ `Organization "${identifier}" not found. Valid options: ${orgs.map((o) => o.slug).join(", ")}`
3597
+ );
3598
+ }
3599
+ function persistOrg(value, scope, cwd) {
3600
+ let configPath;
3601
+ if (scope === "repo") {
3602
+ const dir = (0, import_node_path2.join)(cwd || process.cwd(), ".cva");
3603
+ (0, import_node_fs3.mkdirSync)(dir, { recursive: true });
3604
+ configPath = (0, import_node_path2.join)(dir, "agent.json");
3605
+ } else {
3606
+ const dir = (0, import_node_path2.join)((0, import_node_os3.homedir)(), ".config", "cva");
3607
+ (0, import_node_fs3.mkdirSync)(dir, { recursive: true });
3608
+ configPath = (0, import_node_path2.join)(dir, "config.json");
3450
3609
  }
3451
- return ansi_styles_default[type][model](...arguments_);
3452
- };
3453
- var usedModels = ["rgb", "hex", "ansi256"];
3454
- for (const model of usedModels) {
3455
- styles2[model] = {
3456
- get() {
3457
- const { level } = this;
3458
- return function(...arguments_) {
3459
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]);
3460
- return createBuilder(this, styler, this[IS_EMPTY]);
3461
- };
3462
- }
3463
- };
3464
- const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
3465
- styles2[bgModel] = {
3466
- get() {
3467
- const { level } = this;
3468
- return function(...arguments_) {
3469
- const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]);
3470
- return createBuilder(this, styler, this[IS_EMPTY]);
3471
- };
3610
+ let existing = {};
3611
+ try {
3612
+ if ((0, import_node_fs3.existsSync)(configPath)) {
3613
+ existing = JSON.parse((0, import_node_fs3.readFileSync)(configPath, "utf-8"));
3472
3614
  }
3473
- };
3615
+ } catch {
3616
+ }
3617
+ existing.organization = value;
3618
+ const tmpPath = configPath + ".tmp";
3619
+ (0, import_node_fs3.writeFileSync)(tmpPath, JSON.stringify(existing, null, 2) + "\n", {
3620
+ mode: scope === "global" ? 384 : 420
3621
+ });
3622
+ (0, import_node_fs3.renameSync)(tmpPath, configPath);
3623
+ return configPath;
3474
3624
  }
3475
- var proto = Object.defineProperties(() => {
3476
- }, {
3477
- ...styles2,
3478
- level: {
3479
- enumerable: true,
3480
- get() {
3481
- return this[GENERATOR].level;
3482
- },
3483
- set(level) {
3484
- this[GENERATOR].level = level;
3625
+ async function promptPersistScope() {
3626
+ const readline = await import("node:readline");
3627
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
3628
+ console.log();
3629
+ console.log(source_default.gray(" Save this choice for next time?"));
3630
+ console.log(` ${source_default.cyan("r")}. Save to this repo's .cva/agent.json ${source_default.gray("(recommended)")}`);
3631
+ console.log(` ${source_default.cyan("g")}. Save globally to ~/.config/cva/config.json`);
3632
+ console.log(` ${source_default.cyan("n")}. Don't save \u2014 prompt again next time`);
3633
+ console.log();
3634
+ const input = await new Promise((resolve2) => {
3635
+ rl.question(" Choice [r/g/n] (default: r): ", (answer) => {
3636
+ rl.close();
3637
+ resolve2(answer.trim().toLowerCase() || "r");
3638
+ });
3639
+ });
3640
+ return input === "g" ? "global" : input === "n" ? "none" : "repo";
3641
+ }
3642
+ async function confirmAutoMatch(match, sourceSlug) {
3643
+ const readline = await import("node:readline");
3644
+ console.log();
3645
+ console.log(` Auto-matched organization: ${source_default.bold(match.name)} (${match.slug})`);
3646
+ console.log(source_default.gray(` from repo owner: ${sourceSlug}`));
3647
+ console.log();
3648
+ console.log(` Register executor under ${match.name}?`);
3649
+ console.log(` ${source_default.cyan("Y")} \u2014 yes, use ${match.name}`);
3650
+ console.log(` ${source_default.cyan("n")} \u2014 no, abort`);
3651
+ console.log(` ${source_default.cyan("p")} \u2014 show the full org list and pick manually`);
3652
+ console.log();
3653
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
3654
+ let attempts = 0;
3655
+ while (attempts < 2) {
3656
+ const input = await new Promise((resolve2) => {
3657
+ rl.question(" Choice [Y/n/p] (default: Y): ", (answer) => {
3658
+ resolve2(answer.trim().toLowerCase() || "y");
3659
+ });
3660
+ });
3661
+ if (input === "y" || input === "yes") {
3662
+ rl.close();
3663
+ return "accept";
3664
+ }
3665
+ if (input === "n" || input === "no") {
3666
+ rl.close();
3667
+ return "abort";
3668
+ }
3669
+ if (input === "p" || input === "pick") {
3670
+ rl.close();
3671
+ return "pick";
3672
+ }
3673
+ attempts++;
3674
+ if (attempts < 2) {
3675
+ console.log(source_default.yellow(" Invalid input. Enter Y, n, or p."));
3485
3676
  }
3486
3677
  }
3487
- });
3488
- var createStyler = (open, close, parent) => {
3489
- let openAll;
3490
- let closeAll;
3491
- if (parent === void 0) {
3492
- openAll = open;
3493
- closeAll = close;
3494
- } else {
3495
- openAll = parent.openAll + open;
3496
- closeAll = close + parent.closeAll;
3678
+ rl.close();
3679
+ return "abort";
3680
+ }
3681
+ async function pickOrg(orgs, opts) {
3682
+ if (!opts.interactive || !process.stdout.isTTY) {
3683
+ throw new Error(
3684
+ `CV-Hub requires organization selection. Set CV_HUB_ORG or pass --org. Valid slugs: ${orgs.map((o) => o.slug).join(", ")}`
3685
+ );
3497
3686
  }
3498
- return {
3499
- open,
3500
- close,
3501
- openAll,
3502
- closeAll,
3503
- parent
3504
- };
3505
- };
3506
- var createBuilder = (self, _styler, _isEmpty) => {
3507
- const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
3508
- Object.setPrototypeOf(builder, proto);
3509
- builder[GENERATOR] = self;
3510
- builder[STYLER] = _styler;
3511
- builder[IS_EMPTY] = _isEmpty;
3512
- return builder;
3513
- };
3514
- var applyStyle = (self, string) => {
3515
- if (self.level <= 0 || !string) {
3516
- return self[IS_EMPTY] ? "" : string;
3687
+ const readline = await import("node:readline");
3688
+ console.log();
3689
+ console.log(source_default.bold(" CV-Hub requires organization selection."));
3690
+ console.log(source_default.gray(" Which organization should this executor register under?"));
3691
+ console.log();
3692
+ orgs.forEach((o, i) => {
3693
+ console.log(` ${source_default.cyan(String(i + 1))}. ${o.name.padEnd(20)} (${source_default.gray(o.slug)})`);
3694
+ });
3695
+ console.log(` ${source_default.cyan("c")}. Cancel`);
3696
+ console.log();
3697
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
3698
+ const input = await new Promise((resolve2) => {
3699
+ rl.question(" Enter number, slug, or 'c': ", (answer) => {
3700
+ rl.close();
3701
+ resolve2(answer.trim());
3702
+ });
3703
+ });
3704
+ if (input.toLowerCase() === "c" || !input) {
3705
+ throw new Error("Registration aborted. Set CV_HUB_ORG or use --org to skip this prompt.");
3517
3706
  }
3518
- let styler = self[STYLER];
3519
- if (styler === void 0) {
3520
- return string;
3707
+ let chosen;
3708
+ const num = parseInt(input, 10);
3709
+ if (!isNaN(num) && num >= 1 && num <= orgs.length) {
3710
+ chosen = orgs[num - 1];
3711
+ } else {
3712
+ chosen = orgs.find((o) => o.slug.toLowerCase() === input.toLowerCase());
3713
+ }
3714
+ if (!chosen) {
3715
+ throw new Error(`"${input}" doesn't match any organization. Valid: ${orgs.map((o) => o.slug).join(", ")}`);
3521
3716
  }
3522
- const { openAll, closeAll } = styler;
3523
- if (string.includes("\x1B")) {
3524
- while (styler !== void 0) {
3525
- string = stringReplaceAll(string, styler.close, styler.open);
3526
- styler = styler.parent;
3717
+ console.log();
3718
+ console.log(` ${source_default.green("\u2713")} ${chosen.name} (${chosen.slug})`);
3719
+ const persistScope = await promptPersistScope();
3720
+ return { chosen, persistScope };
3721
+ }
3722
+ function parseMultiOrgError(status, body) {
3723
+ if (status !== 400) return null;
3724
+ try {
3725
+ const data = JSON.parse(body);
3726
+ const orgs = data?.error?.organizations;
3727
+ if (Array.isArray(orgs) && orgs.length > 0 && orgs[0]?.id && orgs[0]?.slug) {
3728
+ return orgs;
3527
3729
  }
3730
+ } catch {
3528
3731
  }
3529
- const lfIndex = string.indexOf("\n");
3530
- if (lfIndex !== -1) {
3531
- string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
3732
+ return null;
3733
+ }
3734
+ var import_node_fs3, import_node_path2, import_node_os3;
3735
+ var init_org_resolver = __esm({
3736
+ "src/utils/org-resolver.ts"() {
3737
+ "use strict";
3738
+ import_node_fs3 = require("node:fs");
3739
+ import_node_path2 = require("node:path");
3740
+ import_node_os3 = require("node:os");
3741
+ init_source();
3532
3742
  }
3533
- return openAll + string + closeAll;
3534
- };
3535
- Object.defineProperties(createChalk.prototype, styles2);
3536
- var chalk = createChalk();
3537
- var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
3538
- var source_default = chalk;
3743
+ });
3744
+
3745
+ // node_modules/commander/esm.mjs
3746
+ var import_index = __toESM(require_commander(), 1);
3747
+ var {
3748
+ program,
3749
+ createCommand,
3750
+ createArgument,
3751
+ createOption,
3752
+ CommanderError,
3753
+ InvalidArgumentError,
3754
+ InvalidOptionArgumentError,
3755
+ // deprecated old name
3756
+ Command,
3757
+ Argument,
3758
+ Option,
3759
+ Help
3760
+ } = import_index.default;
3761
+
3762
+ // src/commands/setup.ts
3763
+ var import_node_child_process = require("node:child_process");
3764
+ var import_node_fs = require("node:fs");
3765
+ var import_node_path = require("node:path");
3766
+ var import_node_os2 = require("node:os");
3767
+ init_source();
3539
3768
 
3540
3769
  // src/utils/credentials.ts
3541
3770
  var import_fs = require("fs");
@@ -4119,6 +4348,7 @@ function setupCommand() {
4119
4348
  var import_node_child_process5 = require("node:child_process");
4120
4349
  var os3 = __toESM(require("node:os"));
4121
4350
  var path2 = __toESM(require("node:path"));
4351
+ init_source();
4122
4352
 
4123
4353
  // src/utils/event-queue.ts
4124
4354
  var import_node_fs2 = require("node:fs");
@@ -4247,6 +4477,7 @@ function sleep(ms) {
4247
4477
  }
4248
4478
 
4249
4479
  // src/utils/api.ts
4480
+ init_source();
4250
4481
  async function apiCall(creds, method, path3, body) {
4251
4482
  const url = `${creds.CV_HUB_API}${path3}`;
4252
4483
  const headers = {
@@ -4259,7 +4490,16 @@ async function apiCall(creds, method, path3, body) {
4259
4490
  body: body ? JSON.stringify(body) : void 0
4260
4491
  });
4261
4492
  }
4262
- async function registerExecutor(creds, machineName, workingDir, repositoryId, metadata, repoOwnerSlug) {
4493
+ async function registerExecutor(creds, machineName, workingDir, repositoryId, metadata, orgOptions) {
4494
+ const {
4495
+ resolveOrg: resolveOrg2,
4496
+ resolveToUUID: resolveToUUID2,
4497
+ pickOrg: pickOrg2,
4498
+ confirmAutoMatch: confirmAutoMatch2,
4499
+ promptPersistScope: promptPersistScope2,
4500
+ persistOrg: persistOrg2,
4501
+ parseMultiOrgError: parseMultiOrgError2
4502
+ } = await Promise.resolve().then(() => (init_org_resolver(), org_resolver_exports));
4263
4503
  const body = {
4264
4504
  name: `cva:${machineName}`,
4265
4505
  machine_name: machineName,
@@ -4278,21 +4518,68 @@ async function registerExecutor(creds, machineName, workingDir, repositoryId, me
4278
4518
  if (metadata?.tags) body.tags = metadata.tags;
4279
4519
  if (metadata?.owner_project) body.owner_project = metadata.owner_project;
4280
4520
  if (metadata?.integration) body.integration = metadata.integration;
4521
+ const resolved = resolveOrg2({
4522
+ cliFlag: orgOptions?.cliFlag,
4523
+ cwd: orgOptions?.cwd || workingDir
4524
+ });
4281
4525
  let res = await apiCall(creds, "POST", "/api/v1/executors", body);
4282
- if (res.status === 400 && repoOwnerSlug) {
4283
- try {
4284
- const errData = await res.json();
4285
- const orgs = errData.error?.organizations;
4286
- if (orgs && orgs.length > 0) {
4526
+ if (res.status === 400) {
4527
+ const errBody = await res.text();
4528
+ const orgs = parseMultiOrgError2(res.status, errBody);
4529
+ if (orgs) {
4530
+ if (resolved.value) {
4531
+ try {
4532
+ const orgId = resolveToUUID2(resolved.value, orgs);
4533
+ body.organization_id = orgId;
4534
+ res = await apiCall(creds, "POST", "/api/v1/executors", body);
4535
+ } catch (e) {
4536
+ throw new Error(
4537
+ `Organization "${resolved.value}" (from ${resolved.source}) is invalid. ${e.message}`
4538
+ );
4539
+ }
4540
+ }
4541
+ let autoMatchHandled = false;
4542
+ if (!resolved.value && orgOptions?.repoOwnerSlug) {
4287
4543
  const match = orgs.find(
4288
- (o) => o.slug.toLowerCase() === repoOwnerSlug.toLowerCase()
4544
+ (o) => o.slug.toLowerCase() === orgOptions.repoOwnerSlug.toLowerCase()
4289
4545
  );
4290
4546
  if (match) {
4291
- body.organization_id = match.id;
4292
- res = await apiCall(creds, "POST", "/api/v1/executors", body);
4547
+ if (!process.stdout.isTTY) {
4548
+ throw new Error(
4549
+ `Auto-matched "${match.slug}" from repo owner, but running non-interactively. Set CV_HUB_ORG=${match.slug} or pass --org ${match.slug} to confirm, or pick a different org from: ${orgs.map((o) => o.slug).join(", ")}.`
4550
+ );
4551
+ }
4552
+ const decision = await confirmAutoMatch2(match, orgOptions.repoOwnerSlug);
4553
+ if (decision === "accept") {
4554
+ const scope = await promptPersistScope2();
4555
+ if (scope !== "none") {
4556
+ const savedPath = persistOrg2(match.slug, scope, orgOptions?.cwd || workingDir);
4557
+ console.log(source_default.gray(` Saved to ${savedPath}`));
4558
+ }
4559
+ body.organization_id = match.id;
4560
+ res = await apiCall(creds, "POST", "/api/v1/executors", body);
4561
+ autoMatchHandled = true;
4562
+ } else if (decision === "abort") {
4563
+ throw new Error(
4564
+ "Registration aborted. Set CV_HUB_ORG or use --org to choose an org non-interactively."
4565
+ );
4566
+ }
4293
4567
  }
4294
4568
  }
4295
- } catch {
4569
+ if (!autoMatchHandled && !res.ok) {
4570
+ const picked = await pickOrg2(orgs, {
4571
+ interactive: true,
4572
+ cwd: orgOptions?.cwd || workingDir
4573
+ });
4574
+ if (picked.persistScope !== "none") {
4575
+ const savedPath = persistOrg2(picked.chosen.slug, picked.persistScope, orgOptions?.cwd || workingDir);
4576
+ console.log(source_default.gray(` Saved to ${savedPath}`));
4577
+ }
4578
+ body.organization_id = picked.chosen.id;
4579
+ res = await apiCall(creds, "POST", "/api/v1/executors", body);
4580
+ }
4581
+ } else {
4582
+ throw new Error(`Failed to register executor: ${res.status} ${errBody}`);
4296
4583
  }
4297
4584
  }
4298
4585
  if (!res.ok) {
@@ -4654,6 +4941,7 @@ function verifyGitRemote(cwd, task, gitHost) {
4654
4941
  }
4655
4942
 
4656
4943
  // src/utils/display.ts
4944
+ init_source();
4657
4945
  function formatDuration(ms) {
4658
4946
  const s = Math.floor(ms / 1e3);
4659
4947
  if (s < 60) return `${s}s`;
@@ -4690,6 +4978,7 @@ function updateStatusLine(idle, poll, completedCount, failedCount) {
4690
4978
  }
4691
4979
 
4692
4980
  // src/utils/retry.ts
4981
+ init_source();
4693
4982
  async function withRetry(fn, label, maxRetries = 3) {
4694
4983
  for (let i = 0; i < maxRetries; i++) {
4695
4984
  try {
@@ -4737,9 +5026,9 @@ async function writeConfig(config) {
4737
5026
 
4738
5027
  // src/commands/git-safety.ts
4739
5028
  var import_node_child_process3 = require("node:child_process");
4740
- var import_node_fs3 = require("node:fs");
4741
- var import_node_path2 = require("node:path");
4742
- var import_node_os3 = require("node:os");
5029
+ var import_node_fs4 = require("node:fs");
5030
+ var import_node_path3 = require("node:path");
5031
+ var import_node_os4 = require("node:os");
4743
5032
  var DANGEROUS_PATTERNS = [
4744
5033
  ".claude/",
4745
5034
  ".claude.json",
@@ -4765,15 +5054,15 @@ function git(cmd, cwd) {
4765
5054
  return (0, import_node_child_process3.execSync)(cmd, { cwd, encoding: "utf8", timeout: 3e4 }).trim();
4766
5055
  }
4767
5056
  function checkWorkspaceSafety(workspaceRoot) {
4768
- const resolved = (0, import_node_path2.resolve)(workspaceRoot);
4769
- const home = (0, import_node_path2.resolve)((0, import_node_os3.homedir)());
5057
+ const resolved = (0, import_node_path3.resolve)(workspaceRoot);
5058
+ const home = (0, import_node_path3.resolve)((0, import_node_os4.homedir)());
4770
5059
  if (resolved === home) {
4771
5060
  return `Workspace is user HOME directory (${home}). Refusing to auto-commit to prevent indexing personal files.`;
4772
5061
  }
4773
5062
  if (home.startsWith(resolved + "/")) {
4774
5063
  return `Workspace (${resolved}) is a parent of HOME. Refusing to auto-commit.`;
4775
5064
  }
4776
- if (!(0, import_node_fs3.existsSync)((0, import_node_path2.join)(resolved, ".git"))) {
5065
+ if (!(0, import_node_fs4.existsSync)((0, import_node_path3.join)(resolved, ".git"))) {
4777
5066
  return `No .git directory in ${resolved}. Not a git repository.`;
4778
5067
  }
4779
5068
  return null;
@@ -4915,8 +5204,8 @@ Files: ${added} added, ${modified} modified, ${deleted} deleted`;
4915
5204
 
4916
5205
  // src/commands/deploy-manifest.ts
4917
5206
  var import_node_child_process4 = require("node:child_process");
4918
- var import_node_fs4 = require("node:fs");
4919
- var import_node_path3 = require("node:path");
5207
+ var import_node_fs5 = require("node:fs");
5208
+ var import_node_path4 = require("node:path");
4920
5209
  function exec(cmd, cwd, timeoutMs = 3e5, env2) {
4921
5210
  try {
4922
5211
  const stdout = (0, import_node_child_process4.execSync)(cmd, {
@@ -4959,10 +5248,10 @@ function getHeadCommit(cwd) {
4959
5248
  }
4960
5249
  }
4961
5250
  function loadDeployManifest(workspaceRoot) {
4962
- const manifestPath = (0, import_node_path3.join)(workspaceRoot, ".cva", "deploy.json");
4963
- if (!(0, import_node_fs4.existsSync)(manifestPath)) return null;
5251
+ const manifestPath = (0, import_node_path4.join)(workspaceRoot, ".cva", "deploy.json");
5252
+ if (!(0, import_node_fs5.existsSync)(manifestPath)) return null;
4964
5253
  try {
4965
- const raw = (0, import_node_fs4.readFileSync)(manifestPath, "utf8");
5254
+ const raw = (0, import_node_fs5.readFileSync)(manifestPath, "utf8");
4966
5255
  const manifest = JSON.parse(raw);
4967
5256
  if (!manifest.version || manifest.version < 1) {
4968
5257
  console.log(" [deploy] Invalid manifest version");
@@ -4987,7 +5276,7 @@ async function postTaskDeploy(workspaceRoot, taskId, log) {
4987
5276
  console.log(` [deploy] Building: ${buildStep.name}`);
4988
5277
  log("lifecycle", `Building: ${buildStep.name}`);
4989
5278
  const start = Date.now();
4990
- const cwd = (0, import_node_path3.join)(workspaceRoot, buildStep.working_dir || ".");
5279
+ const cwd = (0, import_node_path4.join)(workspaceRoot, buildStep.working_dir || ".");
4991
5280
  const timeoutMs = (buildStep.timeout_seconds || 300) * 1e3;
4992
5281
  const result = exec(buildStep.command, cwd, timeoutMs);
4993
5282
  if (!result.ok) {
@@ -5078,7 +5367,7 @@ async function rollback(workspaceRoot, targetCommit, manifest, log) {
5078
5367
  }
5079
5368
  if (manifest.build?.steps) {
5080
5369
  for (const step of manifest.build.steps) {
5081
- exec(step.command, (0, import_node_path3.join)(workspaceRoot, step.working_dir || "."), (step.timeout_seconds || 300) * 1e3);
5370
+ exec(step.command, (0, import_node_path4.join)(workspaceRoot, step.working_dir || "."), (step.timeout_seconds || 300) * 1e3);
5082
5371
  }
5083
5372
  }
5084
5373
  if (manifest.service?.restart_command) {
@@ -6009,7 +6298,11 @@ async function runAgent(options) {
6009
6298
  console.log(source_default.yellow(` Guard: ${guardIcon} ${dispatchGuard}`));
6010
6299
  }
6011
6300
  const executor = await withRetry(
6012
- () => registerExecutor(creds, machineName, workingDir, detectedRepoId, executorMeta, detectedOwnerSlug),
6301
+ () => registerExecutor(creds, machineName, workingDir, detectedRepoId, executorMeta, {
6302
+ cliFlag: options.org,
6303
+ repoOwnerSlug: detectedOwnerSlug,
6304
+ cwd: workingDir
6305
+ }),
6013
6306
  "Executor registration"
6014
6307
  );
6015
6308
  const mode = options.autoApprove ? "auto-approve" : "relay";
@@ -6385,6 +6678,7 @@ function agentCommand() {
6385
6678
  }
6386
6679
 
6387
6680
  // src/commands/auth.ts
6681
+ init_source();
6388
6682
  async function authLogin(opts) {
6389
6683
  const token = opts.token || await promptForToken();
6390
6684
  const apiUrl = opts.apiUrl || "https://api.hub.controlvector.io";
@@ -6486,6 +6780,7 @@ function authCommand() {
6486
6780
 
6487
6781
  // src/commands/remote.ts
6488
6782
  var import_node_child_process6 = require("node:child_process");
6783
+ init_source();
6489
6784
  function getGitHost(apiUrl) {
6490
6785
  return apiUrl.replace(/^https?:\/\//, "").replace(/^api\./, "git.");
6491
6786
  }
@@ -6554,6 +6849,7 @@ function remoteCommand() {
6554
6849
  }
6555
6850
 
6556
6851
  // src/commands/task.ts
6852
+ init_source();
6557
6853
  async function taskList(opts) {
6558
6854
  const creds = await readCredentials();
6559
6855
  if (!creds.CV_HUB_PAT) {
@@ -6645,6 +6941,7 @@ function taskCommand() {
6645
6941
  }
6646
6942
 
6647
6943
  // src/commands/status.ts
6944
+ init_source();
6648
6945
  async function showStatus() {
6649
6946
  const creds = await readCredentials();
6650
6947
  if (!creds.CV_HUB_PAT) {
@@ -6699,14 +6996,66 @@ function statusCommand() {
6699
6996
  return cmd;
6700
6997
  }
6701
6998
 
6999
+ // src/commands/orgs.ts
7000
+ init_source();
7001
+ async function listOrgs() {
7002
+ const creds = await readCredentials();
7003
+ if (!creds.CV_HUB_PAT) {
7004
+ console.log(source_default.red("Not authenticated.") + ` Run ${source_default.cyan("cva auth login")} first.`);
7005
+ process.exit(1);
7006
+ }
7007
+ if (!creds.CV_HUB_API) {
7008
+ creds.CV_HUB_API = "https://api.hub.controlvector.io";
7009
+ }
7010
+ try {
7011
+ const res = await apiCall(creds, "GET", "/api/v1/orgs/my/list");
7012
+ if (!res.ok) {
7013
+ console.log(source_default.red(`Error: ${res.status}`));
7014
+ process.exit(1);
7015
+ }
7016
+ const data = await res.json();
7017
+ const orgs = data.organizations || [];
7018
+ if (orgs.length === 0) {
7019
+ console.log(source_default.gray("You are not a member of any organizations."));
7020
+ return;
7021
+ }
7022
+ console.log();
7023
+ console.log(source_default.bold(` Your Organizations (${orgs.length})`));
7024
+ console.log();
7025
+ console.log(
7026
+ source_default.gray(" ") + "Slug".padEnd(24) + "Name".padEnd(24) + "ID"
7027
+ );
7028
+ console.log(source_default.gray(" " + "\u2500".repeat(72)));
7029
+ for (const org of orgs) {
7030
+ console.log(
7031
+ " " + source_default.cyan(org.slug.padEnd(24)) + org.name.padEnd(24) + source_default.gray(org.id)
7032
+ );
7033
+ }
7034
+ console.log();
7035
+ console.log(source_default.gray(" Use with: cva agent --org <slug>"));
7036
+ console.log(source_default.gray(" Or set: CV_HUB_ORG=<slug>"));
7037
+ console.log();
7038
+ } catch (err) {
7039
+ console.log(source_default.red(`Error: ${err.message}`));
7040
+ process.exit(1);
7041
+ }
7042
+ }
7043
+ function orgsCommand() {
7044
+ const cmd = new Command("orgs");
7045
+ cmd.description("Manage organizations");
7046
+ cmd.command("list").description("List organizations your account belongs to").action(listOrgs);
7047
+ return cmd;
7048
+ }
7049
+
6702
7050
  // src/index.ts
6703
7051
  var program2 = new Command();
6704
- program2.name("cva").description('CV-Hub Agent \u2014 bridges Claude Code with CV-Hub task dispatch.\n\nRun "cva setup" to get started.').version(true ? "1.10.1" : "1.6.0");
7052
+ program2.name("cva").description('CV-Hub Agent \u2014 bridges Claude Code with CV-Hub task dispatch.\n\nRun "cva setup" to get started.').version(true ? "1.11.1" : "1.6.0");
6705
7053
  program2.addCommand(setupCommand());
6706
7054
  program2.addCommand(agentCommand());
6707
7055
  program2.addCommand(authCommand());
6708
7056
  program2.addCommand(remoteCommand());
6709
7057
  program2.addCommand(taskCommand());
6710
7058
  program2.addCommand(statusCommand());
7059
+ program2.addCommand(orgsCommand());
6711
7060
  program2.parse(process.argv);
6712
7061
  //# sourceMappingURL=bundle.cjs.map