Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vm beta #69

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add vm beta #69

wants to merge 4 commits into from

Conversation

Flaque
Copy link
Member

@Flaque Flaque commented Feb 15, 2025

No description provided.

Copy link

semanticdiff-com bot commented Feb 15, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  src/lib/posthog.ts  69% smaller
  src/index.ts  24% smaller
  src/helpers/feature-flags.ts  0% smaller
  src/lib/vm.ts  0% smaller
  src/types/deno.d.ts  0% smaller

@Flaque Flaque changed the title Add CLI changes Add vm beta Feb 15, 2025
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR introduces VM management functionality to the CLI with feature flag support, including commands for listing VMs, managing startup scripts, and viewing logs.

  • Added src/lib/vm.ts with three core commands: vm list, vm script, and vm logs for VM management
  • Implemented feature flag caching system in src/helpers/feature-flags.ts with 24-hour expiration
  • Added isFeatureEnabled function in src/lib/posthog.ts to gate VM features behind 'vms' flag
  • Potential architecture concern: Mixed usage of Node.js and Deno APIs in feature-flags.ts could cause compatibility issues
  • Security enhancement: All VM commands properly handle unauthorized access with session token expiration checks

5 file(s) reviewed, 10 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +39 to +53
if (!exchangeAccountId) {
const response = await fetch(await getApiUrl("me"), {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${config.auth_token}`,
},
});

const data = await response.json();
if (data.id) {
exchangeAccountId = data.id;
saveConfig({ ...config, account_id: data.id });
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: no error handling for failed API requests - could silently fail if network error or invalid response

Suggested change
if (!exchangeAccountId) {
const response = await fetch(await getApiUrl("me"), {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${config.auth_token}`,
},
});
const data = await response.json();
if (data.id) {
exchangeAccountId = data.id;
saveConfig({ ...config, account_id: data.id });
}
}
if (!exchangeAccountId) {
try {
const response = await fetch(await getApiUrl("me"), {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${config.auth_token}`,
},
});
if (!response.ok) {
throw new Error(`API request failed with status ${response.status}`);
}
const data = await response.json();
if (data.id) {
exchangeAccountId = data.id;
saveConfig({ ...config, account_id: data.id });
}
} catch (error) {
console.error('Failed to fetch account ID:', error);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one might be a real concern

Copy link
Member

@sigmachirality sigmachirality left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some code quality nits. In a perfect world I would prefer these get fixed, but we do not live in a perfect world, so send it if you need to

Comment on lines +27 to +31
} catch (error) {
console.error("boba error saving feature flags:", error);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohnPhamous @Flaque one of you should rebase this branch on main, I believe this change is outdated.

Comment on lines +40 to +46
const response = await fetch(await getApiUrl("me"), {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${config.auth_token}`,
},
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the OpenAPI client fail to properly generate types here? all good if so

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const client = await apiClient(); this one

Comment on lines +53 to +58
let script: string;
try {
script = readFileSync(options.file, "utf-8");
} catch (err) {
logAndQuit(`Failed to read script file: ${err.message}`);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact JS used to have a with keyword

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with

Not supported in strict JS/TS though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DO NOT DO THIS.

Comment on lines +91 to +94
for (const log of data.data) {
console.log(`[${log.timestamp}] ${log.message}`);
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have this be a streaming window like fly log that you can quit out of, but prob out of scope for this PR

Comment on lines +1 to +8
declare namespace Deno {
function writeTextFile(path: string, data: string): Promise<void>;
function readTextFile(path: string): Promise<string>;
function mkdir(
path: string,
options?: { recursive?: boolean }
): Promise<void>;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to declare a type file like this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try adding deno.ns to the tsconfig in the relevant fields

https://docs.deno.com/runtime/reference/ts_config_migration/#using-the-%22lib%22-property

{
  "compilerOptions": {
    "lib": ["deno.ns"]
  }
}

Use the Deno target with the smallest possible scope

@sigmachirality
Copy link
Member

Also @JohnPhamous I think you probably reformatted some files using prettier or biome, but in this codebase we use deno fmt and deno lint where possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants