Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ const outdir = "dist";
const { rmSync } = await import("fs");
rmSync(outdir, { recursive: true, force: true });

// Default features that match the official CLI build.
// Additional features can be enabled via FEATURE_<NAME>=1 env vars.
const DEFAULT_BUILD_FEATURES = ["AGENT_TRIGGERS_REMOTE"];

// Collect FEATURE_* env vars → Bun.build features
const features = Object.keys(process.env)
const envFeatures = Object.keys(process.env)
.filter(k => k.startsWith("FEATURE_"))
.map(k => k.replace("FEATURE_", ""));
const features = [...new Set([...DEFAULT_BUILD_FEATURES, ...envFeatures])];
Comment on lines +16 to +19
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

FEATURE_* parsing currently enables flags even when value is not 1.

Line 16-Line 19 only checks key names, so FEATURE_AGENT_TRIGGERS_REMOTE=0 still turns the feature on. That conflicts with the stated FEATURE_<NAME>=1 contract and can unintentionally ship gated code.

Suggested fix
-const envFeatures = Object.keys(process.env)
-    .filter(k => k.startsWith("FEATURE_"))
-    .map(k => k.replace("FEATURE_", ""));
+const envFeatures = Object.entries(process.env)
+    .filter(([k, v]) => k.startsWith("FEATURE_") && v === "1")
+    .map(([k]) => k.replace("FEATURE_", ""));
 const features = [...new Set([...DEFAULT_BUILD_FEATURES, ...envFeatures])];
Based on learnings: Control feature flags through `FEATURE_=1` environment variables rather than code changes.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const envFeatures = Object.keys(process.env)
.filter(k => k.startsWith("FEATURE_"))
.map(k => k.replace("FEATURE_", ""));
const features = [...new Set([...DEFAULT_BUILD_FEATURES, ...envFeatures])];
const envFeatures = Object.entries(process.env)
.filter(([k, v]) => k.startsWith("FEATURE_") && v === "1")
.map(([k]) => k.replace("FEATURE_", ""));
const features = [...new Set([...DEFAULT_BUILD_FEATURES, ...envFeatures])];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@build.ts` around lines 16 - 19, The current envFeatures computation turns on
any FEATURE_* variable regardless of its value; update the filter to only
include keys whose value equals "1" (e.g., filter(k => k.startsWith("FEATURE_")
&& process.env[k] === "1")), then map as before and keep the dedup with
DEFAULT_BUILD_FEATURES (variables: envFeatures, features,
DEFAULT_BUILD_FEATURES) so only FEATURE_<NAME>=1 enables a flag.


// Step 2: Bundle with splitting
const result = await Bun.build({
Expand Down
2 changes: 1 addition & 1 deletion scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const defineArgs = Object.entries(defines).flatMap(([k, v]) => [

// Bun --feature flags: enable feature() gates at runtime.
// Default features enabled in dev mode.
const DEFAULT_FEATURES = ["BUDDY", "TRANSCRIPT_CLASSIFIER", "BRIDGE_MODE"];
const DEFAULT_FEATURES = ["BUDDY", "TRANSCRIPT_CLASSIFIER", "BRIDGE_MODE", "AGENT_TRIGGERS_REMOTE"];

// Any env var matching FEATURE_<NAME>=1 will also enable that feature.
// e.g. FEATURE_PROACTIVE=1 bun run dev
Expand Down
Loading