@autohq/cli 0.1.108 → 0.1.110
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/agent-bridge.js +1 -1
- package/dist/index.js +54 -82
- package/package.json +1 -1
package/dist/agent-bridge.js
CHANGED
|
@@ -26206,7 +26206,7 @@ Object.assign(lookup, {
|
|
|
26206
26206
|
// package.json
|
|
26207
26207
|
var package_default = {
|
|
26208
26208
|
name: "@autohq/cli",
|
|
26209
|
-
version: "0.1.
|
|
26209
|
+
version: "0.1.110",
|
|
26210
26210
|
license: "SEE LICENSE IN README.md",
|
|
26211
26211
|
publishConfig: {
|
|
26212
26212
|
access: "public"
|
package/dist/index.js
CHANGED
|
@@ -18512,7 +18512,7 @@ var init_package = __esm({
|
|
|
18512
18512
|
"package.json"() {
|
|
18513
18513
|
package_default = {
|
|
18514
18514
|
name: "@autohq/cli",
|
|
18515
|
-
version: "0.1.
|
|
18515
|
+
version: "0.1.110",
|
|
18516
18516
|
license: "SEE LICENSE IN README.md",
|
|
18517
18517
|
publishConfig: {
|
|
18518
18518
|
access: "public"
|
|
@@ -18654,40 +18654,24 @@ var init_path = __esm({
|
|
|
18654
18654
|
import { chmodSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
18655
18655
|
import { dirname as dirname3 } from "path";
|
|
18656
18656
|
function readConfig(path2 = defaultConfigPath()) {
|
|
18657
|
-
const
|
|
18658
|
-
|
|
18659
|
-
return readRawConfigFile(profileFilePath(path2, raw.currentProfile)).config;
|
|
18657
|
+
const profilePath = activeProfilePath(path2);
|
|
18658
|
+
return profilePath ? readProfileFile(profilePath) : {};
|
|
18660
18659
|
}
|
|
18661
18660
|
function currentProfileName(path2 = defaultConfigPath()) {
|
|
18662
18661
|
if (isProfilePath(path2)) return profileNameFromPath(path2);
|
|
18663
|
-
return
|
|
18662
|
+
return readPointerFile(path2);
|
|
18664
18663
|
}
|
|
18665
18664
|
function writeConfig(config2, path2 = defaultConfigPath()) {
|
|
18666
|
-
|
|
18667
|
-
|
|
18668
|
-
|
|
18665
|
+
const profilePath = activeProfilePath(path2);
|
|
18666
|
+
if (!profilePath) {
|
|
18667
|
+
throw new Error("Not logged in. Run `auto auth login` first.");
|
|
18669
18668
|
}
|
|
18670
|
-
|
|
18671
|
-
if (raw.currentProfile) {
|
|
18672
|
-
const targetPath = profileFilePath(path2, raw.currentProfile);
|
|
18673
|
-
const target = readRawConfigFile(targetPath).config;
|
|
18674
|
-
if (hasAccountIdentity(config2) && !sameAccount(config2, target)) {
|
|
18675
|
-
setCurrentProfile(saveProfile({ config: config2, configPath: path2 }), path2);
|
|
18676
|
-
return;
|
|
18677
|
-
}
|
|
18678
|
-
writeConfigFile(config2, targetPath);
|
|
18679
|
-
return;
|
|
18680
|
-
}
|
|
18681
|
-
if (hasAccountIdentity(config2)) {
|
|
18682
|
-
setCurrentProfile(saveProfile({ config: config2, configPath: path2 }), path2);
|
|
18683
|
-
return;
|
|
18684
|
-
}
|
|
18685
|
-
writeConfigFile(config2, path2);
|
|
18669
|
+
writeProfileFile(config2, profilePath);
|
|
18686
18670
|
}
|
|
18687
18671
|
function saveProfile(input) {
|
|
18688
18672
|
const configPath = input.configPath ?? defaultConfigPath();
|
|
18689
18673
|
const name = resolveProfileName(input);
|
|
18690
|
-
|
|
18674
|
+
writeProfileFile(input.config, profileFilePath(configPath, name));
|
|
18691
18675
|
return name;
|
|
18692
18676
|
}
|
|
18693
18677
|
function setCurrentProfile(name, path2 = defaultConfigPath()) {
|
|
@@ -18707,6 +18691,11 @@ function clearCurrentProfile(path2 = defaultConfigPath()) {
|
|
|
18707
18691
|
}
|
|
18708
18692
|
writeFile2("", path2);
|
|
18709
18693
|
}
|
|
18694
|
+
function activeProfilePath(path2) {
|
|
18695
|
+
if (isProfilePath(path2)) return path2;
|
|
18696
|
+
const currentProfile = readPointerFile(path2);
|
|
18697
|
+
return currentProfile ? profileFilePath(path2, currentProfile) : void 0;
|
|
18698
|
+
}
|
|
18710
18699
|
function resolveProfileName(input) {
|
|
18711
18700
|
if (input.name !== void 0) return assertValidProfileName(input.name);
|
|
18712
18701
|
if (!input.config.userEmail || !input.config.serverUrl) {
|
|
@@ -18719,39 +18708,31 @@ function resolveProfileName(input) {
|
|
|
18719
18708
|
serverUrl: input.config.serverUrl
|
|
18720
18709
|
});
|
|
18721
18710
|
}
|
|
18722
|
-
function
|
|
18723
|
-
|
|
18711
|
+
function readPointerFile(path2) {
|
|
18712
|
+
for (const [key, value] of readKeyValueLines(path2)) {
|
|
18713
|
+
if (key === CURRENT_PROFILE_KEY) return value || void 0;
|
|
18714
|
+
}
|
|
18715
|
+
return void 0;
|
|
18724
18716
|
}
|
|
18725
|
-
function
|
|
18726
|
-
|
|
18727
|
-
|
|
18728
|
-
|
|
18729
|
-
|
|
18717
|
+
function readProfileFile(path2) {
|
|
18718
|
+
const config2 = {};
|
|
18719
|
+
for (const [key, value] of readKeyValueLines(path2)) {
|
|
18720
|
+
const known = CONFIG_KEYS.find((candidate) => candidate === key);
|
|
18721
|
+
if (known) config2[known] = value;
|
|
18722
|
+
}
|
|
18723
|
+
return config2;
|
|
18730
18724
|
}
|
|
18731
|
-
function
|
|
18725
|
+
function readKeyValueLines(path2) {
|
|
18726
|
+
let text;
|
|
18732
18727
|
try {
|
|
18733
|
-
|
|
18734
|
-
const config2 = {};
|
|
18735
|
-
let currentProfile;
|
|
18736
|
-
for (const line of text.split(/\r?\n/)) {
|
|
18737
|
-
const match = /^([A-Za-z0-9_]+):\s*(.*)$/.exec(line.trim());
|
|
18738
|
-
if (!match) continue;
|
|
18739
|
-
if (match[1] === CURRENT_PROFILE_KEY) {
|
|
18740
|
-
currentProfile = match[2] || void 0;
|
|
18741
|
-
continue;
|
|
18742
|
-
}
|
|
18743
|
-
const key = CONFIG_KEYS.find((candidate) => candidate === match[1]);
|
|
18744
|
-
if (key) config2[key] = match[2] ?? "";
|
|
18745
|
-
}
|
|
18746
|
-
return { config: config2, currentProfile };
|
|
18728
|
+
text = readFileSync2(path2, "utf8");
|
|
18747
18729
|
} catch (err) {
|
|
18748
|
-
if (err.code === "ENOENT")
|
|
18749
|
-
return { config: {} };
|
|
18750
|
-
}
|
|
18730
|
+
if (err.code === "ENOENT") return [];
|
|
18751
18731
|
throw err;
|
|
18752
18732
|
}
|
|
18733
|
+
return text.split(/\r?\n/).map((line) => /^([A-Za-z0-9_]+):\s*(.*)$/.exec(line.trim())).filter((match) => match !== null).map((match) => [match[1] ?? "", match[2] ?? ""]);
|
|
18753
18734
|
}
|
|
18754
|
-
function
|
|
18735
|
+
function writeProfileFile(config2, path2) {
|
|
18755
18736
|
const lines = CONFIG_KEYS.filter((key) => config2[key]).map(
|
|
18756
18737
|
(key) => `${key}: ${config2[key]}`
|
|
18757
18738
|
);
|
|
@@ -21855,17 +21836,15 @@ async function exchangeAuthorizationCode(input) {
|
|
|
21855
21836
|
}
|
|
21856
21837
|
async function finishLogin(input) {
|
|
21857
21838
|
const { token: token2, serverUrl } = input;
|
|
21858
|
-
const previous = readConfig(input.configPath);
|
|
21859
21839
|
const profile = token2.user ? findAccountProfile({
|
|
21860
21840
|
configPath: input.configPath,
|
|
21861
21841
|
serverUrl,
|
|
21862
21842
|
userId: token2.user.id,
|
|
21863
21843
|
userEmail: token2.user.email
|
|
21864
21844
|
}) : void 0;
|
|
21865
|
-
const
|
|
21866
|
-
|
|
21867
|
-
|
|
21868
|
-
projectId: selectionSource.projectId
|
|
21845
|
+
const selection = profile?.organizationId && profile.projectId ? {
|
|
21846
|
+
organizationId: profile.organizationId,
|
|
21847
|
+
projectId: profile.projectId
|
|
21869
21848
|
} : void 0;
|
|
21870
21849
|
let config2 = {
|
|
21871
21850
|
serverUrl,
|
|
@@ -21912,10 +21891,6 @@ async function finishLogin(input) {
|
|
|
21912
21891
|
);
|
|
21913
21892
|
}
|
|
21914
21893
|
function persistLogin(config2, input) {
|
|
21915
|
-
if (!input.token.user) {
|
|
21916
|
-
writeConfig(config2, input.configPath);
|
|
21917
|
-
return;
|
|
21918
|
-
}
|
|
21919
21894
|
const pinned = input.configPath !== void 0 && isProfilePath(input.configPath);
|
|
21920
21895
|
const name = saveProfile({
|
|
21921
21896
|
config: config2,
|
|
@@ -29266,18 +29241,20 @@ async function handleWhoami(context) {
|
|
|
29266
29241
|
context.io.writeResult(whoami, formatWhoamiText);
|
|
29267
29242
|
}
|
|
29268
29243
|
function logout(context) {
|
|
29269
|
-
|
|
29270
|
-
|
|
29271
|
-
|
|
29272
|
-
|
|
29273
|
-
|
|
29274
|
-
|
|
29275
|
-
|
|
29276
|
-
|
|
29277
|
-
|
|
29278
|
-
|
|
29279
|
-
|
|
29280
|
-
|
|
29244
|
+
if (currentProfileName(context.configPath) !== void 0) {
|
|
29245
|
+
const config2 = readConfig(context.configPath);
|
|
29246
|
+
writeConfig(
|
|
29247
|
+
{
|
|
29248
|
+
...config2,
|
|
29249
|
+
refreshToken: void 0,
|
|
29250
|
+
accessToken: void 0,
|
|
29251
|
+
accessTokenExpiresAt: void 0,
|
|
29252
|
+
accessTokenOrganizationId: void 0,
|
|
29253
|
+
accessTokenProjectId: void 0
|
|
29254
|
+
},
|
|
29255
|
+
context.configPath
|
|
29256
|
+
);
|
|
29257
|
+
}
|
|
29281
29258
|
context.writeOutput(context.io.style.success("Logged out."));
|
|
29282
29259
|
}
|
|
29283
29260
|
function listAccounts(context) {
|
|
@@ -29287,7 +29264,11 @@ function listAccounts(context) {
|
|
|
29287
29264
|
}
|
|
29288
29265
|
for (const profile of profiles) {
|
|
29289
29266
|
context.writeOutput(
|
|
29290
|
-
accountLine(
|
|
29267
|
+
accountLine(
|
|
29268
|
+
profile,
|
|
29269
|
+
currentProfileName(context.configPath),
|
|
29270
|
+
context.io.style
|
|
29271
|
+
)
|
|
29291
29272
|
);
|
|
29292
29273
|
}
|
|
29293
29274
|
}
|
|
@@ -29360,15 +29341,6 @@ function removeProfile(context, name) {
|
|
|
29360
29341
|
rmSync(path2);
|
|
29361
29342
|
context.writeOutput(context.io.style.success(`Removed profile "${name}".`));
|
|
29362
29343
|
}
|
|
29363
|
-
function activeProfileName(context) {
|
|
29364
|
-
const name = currentProfileName(context.configPath);
|
|
29365
|
-
if (name) return name;
|
|
29366
|
-
const active = readConfig(context.configPath);
|
|
29367
|
-
if (!active.userEmail) return void 0;
|
|
29368
|
-
return listProfiles(context.configPath).find(
|
|
29369
|
-
(profile) => profile.config.userEmail === active.userEmail && profile.config.serverUrl === active.serverUrl
|
|
29370
|
-
)?.name;
|
|
29371
|
-
}
|
|
29372
29344
|
function accountLine(profile, activeName, style) {
|
|
29373
29345
|
return [
|
|
29374
29346
|
profile.name,
|