DodoApp: Fix env handling

Change-Id: I836c2037a58463d07a31c61e3e31a52e80be1cbd
diff --git a/core/installer/app_configs/dodo_app.cue b/core/installer/app_configs/dodo_app.cue
index c26fa77..966b93e 100644
--- a/core/installer/app_configs/dodo_app.cue
+++ b/core/installer/app_configs/dodo_app.cue
@@ -169,6 +169,15 @@
 		rootDir:    string | *"/"
 	})
 
+	envs: {
+		"env": env
+		...
+	}
+	envsFlat: list.FlattenN([
+		for _, v in envs {
+			v
+		},
+	], 1)
 	externalEnv: [...string] | *[]
 
 	_allEnv: list.Concat([
@@ -187,14 +196,14 @@
 	lastCmdEnv: list.Concat([
 		_allEnv,
 		[
-			for e in env if e.alias != _|_ {
+			for e in envsFlat if e.alias != _|_ {
 				for m in _envMap if strings.ToLower(e.name) == strings.ToLower(m[0]) {
 					"\(strings.ToUpper(e.alias))=\(m[1])"
 				}
 			},
 		],
 		[
-			for e in env if e.value != _|_ {
+			for e in envsFlat if e.value != _|_ {
 				"\(strings.ToUpper(e.name))=\(e.value)"
 			},
 		],
@@ -517,16 +526,19 @@
 		name:  "p8084"
 		value: 8084
 	}]
-	env: [{
-		name:  "DODO_PROJECT_ID"
-		value: input.appId
-	}, {
-		name:  "DODO_API_BASE_ADDR"
-		value: input.managerAddr
-	}, {
-		name:  "GEMINI_API_KEY"
-		value: _geminiApiKey
-	}]
+	envs: {
+		sketch: [{
+			name:  "DODO_PROJECT_ID"
+			value: input.appId
+		}, {
+			name:  "DODO_API_BASE_ADDR"
+			value: input.managerAddr
+		}, {
+			name:  "GEMINI_API_KEY"
+			value: _geminiApiKey
+		}]
+		...
+	}
 	rootDir: "/dodo/volume/\(_name)-apps"
 
 	lastCmdEnv: [...string]
diff --git a/core/installer/dodo_app_test.go b/core/installer/dodo_app_test.go
index f81f2f9..d4dc1a4 100644
--- a/core/installer/dodo_app_test.go
+++ b/core/installer/dodo_app_test.go
@@ -645,13 +645,45 @@
 
 const sketch = `
 {
-    "agent": [
+  "agent": [
+    {
+      "type": "sketch:latest",
+      "name": "dev",
+      "geminiApiKey": "foo",
+      "ports": [
         {
-            "type": "sketch:latest",
-            "name": "dev",
-            "geminiApiKey": "foo",
+          "name": "agent",
+          "value": 2001,
+          "protocol": "TCP"
+        },
+        {
+          "name": "p8080",
+          "value": 8080,
+          "protocol": "TCP"
+        },
+        {
+          "name": "p8081",
+          "value": 8081,
+          "protocol": "TCP"
+        },
+        {
+          "name": "p8082",
+          "value": 8082,
+          "protocol": "TCP"
+        },
+        {
+          "name": "p8083",
+          "value": 8083,
+          "protocol": "TCP"
+        },
+        {
+          "name": "p8084",
+          "value": 8084,
+          "protocol": "TCP"
         }
-    ],
+      ]
+    }
+  ]
 }
 `